in reply to Split(), Initial Spaces, & a limit?
Anon, ++jethro, and ++ikegami, thanks for the great responses.
The reason I asked this question is because I'm seeing this problem when I use Sort::Fields. The script below will show what I mean:
You'll see in the output that the two fieldsorts() get sorted differently. I contacted the module owner about it, but in the mean time was trying to figure out how to fix it on my own.use strict; use warnings; use Sort::Fields; use Data::Dumper; my @data = ( " 56 1752.eps", " 56 2613.eps", " 56 3469.eps", " 8 INPUT000", " 16 INPUT001", " 16 INPUT002", " 96 MTA.1.ps", " 96 MTA.6.ps", " 80 MTA.7.ps", " 32 head.eps", " 8 labs", " 0 lib", " 8 mkexe.bat", " 112 out", " 0 screenshots", "8720 trace.exe", " 16 trace.pl", " 8 tracehosts", "1160 trace.041409.exe", "1160 trace.orig.exe", ); # Initial spaces in column 1 don't sort the same as... my @sorted = fieldsort( ['1n'], @data); print STDERR "First sorted DUMP:\n", Dumper(\@sorted), "\n"; my @data2 = grep s/^/1 /, @data; # ...initial spaces in column 2! @sorted = fieldsort( ['2n'], @data2); print STDERR "Second sorted DUMP:\n", Dumper(\@sorted), "\n";
If you look in make_fieldsort() sub in the Sort::Fields code, you'll see the nested map commands. I'm just getting comfortable with map, but this nested one is really throwing me for a loop (heh). I just can't seem to come up with the right solution here.
Any help for a poor, confused, I-only-seem-to-be-able-to-understand-non-nested-map-commands type person?
Thanks
-Craig
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bug in Sort::Fields?
by ikegami (Patriarch) on Jul 20, 2010 at 17:29 UTC | |
by cmv (Chaplain) on Jul 20, 2010 at 18:39 UTC | |
by ikegami (Patriarch) on Jul 20, 2010 at 19:02 UTC | |
by cmv (Chaplain) on Jul 20, 2010 at 19:14 UTC | |
by ikegami (Patriarch) on Jul 20, 2010 at 19:17 UTC | |
by ikegami (Patriarch) on Jul 20, 2010 at 19:28 UTC | |
| |
|
Re: Bug in Sort::Fields?
by ikegami (Patriarch) on Jul 20, 2010 at 19:32 UTC | |
by cmv (Chaplain) on Jul 20, 2010 at 20:07 UTC |