in reply to Re: Printing the result of calling an instance method
in thread Printing the result of calling an instance method

I know why it works, but I have always wondered why people do that trick. Personally I find it works just fine to use string concatenation, and that is a lot less syntax as well. Besides which, the trick puts the function call in array context which is usually what I didn't mean.

Now you know better. But most people shown the above are going to get an interesting surprise when comparing:

print "The current date is @{[localtime()]}.\n"; print "The current date is ".localtime().".\n";
So, even though using that shows you are an uber-cool Perl hacker, I don't...

Replies are listed 'Best First'.
Re: Re (tilly) 2: Printing the result of calling an instance method
by davorg (Chancellor) on Apr 02, 2001 at 13:33 UTC

    Oh, you're absolutely right. As I said above, it's very nasty - for all kinds of reasons.

    As for the list/scalar context problem, you could do something like:

    print "The current date is @{[scalar localtime]}.\n";

    But I really wouldn't recommend it :)

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me