Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: How to read zipped file in perl

by Eily (Vicar)
on Jan 09, 2014 at 09:43 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069935]
[stevieb]: hmmm seems the C# library doesn't work right on win10. With berrybrew, only part of the perl portable zip is extracted. no errors nothing. Guess I have to look at switching out zip libraries. sigh

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-03-28 16:20 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (335 votes). Check out past polls.