Sponsored Content
Top Forums Shell Programming and Scripting Perl Array Variables to be returned to main Post 302330330 by Raynon on Tuesday 30th of June 2009 11:05:40 PM
Old 07-01-2009
Perl Array Variables to be returned to main

Hi All,

I can;t seem to print out the array in sequence using the below subroutine.
My first element in the array @lotsuffix is suppose to be $lotsuffix[1] as defined in the subroutine, but when the array variable is being pass on the main program, my first element actually becomes $lotsuffix[0] !
Can any expert give some advice on this ?
How can i overcome this problem ?


Code:
#!/usr/bin/perl
use strict;

my @lotsuffix;
my @date;

capture_LOTSUFFIX_DATE("test");
        print "LOTSUFFIX1= $lotsuffix[1]\n";    
        print "LOTSUFFIX2= $lotsuffix[2]\n";
        print "LOTSUFFIX3= $lotsuffix[3]\n";
        print "LOTSUFFIX4= $lotsuffix[4]\n";
        print "LOTSUFFIX5= $lotsuffix[5]\n";
        print "LOTSUFFIX6= $lotsuffix[6]\n";
        print "LOTSUFFIX7= $lotsuffix[7]\n";
        print "LOTSUFFIX8= $lotsuffix[8]\n";
        print "LOTSUFFIX9= $lotsuffix[9]\n";
        print "LOTSUFFIX10= $lotsuffix[10]\n";


sub capture_LOTSUFFIX_DATE {

        my $counting = 1;
        my $line;


        for ($counting = 1; $counting <= 10 ; $counting++ ) {
                print "reports_${counting}_${_[0]}.txt\n";
                     open(FH, "< $HISTORY/reports_${counting}_${_[0]}.txt" ) or die $!;
                             while( $line = <FH> ) {
                                     my @Fld = split(' ', $line );
                                     if ( $Fld[1] eq 'LOTSUFFIX=' ) {
                                             $lotsuffix[$counting] = $Fld[2];
                                                print "$lotsuffix[$counting]\n";
                                     }
                                    if ( $Fld[1] eq 'DATE=' ) {
                                         $DATE[$counting] = $Fld[2];
                                         my @fields = split(/-/, $DATE[$counting]);
                                         $date[$counting] = sprintf ("%s-%s",$fields[1],$fields[2]);
                                        print "$date[$counting]\n";
                                     }
                             }
                             close FH;
             }

                return (@lotsuffix , @date); 
 
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl: storing regex in array variables trouble

hi this is an example of code: use strict; use warnings; open FILE, "/tmp/result_2"; my $regex="\\ Starting program ver. (.*)"; my $res="Program started, version <$1> - OK.\n"; while (<FILE>) { if ($_ =~ /($regex)/) { print "$res"; } } close FILE; This finds $regex and print... (3 Replies)
Discussion started by: xist
3 Replies

2. Shell Programming and Scripting

'who' command -- getting data returned into variables (in bash)

Anyone know how to get the data out of the "who" command? I'm still in lukewarm pursuit of creating an OS X-like welcome message at the start of any Terminal session, sans having to use either bash login or calling up ssh. My trials & errors and surfing around have narrowed it down for me... (1 Reply)
Discussion started by: SilversleevesX
1 Replies

3. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

4. Shell Programming and Scripting

Perl, searching multiple files and printing returned line to new file

I am trying to find a way to utilise the full potential of my cpu cores and memory on my windows machine. Now, I am quite familiar with grep, however, running a Unix based OS is not an option right now. Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple... (1 Reply)
Discussion started by: Moloch
1 Replies

5. Shell Programming and Scripting

How to get the main node name in xml using perl?

Hi, I am having an conf file like this: <Main> <NODE> <NODENAME>FRUITS</NODENAME> <NAME>APPLE</NAME> <COLOUR>RED</COLOUR> <NODE> <IsWrapper/> <NODENAME>SEASONAL</NODENAME> <NODE> <NAME>MANGO</NAME> <COLOUR>GREEN</COLOUR> </NODE> </NODE>... (4 Replies)
Discussion started by: vanitham
4 Replies

6. Shell Programming and Scripting

Help in separating variables declared in the main function

Hi! I've a C program as shown below.. The line numbers and the statements of the program are separated by a space.. 1 #include<stdio.h> 2 char a,b,c; 3 float x,y,z; 4 int main() 5 { 6 int d,e,f; 7 // further declarations 8 // further declarations 9 /* body*/ 10 } 11 void fun1() 12... (1 Reply)
Discussion started by: abk07
1 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. UNIX for Dummies Questions & Answers

[ksh93+] Array fed by function is empty when used in main.

I feel that i am missing something obvious but i can't find what is wrong. I have a script that is launching some functions with "&" and each call is feeding the array with a value. When all calls are finished I just want to retrieve the values of that array. It is looking like that : ... (5 Replies)
Discussion started by: bibou25
5 Replies

9. Shell Programming and Scripting

Perl: How to avoid warnings for superfluous values returned?

Hi all, a question for the Perl knowledgeable: I have use warnings; enabled. I use something like: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); In the further code I only work with some of the returned variables, as the others I have no need for. Though the... (1 Reply)
Discussion started by: zaxxon
1 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
ARRAY_POP(3)								 1							      ARRAY_POP(3)

array_pop - Pop the element off the end of array

SYNOPSIS
mixed array_pop (array &$array) DESCRIPTION
array_pop(3) pops and returns the last value of the $array, shortening the $array by one element. Note This function will reset(3) the array pointer of the input array after use. PARAMETERS
o $array - The array to get the value from. RETURN VALUES
Returns the last value of $array. If $array is empty (or is not an array), NULL will be returned. ERRORS
/EXCEPTIONS This function will produce an error of level E_WARNING when called on a non-array. EXAMPLES
Example #1 array_pop(3) example <?php $stack = array("orange", "banana", "apple", "raspberry"); $fruit = array_pop($stack); print_r($stack); ?> After this, $stack will have only 3 elements: Array ( [0] => orange [1] => banana [2] => apple ) and raspberry will be assigned to $fruit. SEE ALSO
array_push(3), array_shift(3), array_unshift(3). PHP Documentation Group ARRAY_POP(3)
All times are GMT -4. The time now is 05:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy