Chas Owens wrote:
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)}
But the expression $hash{"@cdr[2,3,6,7]"} is the same as
$hash{join($",@cdr[2,3,6,7])} You have just replaced one special variable with another and
$" is a bad choice since it's default is a space character, which may easily appear in one (or
all) of @cdr[2,3,6,7]
A better choice is $hash{$cdr[2]}{$cdr[3]}{$cdr[6]}{$cdr[7]} but you would need
four for-loops to get to the value.
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/