Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] More fun with Perl



Perl hackers, I need your help!

Dig this code fragment (i.e. line of code):


$str =~ s/\[?$chunk\]?/$value/;


Now, allow me to paste a bit of a debug session:


  DB<6> p $str
What is foo?    $foo

  DB<7> p $chunk
$foo
  DB<8> p $str =~ /\$foo/
1
  DB<9> p $chunk eq "\$foo"
1
  DB<10> p $str =~ /$chunk/



My question is this: when $chunk == "\$foo" and $str =~ /\$foo/ is true, why
is $str =~ /$chunk/ not true?

My theory is that Perl is interpreting /$chunk/ as end-of-line, followed by
literal "chunk". This is certainly not what I want. And Perl is behaving the
way that I expect (i.e. evaluating $chunk first and trying to match its value
literally) in other places in my code.

Any ideas here? I certainly have read through the perlre documentation, and
saw no clues therein.


TIA,
Josh


-- 
Josh Glover <jmglov@example.com>

Associate Systems Administrator
INCOGEN, Inc.
http://www.incogen.com/

GPG keyID 0x62386967 (7479 1A7A 46E6 041D 67AE  2546 A867 DBB1 6238 6967)
gpg --keyserver pgp.mit.edu --recv-keys 62386967

Attachment: pgp00002.pgp
Description: PGP signature


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links