Jon Earle wrote:

> Consider this:
> 
> while (<FD>) {
>         @_ = split /\s*:\s*/;
>         if (/something/) {
>                 $found = $_[$#_];
> ...
> 
> My interpretation based on what is happening:
> 
> $_ is set to whatever current line is read-in via the while loop.  That
> line is split and stored into the current argument stack.  If 'something'
> is found in (the unchanged) $_, then $found is set to the last value from
> the split command.
> 
> My question is, why?  What is ``$#_''?  Is it simply considering _ to be
> the array @_ and simply giving the index of the last element?  If so, then

Yes.

> why would $_ have elements from which to pick, if $_ is the whole line?

You can have an array and a scalar with the same name.  @_ and $_ do not
refer to the same vrbl.  $_[1] is not referring to $_ - it's referring
to the 2nd element of @_.  This is just normal Perl syntax.

{ my $found = $_[$#_]; } might be nicer to read as { my $found = $_[-1]; }



-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to