Hi monks, I have a code that reads like this:
my %csahash;
my $line=<>;
while($line=<>){
if($line=~ /\b(\d\w{3})\b/){
$csahash{$1}++;
}
}
and the ouput is this:
2buf= 48
1lsj= 6
2bp7= 12
1ye6= 36
8icc= 1
1a2n= 4
1lz6= 2
1pw1= 5
1e4d= 4
2f8j= 28
1iw8= 24
1qbd= 2
1kf4= 7
1z53= 3
1gxx= 2
1dd6= 10
1ke5= 10
2og7= 1
I have a very similar %hash like this:
%cathhash;
my $line2=<>;
while($line2=<>){
if($line2=~/\b(\d\w{3})\b/){
$cathhash{$line2}++;
}
}
which will print out very similar output. My question is to see which of those id nos match between the hashs and give me a print out of the matches preferabaly.
Thanks. A.
Ok many thanks for both ur tips. My code now looks like this :
my %csahash;
my $line=<>;
while($line=<>){
if($line=~ /\b(\d\w{3})\b/){
$csahash{$1}++;
}
}
%cathhash;
my $line2=<>;
while($line2=<>){
if($line2=~/\b(\d\w{3})\b/){
$cathhash{$line2}++;
}
}
foreach my $key(keys %csahash){
if(defined $cathhash{$key}){
print "$key matches. It's values are $csahash{$key} and $cathhash{$key
+}\n";
}
}
but when I try to execute it on the command prompt like this :
perl pl.pl csa.txt cath.txt
I get nothing just a blank cursor. do I have to do something with cntrl+D? I am bit new to perl so am having teething problems. Many thanks.
Ok, thanks again but when I run this code through I still get no print out, can someone tell me where I'm going wrong in my execution?
In reply to hash question
by ada
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.