The thing that is making it non-trivial is that the rules for the data are not as trivial as usual. I don't think I will explain the rules, but rather give an example.
(Name is Graq, Number is 634321, age 27, jameson is my fave drink, detest bells etc)# DATA: Start Graq Agnostic Number: 634321 age: 27 hair colour: black height: 73 weight: 123 legs: 2 arms: 2 jameson bells guinness favourite detests likes # DATA: End
Now this data is also surrounded by further noise, and may contain extra blank lines.
But the 'Number' tag is unique, and there is always exactly
70 lines of (non-empty) relavent data, so I can index
that and grab the lines I need.
So this gives me an array of 'useful' data. A big thanks to people in CB for some of the individual lines in there, but it is all starting to look a little clumsy (and I am stripping some unwanted values at [1])# CODE: Start #!perl -w use strict; my $pasteRaw; while(<STDIN>) { # Remove spaces from before ':' to avoid splitting on 'hair colour' +. substr($_, 0, 1+index($_, ":")) =~ tr/ //d; $pasteRaw .= $_; } my @pasteSplitAll = split( "[^:] |\n", $pasteRaw ); # [1] See below # Remove empty parts of the array. my @pasteNotEmpty = grep { $_ ne "" } @pasteSplitAll; # Defined an index for splicing later. my $index = 0; # Set the index (looking for 'Number') $pasteNotEmpty[$_] =~ /^Number/ and $index = $_ and last for 0..$#pasteNotEmpty; my @pasteUseful = splice( @pasteNotEmpty, $index-2, 70 ); $pasteUseful[$_] =~ s/^\w+:// for 0..$#pasteUseful; # CODE: End
So.. to my point. I am looking for some help in handling this data, preferably into a hash, so that I can do stuff with it.
Anything ranging from help on the individual REs to new approaches on tackling the problem as a whole. Am I just kicking a dead horse and might aswell write something a lot less generic?
In reply to More Regular Expressions (text data handling) by graq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |