Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Re: Sort alphabetically from file

by haukex (Archbishop)
on Jun 14, 2019 at 13:25 UTC ( [id://11101347]=note: print w/replies, xml ) Need Help??

in reply to Sort alphabetically from file

Please see How do I post a question effectively?: Please show the code you tried and use <code> tags to properly format your input, code, and output.

$ cat in.txt 1 2 3 delta 1 2 3 apricot 1 2 3 charlie 1 2 3 bravo 1 2 3 echo 1 2 3 fox $ cat #!/usr/bin/env perl use warnings; use strict; my @rows; while ( my $line = <> ) { my @fields = split ' ', $line; push @rows, \@fields; } @rows = sort { $a->[3] cmp $b->[3] } @rows; for my $row (@rows) { print join(' ', @$row ), "\n"; } $ perl in.txt 1 2 3 apricot 1 2 3 bravo 1 2 3 charlie 1 2 3 delta 1 2 3 echo 1 2 3 fox

Update: To clarify: this is intended top be a simple example to get you started; it works on the data as you've provided it here, and I've had to guess what you want the output to look like. If it's not what you were looking for, then as I said, have a look at How do I post a question effectively? and also SSCCE.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-07-25 13:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.