[Courses] [Perl] Re: exercises

Dan dan at cellectivity.com
Sat May 7 01:48:12 EST 2005


Hi Karine.

I'm sorry: for some reason I didn't receive your post. I only saw it as
I browsed the LinuxChix archives.

Your first exercise is excellent. Good for you for remembering to begin
with "^" and end with ":".

> I wonder if there is a way to know when your regular expression
> is "enough".

That's a classic problem with regular expressions: it really is hard to
know that you won't get any false matches. Caveat hacker.

Now on to your second example:

> my $file = <STDIN>;
> 
> open MY_INPUT, "< $file" or die "Couldn't open input file: $!";

Notice that you didn't chomp the input, but the "open" statement takes it anyway.

> if ($line =~ /\s*#include /)

This is good, but you forgot to start the pattern with "^" this time. Caveat hackor!

-- 
 [Larry] Wall [inventor of Perl] believes that people think about
 things in different ways, that natural languages accommodate many
 mindsets, and that programming languages should too.
   - Jon Udell, in his essay, "A Perl Hacker in the Land of Python"




More information about the Courses mailing list