Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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


Comment on Re: comparing columns using regular expression
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2014-11-01 03:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (227 votes), past polls