Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

jmcnamara's scratchpad

by jmcnamara (Monsignor)
on Jun 01, 2004 at 23:18 UTC ( [id://358786]=scratchpad: print w/replies, xml ) Need Help??


All this scratching is making me itch.

For scratch. Print serial numbers from a file that are not included in another "subset" file. Both files must be sorted:

#!/usr/bin/perl -w use strict; die "Usage: $0 subset serial\n" unless @ARGV == 2; my $subset = shift; my $serial = shift; open SUBSET, $subset or die "Couldn't open $subset: $!\n"; open SERIAL, $serial or die "Couldn't open $serial: $!\n"; while (<SUBSET>) { my $subset_num = $_; my $serial_num; print $serial_num while ($serial_num = <SERIAL>) < $subset_num +; } print while <SERIAL>; __END__
The following works for unsorted files but is less efficient than the above example:

#!/usr/bin/perl -w use strict; die "Usage: $0 subset serial\n" unless @ARGV == 2; my $subset = shift; my $serial = shift; open SUBSET, $subset or die "Couldn't open $subset: $!\n"; open SERIAL, $serial or die "Couldn't open $serial: $!\n"; my %used; $used{$_}++ while <SUBSET>; while (<SERIAL>) {print unless $used{$_}} __END__
# Find the version number of a module perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::M +odule # Check if a module is installed perl -le 'print 0 + eval "require $ARGV[0]" ' Some::Module # Or this mnemonic cheat perl -exists -MSome::Module # Plain silly $ perl -wevest String vest may clash with future fashion at -e line 1.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2025-04-19 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.