Next | Program Repair Shop | 137 |
Here's an extremely common special case of this problem:
Subject: Re: string tokenization Message-Id: <20010627.084604.1001243552.6624@dhthomaslnx.mcafee.com>
> I am working on an autometic emailing program...intended to be > written in perl I have a file of rows of email addresses and > names separated by a space and each entry by a linefeed > > emailadd FirstName LastName > emailadd2 FN2 LN2
... if ($line =~ /(\w+)\s(\w+)\s(\w+)/) { my $email = $1; my $first = $2; my $last = $3; ...
This is The swswsw Problem
When you see a lot of \s alternating with \w+ or \d* or .+ or \S*, consider using split instead:
my ($email, $first, $last) = split /\s/, $line; next unless defined $last;
Next | Copyright © 2002 M. J. Dominus |