Uri said:
where is 'regex engine would interpolate scalar variables' happening
there? in fact where is any interpolation happening there? if you knew
about regexes but didn't know how to apply them, how have you been using
them? did you really think that they could only be applied to $_ (i am
guessing this from the disconnect). if so then how could you have been
coding perl and not ever seen =~ used to bind an expression (commonly a
scalar var) to the regex?
inquiring minds want to know so we can fix the docs and close this trap
so it won't confuse future perl newbies.
Okay, confession time.
I went back and looked at a series of scripts I wrote during the course
of this week. Essentially, what is happening is that we are getting
large pipe delimited files that we have to edit and upload. We do this
through a series of steps (and unimaginitively I named the scripts
step1.plx, step2.plx, and so on). Step four consists of printing out a
document to physically check the values, which I do by writing an
OUTFILE using an appropriate format. The input file is a .txt file, and
I wanted to use the same name but with a .rtf or .doc extensions. The
user can them open them natively in Word and print them on her Windows
workstation.
My other scripts did exactly what I wanted, something like $line =~
s/","/"|"/g. I guess I had a mental lapse when thinking outside the
loop (and I mean this literally). I was so focused on the trees that I
forgot that they were a part of the forest.
LESSON: When faced with a question, take a deep breath, check the
documentation, and look at the problem from another angle. I should
have done this before posting to c.l.p.misc -- I didn't, which was my
bad. Maybe a contributing factor is that I use vi as my working editor,
and regexes in vi differ from regexes in perl, and I had on my vi hat
rather than my perl hat.
You might consider revising the documentation to emphasize that the
binding operator matches the CONTENT of the scalar in the lhs, as well
as a literal. The re tutor states as follows: "If you've been around
Perl a while, all this talk of escape sequences may seem familiar.
Similar escape sequences are used in double-quoted strings and in fact
the regexps in Perl are mostly treated as double-quoted strings. This
means that variables can be used in regexps as well. Just like
double-quoted strings, the values of the variables in the regexp will
be substituted in before the regexp is evaluated for matching
purposes." This is buried pretty deep, and I didn't find it until I
went looking for it. I don't know if it would have helped me to have
emphasized it, but I will admit that it was one of those points that
escaped me until it bit me.
Thanks much for your help. Perl has turned into a real plus for my
organization, and I have found c.l.p.misc a really good resource, and I
appreciate the participation of those willing to extend a helping hand
to those of us who happen to be on the lower end of the learning curve.
CC