in reply to Parse $ Variable in text file

so basically, you'll do something like this (if you haven't read the perldoc the AnoMonk gave us):

perl -e '$name='kak';$q=do {open(F,"/tmp/file");<F>}; $q=~ s/\$(\w+)/$ +{$1}/g;; print $q' gives: select * from kak cat /tmp/file select * from $name

In my example, the /tmp/file only contains one line, that's why I assigned it to a scalar and not an array.
Hope this helps...

--
to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re^2: Parse $ Variable in text file
by Juerd (Abbot) on Jan 11, 2005 at 14:30 UTC

      More specifically it doesn't work with lexical (my) variables - you will need to use package variables instead.

      /J\

      ok thanks!... then someone needs to update perldoc -q "expand variable" because i just quickly copied and pasted it ;-)

      i didn't even test the code.. since it looked so obvious. but, once more!, ppl slap me around the ears saying: "use strict" and try out your code !
      one day i'll learn... one day ;-)

      --
      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame