in reply to Can you explain the difference with print?

Your call to localtime is a function call, and you can't do that from within a string. Perl does variable interpolation, which expands a variable's value, but it does not do function calls within a string.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Replies are listed 'Best First'.
Re^2: Can you explain the difference with print?
by NERDVANA (Priest) on Aug 04, 2023 at 21:03 UTC
    I think you mis-read. He's not doing it inside a string, that string is for the shell. The problem here is just the classic "print is not a keyword, and if parens follow it, those become the arguments"
Re^2: Can you explain the difference with print?
by Bod (Parson) on Aug 04, 2023 at 20:53 UTC

    I still don't understand...

    If localtime is a function call that I can't evaluate in print, how come I can do this?

    C:\Users\user>perl -we "use Time::Piece;print localtime->day_of_week" 5

      Because you're not doing any variable interpolation there -- there are no double quotes, you're just printing the output of a function call.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

        That's Bod's point. The same applies to the OP. No quotes, so no interpolation.