Hello Wise Monks:

I have confused myself with a simple pass by reference issue. Please consider the code below:

As you can see in the subroutine, $yr, $mth , $dt get set. But when I return the values are lost. Well they are lost to me.

What am I doing wrong?

Thanks for your kind assistance.

KD
sub maxFileDate { my ( $filePrefix_In, @entries_In, $yr_ref, $mth_ref, $dt_ref ); ( $filePrefix_In, @entries_In, $yr_ref, $mth_ref, $dt_ref ) = @_ ; my $entry; my @fields; my @fileName; print "fileName Prefix: " . $filePrefix_In . "\n" ; ##print Dumper @entries_In ; my $maxdate = 20000101; foreach $entry (@entries_In) { ##print "$entry \n "; chomp $entry; @fields = split /\s+/, $entry; if ( $fields[0] =~ m/^-/) { # ** ** ** ** #this a file entry if ($fields[-1] =~ m/^$filePrefix_In/) { @fileName = split /\.|_/ , $fields[-1]; print Dumper @fileName ; print "file name: " . $fields[-1] . " date part: " . $ +fileName[4]. $fileName[5]. $fileName[6]. "\n"; if ( ('20'. $fileName[4]. $fileName[5]. $fileName[6]) > $ +maxdate ) { $maxdate = ('20'. $fileName[4]. $fileName[5]. $fileNa +me[6]) ; $$yr_ref = $fileName[4]; $$mth_ref = $fileName[5]; $$dt_ref = $fileName[6]; } } ##file name like } ##file entries } ## for each entry print "yr " . $yr_ref . "\n" ; print "mth". $mth_ref . "\n" ; print "dt " . $dt_ref . "\n" ; print "yr " . $$yr_ref . "\n" ; print "mth". $$mth_ref . "\n" ; print "dt " . $$dt_ref . "\n" ; ##$maxdate; } # maxFileDate

I call the above as follows:
if ( !defined( $datein ) ) { maxFileDate('WSB826TB', @entries, \$yr, \$mth, \$dt ); } # no date passed in else { $datea = $datein; } print "\nDownload WSB826TB for date: " . $yr. $mth. $dt . "\n";

It produces the following results:
C:\HFAccess\devPostgresql>perl -w xxx_ftpgetTest.pl xxx_ftp.prop Properties File: xxx_ftp.prop. Properties FTPServer = ftp.xxx.ml.com RemoteDirectory = /outgoing User Id = mysecretid LocalServer = LocalDirectory = C:\HFAccess\xxxx GPG_HomeDirectory = Q:\Downloads\gnupg\keys Remote Directory: /outgoing fileName Prefix: WSB826TB $VAR1 = 'WSB826TB'; $VAR2 = 'CST238PO'; $VAR3 = 'CSV'; $VAR4 = 'asc'; $VAR5 = '09'; $VAR6 = '04'; $VAR7 = '21'; $VAR8 = '01'; $VAR9 = '10'; file name: WSB826TB.CST238PO.CSV.asc.09.04.21_01.10 date part: 09042 +1 $VAR1 = 'WSB826TB'; $VAR2 = 'CST238PO'; $VAR3 = 'CSV'; $VAR4 = 'asc'; $VAR5 = '09'; $VAR6 = '04'; $VAR7 = '22'; $VAR8 = '00'; $VAR9 = '54'; file name: WSB826TB.CST238PO.CSV.asc.09.04.22_00.54 date part: 09042 +2 $VAR1 = 'WSB826TB'; $VAR2 = 'CST238PO'; $VAR3 = 'CSV'; $VAR4 = 'asc'; $VAR5 = '09'; $VAR6 = '04'; $VAR7 = '23'; $VAR8 = '02'; $VAR9 = '43'; file name: WSB826TB.CST238PO.CSV.asc.09.04.23_02.43 date part: 09042 +3 $VAR1 = 'WSB826TB'; $VAR2 = 'CST238PO'; $VAR3 = 'CSV'; $VAR4 = 'asc'; $VAR5 = '09'; $VAR6 = '04'; $VAR7 = '24'; $VAR8 = '01'; $VAR9 = '33'; file name: WSB826TB.CST238PO.CSV.asc.09.04.24_01.33 date part: 09042 +4 $VAR1 = 'WSB826TB'; $VAR2 = 'CST238PO'; $VAR3 = 'CSV'; $VAR4 = 'asc'; $VAR5 = '09'; $VAR6 = '04'; $VAR7 = '25'; $VAR8 = '00'; $VAR9 = '26'; file name: WSB826TB.CST238PO.CSV.asc.09.04.25_00.26 date part: 09042 +5 yr SCALAR(0x1ae256c) mthSCALAR(0x1ae2578) dt SCALAR(0x1ae2584) yr 09 mth04 dt 25 Use of uninitialized value in concatenation (.) or string at xxx_ftpge +tTest.pl line 153. Use of uninitialized value in concatenation (.) or string at xxx_ftpge +tTest.pl line 153. Use of uninitialized value in concatenation (.) or string at xxx_ftpge +tTest.pl line 153. Download WSB826TB for date: C:\HFAccess\devPostgresql>

In reply to simple reference by kevind0718

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.