Jeff 'Japhy' Pinyan wrote at Thu, 07 Aug 2003 20:19:22 -0400: > my ($city, $state, $zip) = $line =~ /^(.*) ([A-Z]{2}) (\d{5,9})$/; > > This assumes the fields are separated by a space. It also only checks for > AT LEAST 4 and AT MOST 9 digits, so it would let a 7-digit zip code > through. If you want to be more robust, the last part of the regex could > be > > (\d{5}(?:\d{4})?) > > which ensures 5 digits, and then optionally matches 4 more. Then again, > maybe just > > (\d{9}|\d{5}) > > is simpler on the eyes and brain. > > Another approach, if you don't really care about the format of the lines,
Why than not the very simple my ($city, $state, $zip) = $line =~ /(.*) (\w+) (\d+)/; The ^ and $ aren't necessary as Perl is greedy and the \w+, \d+ are enogh to get the data (also a .* would be enough) And otherwise, instead of a "crypting" reverse of reverse solution, I still would prefer to write something like my @col = split ' ', $line; my $zip = join ' ', @col[0..-3]; my ($state, $zip) = @col[-2,-1]; what could also be shortcutted to 2 lines :-) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]