Christopher Spears wrote:
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;


# from here

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

# try:
my @allfiles = glob( '*' );


foreach $_(@allfiles){
        if ($_ =~ \$regexp){

# bad regular expression. try:
 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

"Of course we'll win; we're British"
- another British military motto


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


--
Just my 0.00000002 million dollars worth,
 Shawn

"For the things we have to learn before we can do them, we learn by doing them."
 Aristotle

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


Reply via email to