[clue-tech] [spam?] text processing howto

Collins Richey crichey at gmail.com
Wed Oct 6 20:38:57 MDT 2010


On Wed, Oct 6, 2010 at 6:36 PM, Collins Richey <crichey at gmail.com> wrote:

>
> You can do the same thing in two lines of perl.

Well, I lied about 2 lines; I forgot about printing. Anyway, in the
much maligned perl code ...

#!/usr/bin/perl
# string has imbedded tabs and varying number of spaces
$string = "this          that1   that2   that3          theotherthing";
@list = split(/\s+/, $string);
foreach $item (@list) {
        print "$item\n";
}
# and if you want just the otherthing
print "$list[$#list]\n"

# or split out theotherthing leaving only the thises and thats in the array
$item = pop @list
print "$item\n";



-- 
Collins Richey
     If you fill your heart with regrets of yesterday and the worries
     of tomorrow, you have no today to be thankful for.


More information about the clue-tech mailing list