Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: a perl code syntax help

by ghosh123 (Monk)
on Jul 28, 2014 at 11:17 UTC ( [id://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 (Curate) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found