perlquestion
vinoth.ree
<c> use strict;
use warnings;
use Data::Dumper;
my $test="[1,2,3]";
my @var = split(/[\]\[,]/,"[1,2,3]");
print Dumper \@var;
</c>
<p>In the above code I split the string using the separators [], So I got the output in the @var array as follows.</p>
<c> $VAR1 = [
'',
'1',
'2',
'3'
];
</c>
<p>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.</p>
<p>I did the following to avoid the empty element as</p>
<c> use strict;
use warnings;
use Data::Dumper;
my $test="[1,2,3]";
my $empty;
my ($empty,@var) = split(/[\]\[,]/,"[1,2,3]");
print Dumper \@var;
</c>
<p>Do you have any better idea to avoid the empty element ?</p>
<b>Update</b>
<p>Title modified</p>