Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

jmcnamara's scratchpad

by jmcnamara (Monsignor)
on Jun 01, 2004 at 23:18 UTC ( #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
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-09-23 03:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls