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

Re: Matching elements in two arrays and printing the element next to the match.

by murugaperumal (Sexton)
on Mar 22, 2010 at 08:53 UTC ( #830046=note: print w/ replies, xml ) Need Help??


in reply to Matching elements in two arrays and printing the element next to the match.

use strict; use warnings; #this script is to match the two files and print the matched content i ++n the two files open (FILE1,"<A") or die "Can't Open $!"; my $var=<FILE1>; my @array=split(' ',$var); open (FILE2,"<B") or die "Can't Open $!"; my @new; while(<FILE2>) { chomp; push(@new, $_); } my $i; my $line; open(OUT,">nrset.txt"); foreach $line (@array) { chomp $line; for($i=0;$i<$#new;$i++) { chomp $new[$i]; if ($new[$i]=~/$line/i) { print OUT "$new[$i]\n$new[$i+1]\n"; } } }


Comment on Re: Matching elements in two arrays and printing the element next to the match.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-09-20 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls