On Aug 31, Yusuf Goolamabbas said:
>#!/usr/bin/perl
>
>sub main() {
Um, the () here is probably not intended. And Perl programs don't need a
main().
>$key = 5 ;
>print <<"TARGET" ;
>Foobar
>Snafu
>${\(interp($key))}
>TARGET
>}
>
>sub interp {
> my ($arg) = @_ ;
> print "Hello World, $arg \n" ;
> return;
>}
>
>main();
>
>gives the following output
>--
>Hello World 5
>Foobar
>Snafu
Right. Your function interp() PRINTS something, and then returns. That
happens before the completion of the print << "TARGET".
If you wrote your code as:
print << "END";
a
b
@{[ foo() ]}
END
sub foo {
return "c";
}
Then you would get
a
b
c
as your output. Because you're printing in the interp() function itself,
you're getting what appears to be out-of-order data.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
Thread Previous