vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use Data::Dumper; my $test="[1,2,3]"; my @var = split(/[\]\[,]/,"[1,2,3]"); print Dumper \@var;
In the above code I split the string using the separators [], So I got the output in the @var array as follows.
$VAR1 = [ '', '1', '2', '3' ];
As I know that I get the empty element at first because it matches the first character of $var matched the regular expressions. I do not want this empty element in the @var array.
I did the following to avoid the empty element as
use strict; use warnings; use Data::Dumper; my $test="[1,2,3]"; my $empty; my ($empty,@var) = split(/[\]\[,]/,"[1,2,3]"); print Dumper \@var;
Do you have any better idea to avoid the empty element ?
UpdateTitle modified
Back to
Seekers of Perl Wisdom