For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2007 > define an array in perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author define an array in perl
Jeniffer

2007-07-31, 6:59 pm

Hi
I am a newbie in perl. I have an array block_list :

push ( @block_list ,$word); # this word is read from a file.
$list_name = $block_list[$#block_list]; # i extract the last element
ie $word in this case
now i want to define an array with the name $list_name


like ,
my @"$list_name";

But this is giving me errors...
sorry for the stupid question,,,please help me out ,,,,

Chas Owens

2007-07-31, 6:59 pm

On 7/31/07, jeniffer <zenith.of.perfection@gmail.com> wrote:
> Hi
> I am a newbie in perl. I have an array block_list :
>
> push ( @block_list ,$word); # this word is read from a file.
> $list_name = $block_list[$#block_list]; # i extract the last element
> ie $word in this case
> now i want to define an array with the name $list_name

snip

No, you don't. Well, you may think that is what you want, but it is
an incredibly bad idea. What is it that you want to achieve by doing
this? There is almost always a better solution. One is to use a
hash:

push @block_list, $word;
my $list_name = $block_list[-1];
my %lists;

push @{$lists{$list_name}}, 1 .. 10;

print "$_ => @$_\n" for keys %lists;
Paul Lalli

2007-07-31, 6:59 pm

On Jul 31, 6:59 am, zenith.of.perfect...@gmail.com (Jeniffer) wrote:
> sorry for the stupid question,,,please help me out ,,,,


What was wrong with the answers you got when you asked the same
question in comp.lang.perl.misc?

http://groups.google.com/group/comp...983d0954e06af/#

It is very rude to ask the same question multiple times in different
forums, as it wastes the time of those who do not realize your
question has already been answered. Please don't do that again.

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com