Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to read zipped file in perl

by Eily (Monsignor)
on Jan 09, 2014 at 09:43 UTC ( [id://1069935]=note: print w/replies, xml ) Need Help??


in reply to How to read zipped file in perl

This works far better than it should, (split /\|/)[4] means that you read values separated by a |, and take the fifth (Edit: not fourth, thanks choroba). Since your values are separated by commas, that's either not your real input or the code you actually used. Do read the documentation on split if you intend to use it. The [4] means "only the fifth value", and join is used to join several values, so in this case, it is useless.

For your expected result, you could do something like that :

while (my $line = <$handle>) { my ($number, $key1, $dontcare, $country, $key2) = split /:/, $line; + # Something to change here $result{$key1}{$key2}++; } print Dumper(\%result);
You still have to change something for the split to work, that's because I didn't want you to just copy and paste my code without understanding anything, and because I'm not really sure what you values separator actually is. In the list of variable in the my(), you should rename key1 and key2 to give them meaningful names, and you can replace all the variables you won't use by undef.

To have something more useful with Data::Dumper, you should write print Dumper(\%result);, the backslash returns a reference to your hash, which means that instead of using Dumper on each element (key or value) of %result, you'll do it on %result as a whole.

There is one thing you do correctly though, and it's reading from a zipped file. So you don't have to ask for that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-24 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found