0

Basically I'm trying to replace with whatever is returned from a function call from an object. But I need a return value from the regex search as the argument. It's a little tricky but the code should speak for itself:

while ( $token =~ s/\$P\(([a-z0-9A-Z_]+)\)/$db->getValue("params", qw($1))/e ) { }

The error I'm getting is that $1 is not getting evaluated to anything (the argument literally becomes "$1") so it screws up my getValue() method.

Cheers

1 Answer 1

5

The qw() functions quotes "words". I.e. it splits a string at all whitespace characters and returns that list. It does not interpolate.

You can just use the variable "as is":

s/\$P\(([a-z0-9A-Z_]+)\)/$db->getValue("params", $1)/e

The qw() function is very different from

  • q(abc) (<=> 'abc'),
  • qq(abc) (<=> "abc"), and
  • qx(abc) (<=> `abc`) or
  • qr(abc) (<=> m/abc/):

qw(a b c) <=> ('a', 'b', 'c')

Sign up to request clarification or add additional context in comments.

1 Comment

You're right, I was using the qw() function incorrectly. Turns out I don't need it. Thanks bro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.