Re: Create two-dimensional Array from string
- From: jgraber@xxxxxx
- Date: 03 Apr 2008 13:05:16 -0500
jjcassidy@xxxxxxxxx writes:
On Apr 2, 1:21 pm, "pjfa...@xxxxxxxxx" <pjfa...@xxxxxxxxx> wrote:
I'm looking for the most efficient way to create a two dimensional
array from strings such as
MULTISET{ROW(1 ,' 3667 ','WARREN ','OH'),ROW(2 ,' 2948
','SHAKER HTS','OH')}
Let Perl parse it for you. You can *eval* it.
use Data::Dumper;
sub ROW (@) { return [ @_ ]; }
sub MULTISET (&) { return [ sort { $a->[0] <=> $b->[0] } shift()-
() ]; }
# observe:
my $multi_set = eval <<END_EVAL1;
MULTISET{ROW(1 ,' 3667 ','WARREN ','OH'),ROW(2 ,'
2948','SHAKER HTS','OH')}
END_EVAL1
Beware eval with unsanitized user inputs like
http://xkcd.com/327/
--
Joel
.
- Follow-Ups:
- Re: Create two-dimensional Array from string
- From: jjcassidy
- Re: Create two-dimensional Array from string
- References:
- Create two-dimensional Array from string
- From: pjfalbe@xxxxxxxxx
- Re: Create two-dimensional Array from string
- From: jjcassidy
- Create two-dimensional Array from string
- Prev by Date: Re: Problem adding new line !
- Next by Date: Re: New errors of export image format
- Previous by thread: Re: Create two-dimensional Array from string
- Next by thread: Re: Create two-dimensional Array from string
- Index(es):
Relevant Pages
|