in reply to Re: Re: Removing duplicates
in thread Removing duplicates

another approach to this step?

Of course! :-)

The idiomatic slurp goes something like this:

my $data = do { local (@ARGV, $/) = $filename; <> };

You may see why I chose to use File::Slurp originally. To integrate that into the second snippet, it would be:

#!/usr/bin/perl use strict; use warnings; my $file = shift or die "Usage: $0 file2 < another-file"; my $file_contents = do { local (@ARGV, $/) = $file; <> }; my $nets = join "|", map {chomp;$_} $file_contents; /$nets/ or print while <STDIN>;

Note: this code is untested.

Update: please note that some people get upset when you write "PERL." The language is called Perl, and the program that executes Perl code is called perl. Perl is not an acronym, so capitalizing its name makes it look like you're shouting.

Replies are listed 'Best First'.
Re: Re: Re: Re: Removing duplicates
by RCP (Acolyte) on Mar 04, 2004 at 12:33 UTC
    Didn't mean to shout Perl, more of praise over what I have been using (Korn). I ran your program and it seems to do the opposite of what was expected. "another-file" should strip out any lines in "file2", thats contained in "another-file" and print out only the lines that are not contained in "another-file". I just found out that the book I brought, a few months ago, was not ideally suited for beginners, have any suggestions for a good beginners book? Thanks, RCP