"John W. Krahn" schreef:
> six24hourdays:

>> I would like to know how to test for the last element of a list
>> during a foreach loop [...]
>
> You can't because a list does not have a name. [...]
> You can however do it with an array by comparing references:
> 
> $ perl -le'
> my @x = "a" .. "z";
> for my $elem ( @x ) {
>      print $elem if \$elem == \$x[-1];
> }
> '
> z

There are of course ways in Perl to make this fail. One way:

$ perl -MData::Alias -wle'                                        
  my @x = "a".."z";
  alias $x[3] = $x[-1];
  $x[-1] = "test";   
  for my $elem (@x) {
    print $elem if \$elem == \$x[-1];
  }
'
test
test

-- 
Affijn, Ruud

"Gewoon is een tijger."

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to