SPUG: Another Eval Question
Tim Maher/CONSULTIX
tim at consultix-inc.com
Tue Oct 12 12:25:01 CDT 1999
>> Message submitted at: Tue Oct 12 10:25:01 PDT 1999
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 2053
According to Asim Jalis:
>
> Richard A. Puckett II writes:
> > Want to use single quotes here so variables aren't "interpolated".
> > Also want to ditch the ampersand on "length". FYI, you can check
> > $@ after the eval for possible errors.
>
> Good point.
>
> Another question.
>
> #!/usr/bin/perl
> sub hello {
> my $y; my $x = q{ $y = shift @_; };
> eval $x;
> print "y = [$y]\n";
> print "@ = [$@]\n";
> }
> hello(5);
>
> This prints:
>
> y = [5]
> @ = []
>
> But replacing "shift @_" with "shift" results in:
>
> y = []
> @ = []
Please read the man pages; for example, "perldoc -f shift" would show you:
shift ARRAY
shift
Shifts the first value of the array off and returns it, shortening the
array by 1 and moving everything down. If there are no elements in the
array, returns the undefined value. If ARRAY is omitted, shifts the
@_ array within the lexical scope of subroutines and formats, and the
@ARGV array at file scopes or within the lexical scopes established by
the eval '', BEGIN {}, END {}, and INIT {} constructs.
See also unshift(), push(), and pop(). Shift() and unshift() do the
same thing to the left end of an array that pop() and push() do to the
right end.
>
> Why is this?
>
> Asim
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
> SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
> Email to majordomo at pm.org: ACTION spug-list your_address
>
>
>
*==================================================================*
| Tim Maher, PhD CEO, Consultix & (206) 781-UNIX/8649 |
| Pacific Software Gurus, Inc. Email: tim at consultix-inc.com |
| "The UNIX/Perl Training Experts" http://www.consultix-inc.com |
|Classes: 11/1 Shell/Utils 11/15 Adv Shell 12/7 LINUX 12/13 Perl|
*==================================================================*
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list