A short question: I want to give users of my script the possibility to enter arbitrary arrays, e.g. "[1 .. 5]" or "[1, 2, 6, 9 .. 20]". Currently, I just eval the given string (obviously not very secure!) and perlcritic gives me a Level 5 warning.
My current code:
my $arr = eval $patternData{"arr"};
unless ($arr) {
# fixes <arr> values like "(1 .. 5)"
$arr = undef;
@$arr = eval $patternData{"arr"};
}
EDIT: As many people are asking: This is a "the-more-the-better" thingy. I search a solution both powerful (in terms of expressiveness) and simple (in terms of debugging, parsing and writing input). Also: It absolutely has to support ranges (arrays with well above 100 entries should be entered easily)
and - as always - I forgot to include my version. 5.8 is a must, I'm working with vSphere API, which requires 5.8 (I miss ~~ so much !)
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)
Copyright 1987-2006, Larry Wall
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46
[ map { ($_, $_+7 ) } split //, q(123)]or how much expressiveness do you really need?