Looking at some of my older scripts I had written. What is the advantage of this reference use or in general why are reference useful compared to scalars? I have only used them 1-2 times that I can remember.
use strict; use warnings; >snip< sub new_date { my ( $year, $month, $day ) = (localtime)[ 5, 4, 3 ]; sprintf( "%04d%02d%02d", ( $year += 1900 ), $month + 1, $day ); } $passed_new_date = new_date(); sub new_date_append { return $monster_date = "OhioS$passed_new_date"; } $fref = \&new_date_append(); ###--- HERE is my REF ---### >snip< if ( $passed_new_date and $$fref ) { calls 2 subs.... }
thx! HERE IS THE WHOLE KITnKABOODLE I wrote it back in 2004...to be kind.
use strict; use warnings; use Net::FTP; use MIME::Lite; my ( $ftplog, $fref ); my $OHMONSTER; my $RENAMED = q/OhioS.xml/; my ( $monster_date, $passed_new_date ) = 0; my $overide = $SIG{__DIE__}; ## get error handler currently assigne +d to die() $SIG{__DIE__} = sub { my $error = shift; ## error now holds the mesg passed to +die $overide->($error) if ( ref $overide ); mailme($error); }; sub new_date { my ( $year, $month, $day ) = (localtime)[ 5, 4, 3 ]; sprintf( "%04d%02d%02d", ( $year += 1900 ), $month + 1, $day ); } $passed_new_date = new_date(); sub new_date_append { return $monster_date = "OhioS$passed_new_date"; } $fref = \&new_date_append(); sub mailme { my $error = shift; my $msg = MIME::Lite->new( From => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx>', To => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx>', To => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx>', Subject => "HRIS FTP Inbound to monster.com had problems and or failed:\t\t$e +rror", Type => 'multipart/related' ); $msg->attach( Type => 'TEXT', Disposition => 'attachment', Path => "$ftplog", Filename => "$ftplog" ); $msg->send; } ## Delete files older than 12 days sub filetest { my $e = 0; my @diraray = glob("/psofthr/hr88prd/intf/monster/inbound/*"); foreach $e (@diraray) { if ( -M $e > 12 ) { unlink $e; } } } sub ftpme { my $remotehost = "ftp.monster.com"; my $remotedir = "xxxxxxx"; my $localdir = "/psofthr/hr88prd/intf/monster/inbound"; my $user = "xxxx"; my $pass = "xxxx"; $ftplog = "/psofthr/hr88prd/intf/monster/log/interface_monster.log"; open( FTPLOG, ">>$ftplog" ) || warn "Could not open FTPLOG FH $!"; my $ftp = Net::FTP->new( $remotehost, Debug => 10 ) || die "Failed to connect to $remotehost: $!", print FTPLOG "\n$passed_new_date\nFailed to connect to $remotehost! +"; print FTPLOG $passed_new_date; $ftp->login( $user, $pass ) || die "Login failed at $remotehost!: $!" +, print FTPLOG "\n$passed_new_date\nLogin Failed at $remotehost!"; $ftp->binary(); $ftp->cwd($remotedir) || die "CWD to folder outbound failed!: $!", print FTPLOG "\n$passed_new_date\nCWD to folder outbound failed!"; foreach ( $ftp->ls() ) { if (/${$fref}\d+\w+/) { $OHMONSTER = $_; $ftp->get( $OHMONSTER, "$localdir/$OHMONSTER" ) || die "FTP get from monster.com failed!: $!", print FTPLOG "\nFTP get at monster.com failed!"; sleep 2; $ftp->delete($RENAMED) || die "FTP dele of existing file at monster.com failed! : $!", print FTPLOG "\nFTP dele at monster.com failed!"; sleep 2; $ftp->rename( "$OHMONSTER", "$RENAMED" ) || die "FTP rename at monster.com failed!: $!", print FTPLOG "\n$passed_new_date\nFTP rename at monster.com faile +d!"; print FTPLOG $passed_new_date; last; } } $ftp->quit; close(FTPLOG) || warn "was unable to close FTPLOG FH $!"; } if ( $passed_new_date and $$fref ) { ftpme(); filetest(); } else { my $error = 'variables for FTP rename at monster.com were not set, rename will not + work & process will fail!'; mailme($error); }

In reply to reference , advantages? by dbs

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.