Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: comparing columns using regular expression

by thezip (Vicar)
on Jan 19, 2011 at 04:15 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-20 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found