in reply to Print to specific line
use warnings; use strict; my %lines; while (<DATA>) { my ($num) = $_ =~ /(\d+)$/; $lines{$num} = $_; } for (sort {$a <=> $b} keys %lines) { print $lines{$_}; } __DATA__ foo bar 4 goo 1 hoo boo boo 2 yeah 3
Outputs:
goo 1 hoo boo boo 2 yeah 3 foo bar 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Print to specific line
by 1nickt (Canon) on Jun 23, 2015 at 18:07 UTC | |
by toolic (Bishop) on Jun 23, 2015 at 18:23 UTC | |
by 1nickt (Canon) on Jun 23, 2015 at 18:31 UTC | |
by Anonymous Monk on Jun 23, 2015 at 18:32 UTC | |
by 1nickt (Canon) on Jun 23, 2015 at 18:39 UTC | |
| |
by GotToBTru (Prior) on Jun 23, 2015 at 18:49 UTC | |
by 1nickt (Canon) on Jun 23, 2015 at 18:54 UTC | |
by GotToBTru (Prior) on Jun 23, 2015 at 19:05 UTC |