Re: first post
am 21.07.2011 15:05:20 von Shlomi FishHi sencond,
On Thu, 21 Jul 2011 03:03:13 -0700 (PDT)
sencond gun
> 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{"k=
eys"} 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 P=
erl Â
> > 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"} =3D split(/\t\n/,
> > @header{"info"} =3D split(/\t\n/,
>=20
> In perl you cann't store array as value of hash but reference.
>=20
> maybe following is what you want.
>=20
> use strict;
> use warnings;
>=20
> my %headers;
>=20
> open IN, "<$ARGV[0]";
> my @v1 =3D split("\t \n",
> my @v2 =3D split("\t \n",
Do you really mean "\t \n"?
> $headers{"keys"} =3D \@v1;
> $headers{"info"} =3D \@v2;
This would be more elegantly done using anonymous array references:
$headers{keys} =3D [split(/\t\n/,
$headers{info} =3D [split(/\t\n/,
Regards,
Shlomi Fish
=20
> for my $key (keys %headers){
> print "$key =3D> @{$headers{$key}}\n";
> }
>=20
>=20
--=20
------------------------------------------------------------ -----
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.=20
â=94 one of Shlomi Fishâ=99s relatives
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/