BUU has asked for the wisdom of the Perl Monks concerning the following question:
which solved the problem, but nesting maps seemed a tad hackish and it seemd to be that some solution could be devised using hash slices and be much cleaner.. but I couldn't think of one, so I ask the assorted monks here if anyone can think of a better way to do this?my @old_hashes; my @new_hashes; my @wanted_keys = qw/foo bar baz/; #etc @new_hashes = map{ my $x = $_; +{ map { $_=>$x->{$_} } @wanted_keys } +} @old_hashes;
You'll notice that most of the fields are seperated by white space, except that the middle field can contain embedded whitespace! My solution to this was to devise a regex that basically looks like this:6 2 78 testing stuff 0 69.68.119.54:28960 34756 2500 +0 7 4 118 [:EsU:]|BLaZE| 0 24.86.4.164:28960 7248 500 +0 6 2 78 tessssssstinggggggggggg REAAAAA 40 69.68.119.54:28960 + 34756 25000
Anyone see a better way to parse the above data?my @cols = m/ (\d{1,3}) \ + (-?\d+) \ + (\d{1,4}|CNCT) \ (.+?)(?:\^7)? \ + (\d{1,6}) \ (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:-?\d{1,5}) \ + (\d{1,5}) \ + (\d{3,5}) /x;
"6", "2", "78", "testing stuff", "0", "69.68.119.54:28960", "34756", " +25000" "7", "4", "118", "[:EsU:]|BLaZE|", "0", "24.86.4.164:28960", "7248", " +5000" "6", "2", "78", "tessssssstinggggggggggg REAAAAA", "40", "69.68.119.54 +:28960", "34756", "25000"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing bizarre non delimted data and hash slices
by davorg (Chancellor) on Feb 01, 2004 at 10:18 UTC | |
|
Re: Parsing bizarre non delimted data and hash slices
by ysth (Canon) on Feb 01, 2004 at 10:42 UTC | |
by Not_a_Number (Prior) on Feb 01, 2004 at 15:39 UTC | |
|
Re: Parsing bizarre non delimted data and hash slices
by Roger (Parson) on Feb 01, 2004 at 10:40 UTC |