Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Regular expression help

by Don Coyote (Monk)
on Nov 21, 2012 at 14:33 UTC ( #1004930=note: print w/ replies, xml ) Need Help??


in reply to Regular expression help

Anannassa, I think you are expending too much energy on splitting up the lines to match the separate parts

Though to clear the id you could use split. I have suggested a substition to strip the id out of the line. You then just compare the whole of the remaining line against the 2nd file lines.

This is untested but, should do the trick, if not give you another way to approach the problem.

#strip the id, repeating for each @sample array as necessary foreach (@sample){ s/^ID\d+\s+(.*)/$1/; } #set an array to catch the mathcing lines my @matches #now compare each array element in @sample1 to each array element in @ +sample2 my ($line1, $line2); foreach $line1 (@sample1){ foreach $line2 (@sample2){ push(@matches, $line2) if ($line2 eq $line1); } } print join("\n", @matches);

this type of thing can also be done using greps,maps and hash key indexing.


Comment on Re: Regular expression help
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-27 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls