in reply to Extract line, matching more than one variable

So - the guys above said their piece, but just for my own 2 cents, there's value to be had from this exercise, because doing multi-matching without getting too loopy is tricky.

So from your question, you have two filehandles, FILE1 and FILE2. You need to exract "a line" from FILE2 "that matches several values" from FILE1. So we need to presume you've already hit the matching conditions to know what you're looking for from FILE2.

Which is interesting, because if you know what the value is, then it gets reduced to:

(This is not valid, just giving you the idea)
FILE2 =~ s/my stuff to get removed//g;

In short, you need to give more information than you just did, because logically following what you wrote, you're asking us how to delete lines from a file that match a condition, which results in the above pseudo-code.

Replies are listed 'Best First'.
Re^2: Extract line, matching more than one variable
by yads25 (Initiate) on Nov 13, 2008 at 06:09 UTC
    There are two files, File 1 and File 2. Both have data in columns. Three variables from File 1, var1, var2 and var3 need to match a single line of file2 and that line needs to be extracted and appended in 'results file'. Wrote following code...could some one debug it for me. #!/usr/bin/perl -w #open file f-2 #print "Please type the filename of the data: "; $sasa_file= 'File1'; $pdbfile='File2'; # Remove the newline from the DNA filename open (MYXFILE,$sasa_file); open (PDBFILE, $pdbfile); while (<MYXFILE>){ chomp; @sa = split(/\t/,$_); #print "$sa[0] $sa1 $sa2\n"; #$res = substr $_, 0, 4; #$res_no = substr $_, 4, 5; #$atom =substr $_, 9, 3; while (<PDBFILE>){ chomp; $res = substr $_, 17, 3; $res_no = substr $_, 22, 4; $atom =substr $_, 13, 3; #print " $res $res_no $atom \n" ; # works fine if (( $sa[0]eq$res)&&($sa1==$res_no)&&($sa2 eq $atom)) { print "$_"; # does not print anything. } } } close MYXFILE; close PDBFILE;