Re: first post

Re: first post

am 21.07.2011 15:05:20 von Shlomi Fish

Hi sencond,

On Thu, 21 Jul 2011 03:03:13 -0700 (PDT)
sencond gun 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{"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/

Re: first post

am 21.07.2011 15:20:49 von Shawn H Corey

On 11-07-21 09:05 AM, Shlomi Fish wrote:
> Do you really mean "\t \n"?
>

If you do, it's better to write this as:

"\t\x20\n"

The extra effort of writing all those characters tells anyone who reads
it that you really, truly do mean it. :)


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/