On 8/3/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
>
>
> -----Original Message-----
> >From: Mihir Kamdar <[EMAIL PROTECTED]>
>
> >$hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line; #Add some more cdr key fields
> >if u want.
>
> There are (maybe) two problems above.
> 1. when using hash slice,the form is @hash{'key1','key2'...},not
> $hash{'key1','key2'...}
> 2. when you say @hash{$cdr[2],$cdr[3],$cdr[6],$cdr[7]}=$line,only the first
> key ($cdr[2])
> has got value,the other keys would get undef as their values,since $line is
> a scalar,
> but the statement expect a list on the right of '=' I think.
I don't think he is trying to use the slice notation. He is using the
multidimensional array emulation. This not really a good practice
because it is easy to confuse it with slices. A better way to get
the same functionality is
$hash{"@cdr[2,3,6,7]"} = $line;
The quotes act as a signal that you aren't looking for a slice.
from perldoc perlvar
$; The subscript separator for multidimensional array emulation.
If you refer to a hash element as
$foo{$a,$b,$c}
it really means
$foo{join($;, $a, $b, $c)}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/