in reply to How do you run a subroutine from inside HTML code?

Thanks for all who helped, but I got it running. I had to edit the code to this:
foreach $index (keys %{$_[0]}){ print "<TD WIDTH=\"$table_vars{$index}\">\n"; &$index(); print "</TD>\n"; }
and I had to remove the & from $index so instead of $index = &login it is now $index = login

Replies are listed 'Best First'.
Re^2: How do you run a subroutine from inside HTML code?
by Anonymous Monk on Mar 15, 2006 at 20:54 UTC

    I'd first think to try the following, but that may be perl6 interpolation talking:

    my $index = \&login; for (keys %{$_[0]}) { print qq[<TD WIDTH="$table_vars{$_}">\n$index->()\n</TD>\n]; }

    Generally, and definitely perl5, "@{[foo()]}" calls &foo as list context and interpolates the return value as with an array and "${\foo()]}" similarly, with scalar context and as a scalar.

    For your particular example, however, I'd just use printf.

    for (keys %{$_[0]}) { printf qq[<TD WIDTH="$table_vars{$_}"\n%s</TD>\n], $index->(); }

    There is no need to escape quoting delimeters in Perl.

Re^2: How do you run a subroutine from inside HTML code?
by Anonymous Monk on Mar 15, 2006 at 20:56 UTC

    and I had to remove the & from $index so instead of $index = &login it is now $index = login

    Please always use strict; in your code.