Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: Making a Hash of Arrays

by chromatic (Archbishop)
on Sep 22, 2000 at 22:55 UTC ( [id://33682]=note: print w/replies, xml ) Need Help??


in reply to Making a Hash of Arrays

You're putting stuff in the anonymous array (potentially) twice:
$hash{$arg} = [@array]; push (@{ $hash{$arg} }, @array) unless /^\#|none|unkno/i;
The first line copies all of the contents of @array and populates an anonymous array with them, sticking it in the hash slot.

The second pushes all of the elements of @array onto the anonymous array, unless your regex matches. (Which it probably won't.)

I'd do something like:

while (<FILE>) { next if /^#/; next if /none|unkno/i; chomp; # print "$_\n"; returns expected results my @array = split; # printing each array element also passes here $hash{$arg} = [@array]; }

Replies are listed 'Best First'.
RE: RE: Making a Hash of Arrays
by Limo (Scribe) on Sep 22, 2000 at 23:00 UTC
    I just saw that! I was just getting ready to update my post. When I remove the line:
    $hash{$arg} = [@array];
    things seem better, although printing each key/value seems to print "value" as one continuous string.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://33682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found