> -----Original Message-----
> From: Dave Adams [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, September 27, 2005 5:17 PM
> To: beginners perl
> Subject: Shift Question
>
> QUESTION: What is the purpose of the line "my $msg = shift;"? I am
> guessing it is for the @_ array but what list element is there to be
> shifted off? It seems that the shift function is in a lot of
> subroutines and I am confused as to their purpose.
>From what I understand shift defaults to @_ in a subroutine unless
specified otherwise. If your sub looked like this:
sub write_log($) {
my $msg;
print "$msg\n";
}
$teststring = 'Test Msg to SysLog';
write_log($teststring);
You'd get no output because $msg is undef.
>
> #!/bin/perl -w
> (my $PROGNAME = $0) =~ s/^.*\///;
> (my $SHORT_PROGNAME = $PROGNAME) =~ s/\.pl$//;
> my $SYSLOG_PRIORITY = 'info';
> my $SYSLOG_FACILITY = 'local4';
>
> use Sys::Syslog;
>
> sub write_log($) {
> # write a datestamped message to the logfile, e.g.:
> # &write_log('some message');
>
> my $msg = shift;
>
> # print message to logfile:
> openlog($SHORT_PROGNAME,'pid','');
> syslog("$SYSLOG_FACILITY|$SYSLOG_PRIORITY", '%s', "$msg");
> closelog();
>
> }
> $teststring = 'Test Msg to SysLog';
> write_log($teststring);
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>