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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Remove empty element.
by ikegami (Patriarch) on Jul 14, 2009 at 05:16 UTC | |
|
Re: Remove empty element.
by jwkrahn (Abbot) on Jul 14, 2009 at 05:16 UTC | |
by vinoth.ree (Monsignor) on Jul 14, 2009 at 05:39 UTC | |
by jwkrahn (Abbot) on Jul 14, 2009 at 06:32 UTC | |
by vinoth.ree (Monsignor) on Jul 14, 2009 at 06:39 UTC | |
by Utilitarian (Vicar) on Jul 14, 2009 at 06:33 UTC | |
by vinoth.ree (Monsignor) on Jul 14, 2009 at 07:06 UTC | |
by Utilitarian (Vicar) on Jul 14, 2009 at 07:32 UTC | |
| |
|
Re: Remove empty element.
by rovf (Priest) on Jul 14, 2009 at 07:45 UTC | |
by pemungkah (Priest) on Jul 14, 2009 at 18:43 UTC | |
by afoken (Chancellor) on Jul 14, 2009 at 19:38 UTC | |
by pemungkah (Priest) on Jul 15, 2009 at 20:48 UTC | |
|
Winnowing solutions to the best one (was Re: Remove empty element.)
by roboticus (Chancellor) on Jul 14, 2009 at 11:51 UTC | |
|
Re: Remove empty element.
by Bloodnok (Vicar) on Jul 14, 2009 at 13:54 UTC |