Are you sure you want to use a regex to do this? I think it's much more natural to use unpack (or even split, possibly) to do what you're trying to do.
Update: I suppose I should mention that the *reason* it would be more natural to use unpack is because your columns are fixed-width columns. Unpack is great for extracting columnar data formatted in this way...
Try this to see if it works for you:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash = ( 'CA12DE' => 1 ); my $line = 'Box of Joe CA12DE 12345'; my @data = unpack 'A15A10A9', $line; print Dumper(\@data); my $searchkey = $data[1]; if (exists($hash{$searchkey})) { print qq(searchkey "$searchkey" exists in the hash...\n); }
__OUTPUT__ $VAR1 = [ 'Box of Joe', 'CA12DE', '12345' ]; searchkey "CA12DE" exists in the hash...
In reply to Re: comparing columns using regular expression
by thezip
in thread comparing columns using regular expression
by rocky13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |