Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Regular expression help

by Don Coyote (Pilgrim)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004930]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2018-06-19 20:52 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.