Hi sencond, On Thu, 21 Jul 2011 03:03:13 -0700 (PDT) sencond gun <thesecond...@gmail.com> wrote:
> On Jul 21, 10:28 am, g...@pbwe.com ("H Kern") wrote: > > Hi, My first newbie post. I wish to have two arrays indexed by a hash > > table. The simple program below runs and behaves properly initializing the > > hash table with the information I wish it to have. > > > > However, Perl generates the following suggestion on the @header{} > > assignment statements, > > > > "Scalar value @header{"keys"} better written as $header{"keys"} at > > iifm.pl line..." > > > > If I rewrite it as Perl suggests, the two %header{} elements get > > initialized to the size of the arrays instead of the arrays. Why does Perl > > make this suggestion, and how do I get rid of it without getting rid of > > the "use warnings" statement? > > > > Thanks, --H > > > > use strict; > > use warnings; > > my %header; > > > > open( IN, "<", $ARGV[0] ); > > > > @header{"keys"} = split(/\t\n/, <IN>); > > @header{"info"} = split(/\t\n/, <IN>); > > In perl you cann't store array as value of hash but reference. > > maybe following is what you want. > > use strict; > use warnings; > > my %headers; > > open IN, "<$ARGV[0]"; > my @v1 = split("\t \n", <IN>); > my @v2 = split("\t \n", <IN>); Do you really mean "\t \n"? > $headers{"keys"} = \@v1; > $headers{"info"} = \@v2; This would be more elegantly done using anonymous array references: $headers{keys} = [split(/\t\n/, <IN>)]; $headers{info} = [split(/\t\n/, <IN>)]; Regards, Shlomi Fish > for my $key (keys %headers){ > print "$key => @{$headers{$key}}\n"; > } > > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Best Introductory Programming Language - http://shlom.in/intro-lang An apple a day keeps the doctor away. Two apples a day will keep two doctors away. — one of Shlomi Fish’s relatives Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/