Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: comparing columns using regular expression

by thezip (Vicar)
on Jan 19, 2011 at 04:15 UTC ( #883053=note: print w/replies, xml ) Need Help??

in reply to comparing columns using regular expression

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...

What can be asserted without proof can be dismissed without proof. - Christopher Hitchens

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://883053]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2020-01-28 06:41 GMT
Find Nodes?
    Voting Booth?