Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Separating array contents

by jnyman (Acolyte)
on Jun 07, 2013 at 08:53 UTC ( #1037635=note: print w/ replies, xml ) Need Help??


in reply to Separating array contents

Suggestion:

use 5.014; use Data::Dumper; my @arr = ('!', 'my', 'name', '!', 'is ', '!'); my $joined = join '' => map { s/^\s+|\s+$//g; $_ } @arr; $joined =~ s/^!|!$//g; my @result = split /!/ => $joined; say Dumper(@result);
This will handle the !-character in the beginning so that it won't generate an empty cell. It also trims the strings in the cells as in your description you had "is " -> "is". Update: improved trim regex


Comment on Re: Separating array contents
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037635]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-07-10 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (212 votes), past polls