in reply to Re^3: Easiest way to filter a file based on user input (updated)
in thread Easiest way to filter a file based on user input

I tried to implement the special number regex as such:

#!/usr/bin/env perl use strict; use warnings; use Regexp::Common; print "Enter limit: "; chomp( my $limit = <STDIN> ); $limit = abs($limit); open my $IN, '<', "xt_spacer_results.hairpin" or die $!; open my $SIFTED, '>', "new_xt_spacer_results.hairpin" or die $!; while (<$IN>){ next if /^None/; next if /^( $RE{num}{real}{-places=>2})/ && $1 > $limit; print $SIFTED $_; } close $IN; close $SIFTED;

But it aborts the program due to  use Regexp::Common; and it states:

Can't locate Regexp/Common.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at energy_sifter2.pl line 4. BEGIN failed--compilation aborted at energy_sifter2.pl line 4.

I'm not quite sure how to use modules. Do I download the module somehow and save it in the same file I'm working in?

Replies are listed 'Best First'.
Re^5: Easiest way to filter a file based on user input (updated)
by hippo (Archbishop) on Jul 07, 2017 at 16:44 UTC
    I'm not quite sure how to use modules. Do I download the module somehow and save it in the same file I'm working in?

    Brew yourself a big pot of coffee and have a thorough read of A Guide to Installing Modules. You won't look back.

      How do you apply the module to your script?

      use lib '/location/of/module/';

      or something along the lines of:

      use Regexp::Common

        The latter. See use for examples and the FAQ What's the difference between require and use? for more detail.

        Addendum: Also, almost every module (including Regexp::Common) has a SYNOPSIS section in its documentation which includes a code snippet showing how to use it.

        Perl and (almost) all of its modules have excellent documentation. It will pay you dividends to learn where that documentation is, how to search it and how to understand what you find there.