Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: How do I combine SPLIT with trimming white space

by Grey Fox (Chaplain)
on Aug 11, 2009 at 17:57 UTC ( #787726=note: print w/replies, xml ) Need Help??

in reply to How do I combine SPLIT with trimming white space

Fletch I incorporated a couple of your ideas. I also didn't realize you can do the do blocks in perl, very helpful.
Also Moritz thanks I didn't realize, you can use a complex regex in the splits, nice to know.
The code was changed adding:
foreach my $entry ( split( /;/, $file_data ) ) { do { s/^\s+//; s/\s+$//; } for $entry; push @email_list, $entry; } print join( "\n", sort(@email_list)), "\n";
Thanks again.
-- Grey Fox
"We are grey. We stand between the darkness and the light" B5

Replies are listed 'Best First'.
Re^2: How do I combine SPLIT with trimming white space
by codeacrobat (Chaplain) on Aug 11, 2009 at 20:36 UTC
    Hi, If you want to chain multiple s/// statements, then you can use a comma and get rid of the ugly do and the curlys.
    foreach my $entry ( split( /;/, $file_data ) ) { s/^\s+//, s/\s+$// for $entry; push @email_list, $entry; } print join( "\n", sort(@email_list)), "\n";
    If you are a Perl::Critic follower then you are not allowed to use the for statement modifier Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls. However consider this using List::MoreUtils apply function.
    use List::MoreUtils qw(apply); foreach my $entry ( split( /;/, $file_data ) ) { push @email_list, apply { s/^\s+//; s/\s+$// } $entry; } print join( "\n", sort(@email_list)), "\n";


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2022-08-17 02:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found