"Hmmm..." <[EMAIL PROTECTED]> wrote:
>
> In "Programming Perl", there is an example of eval in chapter 3 that I do
> not understand.  It is on page 161.  It reads:
>
> Here's a statement that assigns an element to a hash chosen at run-time:
>
>     eval "\$$arrayname{\$key} = 1";
>
> I know the \ creates a reference, and the $ is dereferencing $arrayname.
> Why is he calling it $arrayname when he is assigning an element to a hash?
> I am not understading the relationship between array and hash here.
>
> Can anyone provide some details about what is going on here?  Thanks.

Hi. It would be nice to know who's asking...

The backslash in this context is 'escaping' the dollar character so that
it gets inserted literally into the string instead of being parsed as
part of a scalar variable name. If you have

  my $arrayname = 'hash';
  my $statement = "\$$arrayname{\$key} = 1";

then $statement will have the value

  "$hash{$key} = 1"

HTH,

Rob



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

Reply via email to