in reply to need help to create array dynamically
Doesn't the data look close to a data structure already? A few regexes and an eval ...
#!/usr/bin/perl use Data::Dumper; use strict; use warnings; local $/; my $data=<DATA>; $data=~s{\[}{[qw(}sg; $data=~s{\]}{)],}sg; eval '$data=\['.$data.']'; warn Data::Dumper->Dump([\$data],[qw(*data)]).' '; __DATA__ [ abc def ] [ ghi jkl mno ]
and we have ...
$data = \\[ [ 'abc', 'def' ], [ 'ghi', 'jkl', 'mno' ] ]; at pmdata.pl line 13, <DATA> chunk 1.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: need help to create array dynamically
by Anonymous Monk on Jan 24, 2013 at 13:17 UTC |