Grey Fox has asked for the wisdom of the Perl Monks concerning the following question:
Hello Fellow Monks
I wrote a perl script to seperate long lists of email seperated by a semi colon. What I would like to do with the code is combine the split with the trimming of white space so I don't need two arrays. Is there away to trim while loading the first array. Output is a sorted list of names. Thanks.
#!/pw/prod/svr4/bin/perl use warnings; use strict; my $file_data = 'Builder, Bob ;Stein, Franklin MSW; Boop, Elizabeth PHD Cc: Bear, + Izzy'; my @email_list; $file_data =~ s/CC:/;/ig; $file_data =~ s/PHD//ig; $file_data =~ s/MSW//ig; my @tmp_data = split( /;/, $file_data ); foreach my $entry (@tmp_data) { $entry =~ s/^[ \t]+|[ \t]+$//g; push( @email_list, $entry ); } foreach my $name ( sort(@email_list) ) { print "$name \n"; }
-- Grey Fox
"We are grey. We stand between the darkness and the light" B5
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I combine SPLIT with trimming white space
by Fletch (Bishop) on Aug 11, 2009 at 16:58 UTC | |
by Your Mother (Archbishop) on Aug 11, 2009 at 20:37 UTC | |
by Fletch (Bishop) on Aug 11, 2009 at 21:22 UTC | |
Re: How do I combine SPLIT with trimming white space
by moritz (Cardinal) on Aug 11, 2009 at 17:01 UTC | |
Re: How do I combine SPLIT with trimming white space
by Grey Fox (Chaplain) on Aug 11, 2009 at 17:57 UTC | |
by codeacrobat (Chaplain) on Aug 11, 2009 at 20:36 UTC | |
Re: How do I combine SPLIT with trimming white space
by Marshall (Canon) on Aug 11, 2009 at 20:26 UTC | |
by Grey Fox (Chaplain) on Aug 12, 2009 at 13:59 UTC | |
by Marshall (Canon) on Aug 14, 2009 at 17:13 UTC |
Back to
Seekers of Perl Wisdom