Andrej Kastrin wrote:
and additional question: how does Perl know where are the input files (while we only wrote: open (TERM, $file_terms) or die "Can't open...)?

It comes from the command line. The statements:

  my $file_terms = shift;
  my $file_medline = shift;

are a shorten version of:

  my $file_terms = shift @ARGV;
  my $file_medline = shift @ARGV;

When a Perl script starts, the command line arguments are placed in the special array @ARGV. See `perldoc -f shift` and also see `perldoc perlvar` and search for ARGV.

For each field:

#!/usr/bin/perl

use strict;
use warnings;

my $file_terms = shift;
my $file_medline = shift;
open (TERM, $file_terms) or die "Can't open $file_terms: $!\n"; #open list of terms open (MEDL, $file_medline) or die "Can't open $file_medline: $!\n"; #open records file

chomp( my @terms = <TERM> );

while( my $line = <MEDL> ){
  print $line if grep { $line =~ /\b$_\b/ } @terms;
}

__END__


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to