in reply to complex input file
And the output -use strict; use warnings; chomp(my @title = split /\s+/, <DATA>); my %emp; while (<DATA>) { chomp(my @r = split/\s+/); push @{$emp{$r[0]}}, [ @r[1..$#r] ]; } foreach (reverse sort keys %emp) { print "$_"; foreach (@{$emp{$_}}) { print "\t$_->[0]\t$_->[1]\n"; } } __DATA__ EmpNum LOCATION Shift 23 54 1 11 65 3 23 54 2
23 54 1 54 2 11 65 3
use strict; use warnings; use Data::Dumper; chomp(my @title = split /\s+/, <DATA>); chomp(my @data = <DATA>); my @sorted_data = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [/^(\d+)/, $_] } @data; my $last_emp = ''; foreach my $d (@sorted_data) { $d =~ s/^$last_emp\b/' ' x length($last_emp)/e; $d =~ /^(\d+)/ and $last_emp = $1; print "$d\n"; } __DATA__ EmpNum LOCATION Shift 23 54 1 11 65 3 23 54 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: complex input file
by Anonymous Monk on Feb 18, 2004 at 05:06 UTC | |
by Roger (Parson) on Feb 18, 2004 at 05:41 UTC | |
|
Re: Re: complex input file
by Anonymous Monk on Feb 18, 2004 at 05:36 UTC | |
by Roger (Parson) on Feb 18, 2004 at 05:40 UTC | |
by Anonymous Monk on Feb 18, 2004 at 05:52 UTC | |
by Anonymous Monk on Feb 18, 2004 at 05:57 UTC | |
by Anonymous Monk on Feb 18, 2004 at 06:00 UTC |