[ Please do not top-post.  TIA ]

Christiane Nerz wrote:
> 
> Nope - 'cause if I print out the values key for key, I get all four:
> 
> my $array = keys %hash;

$array is a scalar and holds a single value.  It is not related to
@array in any way.

> print $hash{$array[0]};
> print"\n";
> print $hash{$array[1]};
> print"\n";
> print $hash{$array[2]};
> print"\n";
> print $hash{$array[3]};

If you have 'strict' and 'warnings' turned on then perl would tell you
that @array doesn't exist for those four lines.

> With the code
> foreach (keys %hash) {
>         print $hash{$_};
>         print "\n";}
> 
> I only get the value corresponding to $hash{$array[3]}.

It sounds like you are assigning a list to a scalar.

$scalar = ( 'one', 'two', 'three', 'four' );

In this case the comma operator will evaluate the first three items and
discard them and assign the fourth item to the scalar.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to