J
Joe Saldana
I'm trying to write a script that will accept user input for a number of
variables. One of the variables will be a pipe for certain files. I can
read and store the | character in a variable. Later on, when I want to use
that variable in a match, I can't figure out how to tell perl that I am
trying to match a literal |. If I use an escaped | ( \| ), the match works
fine. I don't want alternation; I'd like to match a certain string followed
by any amount of whitespace followed by a delimiter (which will be "|"
sometimes) followed by more whitespace (any/none) followed by a second
variable. Right now, that looks like this:
if ($record =~ /$key\s*?\|\s*?$value/)
That, of course, is with the literal pipe. Assuming that I had the |
character in a variable called $Delmiter, is there a way for me to replace
the \| with $Delimiter in the match? That way the | wouldn't be hard-coded,
and I'd be able to use other delmiters specified by the user.
Thanks,
Joe
variables. One of the variables will be a pipe for certain files. I can
read and store the | character in a variable. Later on, when I want to use
that variable in a match, I can't figure out how to tell perl that I am
trying to match a literal |. If I use an escaped | ( \| ), the match works
fine. I don't want alternation; I'd like to match a certain string followed
by any amount of whitespace followed by a delimiter (which will be "|"
sometimes) followed by more whitespace (any/none) followed by a second
variable. Right now, that looks like this:
if ($record =~ /$key\s*?\|\s*?$value/)
That, of course, is with the literal pipe. Assuming that I had the |
character in a variable called $Delmiter, is there a way for me to replace
the \| with $Delimiter in the match? That way the | wouldn't be hard-coded,
and I'd be able to use other delmiters specified by the user.
Thanks,
Joe