Re: first post
am 21.07.2011 12:03:13 von sencond gunOn Jul 21, 10:28=A0am, g...@pbwe.com ("H Kern") wrote:
> Hi, My first newbie post. I wish to have two arrays indexed by a hash =A0
> table. The simple program below runs and behaves properly initializing th=
e =A0
> hash table with the information I wish it to have.
>
> However, Perl generates the following suggestion on the @header{} =A0
> assignment statements,
>
> =A0 =A0"Scalar value @header{"keys"} better written as $header{"keys"} at=
=A0
> iifm.pl line..."
>
> If I rewrite it as Perl suggests, the two %header{} elements get =A0
> initialized to the size of the arrays instead of the arrays. Why does Per=
l =A0
> make this suggestion, and how do I get rid of it without getting rid of =
=A0
> the "use warnings" statement?
>
> Thanks, --H
>
> use strict;
> use warnings;
> my %header;
>
> open( IN, "<", $ARGV[0] );
>
> @header{"keys"} =3D split(/\t\n/,
> @header{"info"} =3D split(/\t\n/,
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 =3D split("\t \n",
my @v2 =3D split("\t \n",
$headers{"keys"} =3D \@v1;
$headers{"info"} =3D \@v2;
for my $key (keys %headers){
print "$key =3D> @{$headers{$key}}\n";
}
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/