in reply to a really dumb regular expression question

It takes a while for it to really sink in, sometimes. I've hit the ah-ha moment, but I still make mistakes, do things inefficently .... etc. but I'm getting the hang of it. That being said ... your RE:
if($vacation_str =~ /^.*$HOME\/$library::common{username}\/.vacation.m +sg/i)
has a fairly major problem you should be aware of. You start out by saying:
^  # match the begining of a line
.  # match any character
*  # match 0 or more occourances of the preceeding character.
So, what you've said is ... match any line, the entire line, from begining to end. Oopse?

By default, operators like .* make things 'greedy' -- they match as much as possible. You can make it non-greed -- matchign as little as possible -- like this:

$myVar =~m/^.*?Help/;
now you're matching any chars, starting at the begining of the line, up until the regEx engine hits a 'Help'.

Hope that helps.

Oh, and another thing.. you may want to read perlre in the perl docs that come with the standard distribution. Reading through that, slowly, and several times whilst trying the examples in a script really helped me get my poor excuse for a brain wrapped around re's.

- Erik

Replies are listed 'Best First'.
Re: Re: a really dumb regular expression question
by jcpunk (Friar) on Jan 19, 2004 at 23:39 UTC
    Thanks for that 'perl' (i am so not funny) of wisdom. I will again make a trek into perlre perhaps I will be able to gleen a bit more from it this time.

    jcpunk
    all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)