> -----Original Message-----
> From: yun yun [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, January 19, 2002 10:08 AM
> To: [EMAIL PROTECTED]
> Subject: $_ in hash datatype?
> 
> 
> if var is a hash type, i.e. %var,
> then what's the meaning of $_, and $var{$_}?
> Thanks!

The value inside the braces is a hash key. In this
case, $_ is used. $_ is one of the predefined "special"
variables in Perl. It is often used as a default variable
when no specific variable is named.

For example, you see this construct commonly:

   while(<F>) {
      ...
   }

<F> is the operator to read a line from filehandle F. Since
this is not assigned to any specific variable, Perl by
default assigns to the $_ variable when used inside a
while construct like this.

So, if you saw:

   while(<F>) {
      chomp;
      print $var{$_};
   }

this is using the value read from the file as a hash key
into the %var hash. (The line terminator is removed from
$_ by chomp, which uses $_ as its default variable also).

HTH

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

Reply via email to