<?xml version="1.0" encoding="windows-1252"?>
<node id="358786" title="jmcnamara's scratchpad" created="2004-06-01 19:18:33" updated="2005-08-12 21:24:35">
<type id="182711">
scratchpad</type>
<author id="45414">
jmcnamara</author>
<data>
<field name="doctext">
&lt;br&gt;



&lt;p&gt;
All this scratching is making me itch.

&lt;p&gt;
For [scratch]. Print serial numbers from a file that are not included in another "subset" file. Both files must be sorted:

&lt;code&gt;

    #!/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 (&lt;SUBSET&gt;) {

        my $subset_num = $_;
        my $serial_num;

        print $serial_num while ($serial_num = &lt;SERIAL&gt;) &lt; $subset_num;
    }

    print while &lt;SERIAL&gt;;


    __END__




&lt;/code&gt;

The following works for unsorted files but is less efficient than the above example:
&lt;p&gt;
&lt;code&gt;
    #!/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 &lt;SUBSET&gt;;

    while (&lt;SERIAL&gt;) {print unless $used{$_}}


    __END__

&lt;/code&gt;


&lt;!-- --&gt;
&lt;!-- --&gt;


&lt;code&gt;





# Find the version number of a module
perl -le 'eval "require $ARGV[0]" and print $ARGV[0]-&gt;VERSION' Some::Module


# 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.





&lt;/code&gt;
</field>
</data>
</node>
