On 14/05/2011 08:57, Agnello George wrote:
I got a string like this $string = ' [a b c d]' i need to get a b c d in to a array called @all. i was was trying to so a split with delimiter '\s+' but still i get [a b c d] but i want a b c d any idea how to get this done , thanks
By the way, a call to split with a single space string as the pattern is a special case. It is the default if no pattern is provided, and more than likely what you want. This is from perldoc -f split
As a special case, specifying a PATTERN of space (' ') will split on white space just as "split" with no arguments does. [...] A "split" on "/\s+/" is like a "split(' ')" except that any leading whitespace produces a null first field. A "split" with no arguments really does a "split(' ', $_)" internally.
I am sure the problem is more complex han you describe, but to be safe why not just remove the brackets before you do the split? A working program below.
HTH, Rob use strict; use warnings; my $string = ' [a b c d]'; $string =~ tr/[]//d; my @contents = split ' ', $string; print "$_\n" foreach @contents; **OUTPUT** a b c d -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/