Is this what you're trying to do Greg? Try running the script below:
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
my $data = "<{5,26} {20,42,64} {23,48}>"; # assuming it's read in from a
file
$data =~ s/(?<=})\s*(?={)/,/g; # replace spaces between number sets with commas
$data =~ s/[<{]/[/g; # replace < and { with [
$data =~ s/[}>]/]/g; # replace > and } with ]
my $list_of_list = eval $data; # we get an anonymous list of list
# DISPLAY the list of list
# ========================
# use dumper to print out list of list
print Dumper $list_of_list;
# or the step by step method
for my $outerlist (@$list_of_list) {
for my $innerlist (@$outerlist) {
print $innerlist . " ";
}
print "\n";
}
________________________________
From: Greg J <[email protected]>
To: [email protected]
Sent: Thu, January 27, 2011 10:15:48 AM
Subject: Regex
I am trying to extract numeric values from a data file and I'm having
trouble writing a regular expression that would do this.
My data looks like this: <{5, 26}{20, 42, 64}{23, 48}>
I am trying to turn this into a list of lists [ [5, 26], [20, 42, 64],
[23,48] ]
Any pointers would be greatly appreciated