On Thursday, Nov 4, 2004, at 09:38 US/Central, Kevin Old wrote:
my $line = "31232000 07/28/04 DUC000 NET 60 DAYS RD 222264 UPSGNDSVR PREPAID";
What I'm looking for in lines like this are the customer number (DUC000) and a "code" that starts with UPS, or if the code doesn't start with UPS idealy I'd like to have whatever was in that place returned, but I can't figure that out and can settle for just nothing returned along with the customer number.
Can you tell us a little more about the data? Are the fields fixed with? Is the "code" that starts with UPS always the second to last word? Here's a possible solution based on guessing the formatting of the input data:
$ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS " . "RD 222264 UPSGNDSVR PREPAID"; $line =~ /\d+\s+\d+\/\d+\/\d+\s+(\w+).*\s+(\w+)\s+\S+$/; print "$1, $2\n"; ' DUC000, UPSGNDSVR
Here's another version which "simplifies" the pattern matches into spaces and non-spaces:
$ perl -e 'my $line = "31232000 07/28/04 DUC000 NET 60 DAYS " . "RD 222264 UPSGNDSVR PREPAID"; $line =~ /^\S+\s+\S+\s+(\S+).*\s+(\S+)\s+\S+$/; print "$1, $2\n"; ' DUC000, UPSGNDSVR
But if that works, you may want to revisit using split.
Let us know what you try and what works.
Regards, - Robert http://www.cwelug.org/downloads Help others get OpenSource. Distribute FLOSS for Windows, Linux, *BSD, and MacOS X with BitTorrent
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>