Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Help Sorting a CSV File

by dbuckhal (Hermit)
on Oct 05, 2019 at 05:16 UTC ( #11107082=note: print w/replies, xml ) Need Help??


in reply to Help Sorting a CSV File

maybe?
#!/usr/bin/perl use strict; use warnings; my $file = shift or die; # read csv file... my $hash; open my $fh, "<", $file; my $result = <$fh>; # grab header... while ( my $line = <$fh> ) { # then read rest of file. push @{$hash->{ [ split /,/, $line ]->[1] }}, $line; } $result .= join '', @{$hash->{$_}} for sort keys $hash; print $result; __output__ CAT_HEADER,SUPPLIER_CODE,CUSTOMER_CODE CAT_LINE,0001P,ABC12345,20190924,,1,Z,3.36 CAT_LINE,0001P,ABC23456,20190924,,1,Z,2.24 CAT_LINE,0001P,ABC34567,20190924,,1,Z,2.24 CAT_LINE,0002P,ABC12345,20190924,,1,Z,3.36 CAT_LINE,0002P,ABC23456,20190924,,1,Z,2.24 CAT_LINE,0002P,ABC34567,20190924,,1,Z,2.24

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-01-25 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (67 votes). Check out past polls.

    Notices?