Howdy:

I'm looking for examples of how to use element 0
in one array as a search pattern and looking in
other arrays for that pattern.  Here's what I have
so far ...

[snip code]
#!/usr/bin/perl -w
use diagnostics;

# test to read two files into two arrays
# do a search for each *FIRST* element in the array per line
# and print the matching line in the second file into a
# new file


$file="command.txt";
$file2="command2.txt";

@array=<file>;
@array2=<file2>;

open (INFILE, ">/tmp/infile.txt") or die "Unable to open: $!";
while (<file2>) {
if (m!$array[0]!) {
        print INFILE $_;
        }
}
close INFILE;

[/snip code]

What I'm trying to do is use the first element in the first
file (which *should* be an array) and look for it's match
in the second array.  If I find the match, I print that
line.

I'm getting errors about:

* Name "main::array2" used only once: possible typo at 
../h_test.pl line 14 (#1)

* readline() on closed filehandle main::file at 
../h_test.pl line 13 (#2)

* Your perl code sux ... go back to bash shell ...
line 22 (#2) - (*grin*)

The errors go on to say that the filehandle i'm
trying to read got closed before the real fun
began.  But how?  I don't understand why the files
are closed.

Anyhow ... anyone happen to have examples of
something like this around?

-X 

Reply via email to