Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: Sorting one column of results

by choroba (Chancellor)
on Nov 12, 2012 at 11:18 UTC ( #1003418=note: print w/replies, xml ) Need Help??

in reply to Re^2: Sorting one column of results
in thread Sorting one column of results

I assumed you knew more about Perl. My fault. When using a function you do not know yet, consult its documentation.
Here is what I had in mind:
#!/usr/bin/perl use warnings; use strict; my $infile = 'orders.txt'; my $output = 'orders_today.txt'; open my $IN, '<', $infile or die "ERROR: Cannot open '$infile': $!"; my @out; while (<$IN>) { chomp; my @text = split /\t/; push @out, [@text]; } open my $OUT, '>', $output or die "Cannot open '$output': $!"; print {$OUT} map "@$_\n", sort { $a->[10] cmp $b->[10] } @out;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: Sorting one column of results
by perlnoobster (Sexton) on Nov 12, 2012 at 11:25 UTC
    hello choroba, Thank you for replying, the coding works however the output is all in one line, even though the split function is in the coding? not sure why? and is it possible to only print the following (as opposed to the entire original file?) print OUT "$text[10]\n$text[11]\nQuantity:$text[12]\n\n$text[16]\n$text[17]\n$text[18]\n$text[19]\n$text[20]\n$text[21]\n$text[22]\n$text[23]\n\n\n"; Thank you so much :)!
      for my $line (sort { $a->[10] cmp $b->[10] } @out) { printf $OUT "%s\n%s\n" . "Quantity:%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n\n", @$line[10..12], @$line[16..23]; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003418]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-08-18 18:21 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (306 votes). Check out past polls.