Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My Goal is to push the following into an array.For some reason when I print the data in the array,nothing is getting printed.Can anyone advise what should I change in the below code to make it happen?

1.All files with .lib/.lib.*(with .lib,.lib.1,.lib.2... ) extension 2.Files with name serport,serport_d

#!/usr/bin/perl -w use strict; use warnings; use File::Find; use Getopt::Long; my %options=(); my @libs; my %seen; #getopt("b",\%options); GetOptions (\%options, 'data=s') or die("\nERROR:Invalid Option\n"); find(sub { push @libs, "$_\n" if -f && /\.lib$ && serport && serport_d/ && + !$seen{$_}++; }, "$options{data}"); for my $file (@libs) { print "\n$file"; }

Replies are listed 'Best First'.
Re: Data not getting stored in an array
by wind (Priest) on Apr 24, 2011 at 22:51 UTC
    Fix your regex
    find(sub { push @libs, "$_\n" if -f && /\.lib$|serport|serport_d/ && !$seen{$ +_}++; }, "$options{data}");

      Thanks Wind,I figured that out,what I am not able to figure out is ,how to fix the regex to store all .lib,.lib.1,.lib.2.....etc.Can you please help?

        By /\.lib(?:\.\d+)?$/ or more explicitly:
        find(sub { push @libs, "$_\n" if -f && /\.lib(?:\.\d+)?$|serport|serport_d/ & +& !$seen{$_}++; }, "$options{data}");