bory has asked for the wisdom of the Perl Monks concerning the following question:

Hi if I have an array like this (with lots of spaces and new lines):
my @test=("aaa bbbbb cccc"); How can I transform it in: my @test=("aaabbbccc");
Thanks

Edited by Chady -- added code tags.

Replies are listed 'Best First'.
Re: spliting new lines and spaces
by Roger (Parson) on May 07, 2004 at 15:53 UTC
    Do you mean you want to eliminate spaces and new lines?
    use Data::Dumper; my @test=("aaa bbbbb cccc"); my @test = map { s/\s//g; $_ } @test; print Dumper(\@test);

    And the output is as expected:
    $VAR1 = [ 'aaabbbbbcccc' ];

Re: spliting new lines and spaces
by krusty (Hermit) on May 07, 2004 at 15:57 UTC
    The sample code you have given only contains one element in the array. Is that what you really meant?

    The following code should work to get rid of any whitespace characters (tab, newline, form feed, literal space, carraige return) in the elements of your array:
    foreach (@test){ s/\s+//g; }
    Good luck,
    Kris