in reply to Double quoted string as method call

Avoiding comment on your DBI code, since I don't understand it, I think you want, $obj->${"text_${_}"};

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Double quoted string as method call
by Anonymous Monk on May 05, 2004 at 01:11 UTC

    Close Zaxo, I think you were looking for $obj->${\"text_$_"}() (note the reference taken).

      Thank you!

      I have compiled and run and tested, and it does seem this works!

      It doth confuse cperl-mode in emacs, tho!

      Cperl-mode understands $caller->$ {\ "database_$_"}() (note spacing) just fine, however.

      Whether humans will be able to parse such funny spacing remains to be seen ;->

Re: Re: Double quoted string as method call
by ryantate (Friar) on May 04, 2004 at 22:16 UTC

    UPDATE: Actually this compiles fine but doesn't actually work, see first response below for reason why. Thanks anyway.

    ---------- Old message ----------

    Thank you!

    I should note, however, that in my case this failed with a syntax error until I added a () to the end of the, as such:

    $obj->${"text_${_}"}();

    This may have to do with the particulars of my code.

    (As for the DBI call, that stuff can safely be ignored. I would note it was actually flawed insofar as I tried to pass in taint information incorrectly, the correct parameter order is dsn, user, pass, then a hashref with other optional config info, which I usually compose as {Taint=>1}.)

      $obj->${"text_${_}"}();
      I don't think that does what you want it to: it does one too many levels of indirection. if $_ has the value "foo", then I presume you want to do the equivalent of
      $obj->text_foo()
      In fact, supposing you have a variable called $text_foo with value bar, then what you are actually doing is the equivalent of
      $obj->bar()

        You're right -- this doesn't do what I thought. In fact, while it will compile, it doesn't actually work. :--(