Data format:
attribname: data
Sample data:
cheese: good pizza: good bagel: good fire: bad
The code:
my $subFilter='(.+?): (.+)'; my @attrib = ($dataSet=~/$subFilter/g); for (@attrib) { print "$_\n"; }
Code spits out:
cheese good pizza good [etc...]
I was wondering what is the easiest way for Perly to do this? I am parsing the data from the log, the data above is garbage for simplicity. I'm new to Perl, I suspect I can do this with fanatical indexes, but I was wondering if there is a short way to implement this? Is there a way for capture groups to fit into two different variables instead of sequentially adding to the list along with all matches?
Edit: I want the attribute and its associated value to match so that I can do what I need. For example, if inside the for for loop I could access both the attribute name and the attribute value.
Edit:
I tried
my %attribs; while (my $line = <$data>) { my ($attrib, $value) = ($line=~m/$subFilter/); print $attribs{$attrib}," : ", $value,"\n"; }
and no luck :( I do not get any output with this. My data is in a variable, not in a file, because it is parsed from the set of parent data that is in the file. It would be convenient if my variable worked so that my (@attrib, @value) = ($line=~/$subFilter/g); populated the lists accordingly with a few matches.
Decision:
my @line = ($7 =~/(.+?)\n/g); for (@line) { my ($attrib, $value) = ($_=~m/$subFilter/); if ($attrib ne "") { print $attrib," : ", $value,"\n"; } }
perl
Joshua Enfield Jul 01 '10 at 17:02 2010-07-01 17:02
source share