first post

first post

am 21.07.2011 04:28:25 von H Kern

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/, );
@header{"info"} = split(/\t\n/, );



--
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 04:36:08 von Shawn H Corey

On 11-07-20 10:28 PM, H Kern wrote:
> use strict;
> use warnings;
> my %header;
>
> open( IN, "<", $ARGV[0] );
>
> @header{"keys"} = split(/\t\n/, );
> @header{"info"} = split(/\t\n/, );

I'm not sure but I think this is what you want:

( $header{"keys"}, $header{"info"} ) = split(/\t\n/, );


Also, Data::Dumper will dump the complex structures so you can see
exactly what it is. Comment it out to stop its output.

use Data::Dumper;
print Dumper \%header;

Data::Dumper is a standard module and is installed with Perl. For a
list of all the standard modules and pragmatics, see `perldoc perlmodlib`.


--
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/