in reply to Re: Remove empty element.
in thread Remove empty element.

This works fine for numbers only, the element may be any character, In this case what can I do ?

Replies are listed 'Best First'.
Re^3: Remove empty element.
by jwkrahn (Abbot) on Jul 14, 2009 at 06:32 UTC
    my $test = "[1,2,3]"; my @var = $test =~ /[^][,]+/g; print Dumper \@var;

      Fantastic!! Works fine

Re^3: Remove empty element.
by Utilitarian (Vicar) on Jul 14, 2009 at 06:33 UTC
    The second example given by ikegami above should work for you , provided you have a defined separator that doesn't conflict with your data.

      But I get the error as,

      Use of uninitialized value in split at santhosh.pl line 27. $VAR1 = [];

      Following is the code I tried

      use strict; use warnings; use Data::Dumper; my $test="[1,2second,3third,fourth]"; my ($list) = $test =~ /\[ ( [^\]] ) \]/x; my @var = split /,/, $list; print Dumper \@var;
        There's a slight error in the regex,
        my ($list) = $test =~ /\[ ( [^\]]+ ) \]/x;
        resolves your issue here