develooper Front page | perl.beginners | Postings from April 2002

searching arrays with foreign element

Thread Next
Johnson, Shaunn
April 30, 2002 16:08
searching arrays with foreign element
Message ID:

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



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

I'm getting errors about:

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

* readline() on closed filehandle main::file at 
../ 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?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About