Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: a perl code syntax help

by ghosh123 (Monk)
on Jul 28, 2014 at 11:17 UTC ( #1095332=note: print w/replies, xml ) Need Help??

in reply to Re: a perl code syntax help
in thread a perl code syntax help

thanks for your reply and pointer to the doc.
I just do not want to write the same code again and again, can I write a function and pass 'onload' or 'onChange' in a variable? so that it would resolve the $func value as -onChange or -onload ?

Replies are listed 'Best First'.
Re^3: a perl code syntax help
by marto (Cardinal) on Jul 28, 2014 at 11:25 UTC

    You could make life much easier for yourself by using a templating system rather than creating HTML in this manner, but you already know that.

Re^3: a perl code syntax help
by hexcoder (Deacon) on Jul 28, 2014 at 21:08 UTC
    Yes, we can. Like that (untested):
    ... my $trigger = 'onload'; $html .= <<END; ... <td bgcolor="#EEEEEE">@{[ $qry->popup_menu(-id=>'ID +', -name=>'PS', -size=>10, -values=>$array_ref, -labels=>$hash_ref, +-${trigger}=>"fetchData(id,'','','')") ]}</td> </tr> </table> END
    The original code did already interpolate a list expression in the heredoc string (@{[ ... ]} was already present). So you just have to replace the fixed text part (onChange) in the above expression (...) with a string variable (here I used $trigger).

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095332]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-05-20 07:41 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (73 votes). Check out past polls.