Hi!

I'm trying to get back into Perl again by working
through Intermediate Perl.  Unfortunately, the Perl
part of my brain has atrophied!  

I'm working on the second exercise of the second
chapter.  I'm supposed to write a program that asks
the user to type a regular expression.  The program
then uses the regular expression to try to find a
match in the directory that I hard coded into the
program.  Here is what I have so far:

#!/usr/bin/perl -w
use strict;

print "Enter regular expression: ";

chomp(my $regexp = <STDIN>);
#print $regexp;

opendir(CPPDIR,"/home/io/chris_cpp/") or die "Could
not open directory: $!";
my @allfiles = readdir CPPDIR;
closedir CPPDIR;

foreach $_(@allfiles){
        if ($_ =~ \$regexp){
                print $_."\n";
        }
}

My problem lies with the matching part.  I'm not sure
how to use the string that I stored in the $regexp
variable as a regular expression.  Any hints?



"I'm the last person to pretend that I'm a radio.  I'd rather go out and be a 
color television set."
-David Bowie

"Who dares wins"
-British military motto

"I generally know what I'm doing."
-Buster Keaton

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to