in reply to Re: Can you explain the difference with print?
in thread Can you explain the difference with print?

I thought we'd broken your habit of omitting the strict and warnings pragmata. Perhaps not. :-(

You have Ken - except for a oneliner where the only purpose was to check I had remembered correctly that [6] was the weekday!

I hardly ever use oneliners and forgot at add 'w' to -we...is there an equivalently for strict?

You've run afoul of the rule that says...

Thanks for the explanation of this and the Unitary Operator. When I've seen that in the past I've assumed it was shorthand for add nothing, whatever 'nothing' means in the context of that scalar.

Replies are listed 'Best First'.
Re^3: Can you explain the difference with print?
by eyepopslikeamosquito (Archbishop) on Aug 05, 2023 at 23:47 UTC

    I hardly ever use oneliners and forgot at add 'w' to -we...is there an equivalently for strict?

    To nitpick, -w only enables many useful warnings ... while -W enables all warnings ... though I still prefer Mr Oath's self-explanatory:

    perl -Mstrict -Mwarnings

Re^3: Can you explain the difference with print?
by kcott (Archbishop) on Aug 06, 2023 at 04:47 UTC

    Unless I'm using it repeatedly in some code, I never expect to remember the order of the 9-element list returned by localtime. The doco clearly provides that information; it also tells me that $wday is a zero-based index with 0 representing Sunday (which is something else I don't expect to have committed to memory).

    There are lots of other functions, which I use infrequently, and return long lists; e.g. getgrent (4); getpwent (10); stat (13). I find looking these up is a lot quicker, and far less error-prone, than code trial-and-error: 6 was correct for [6] as it was Saturday; 6 could have easily been returned for a number of other indices depending on the date and time.

    Having perle to hand, means I never have to remember to type the -M options nor expend the time and energy to actually type them. Furthermore, warnings is a lexically-scoped pragma; I can turn it off wholly or partly anywhere in my code (neither -w nor -W provides that freedom).

    Any piece of example code that I've posted here as

    perl -E '... single line ...'

    or

    perl -E ' ... code ... ... on ... ... multiple ... ... lines ... '

    would have been tested with perle instead of perl -E beforehand. That way, I can be more confident about the validity of the code, without needing to provide an explanation of perle.

    I also use perle for personal work which never gets published. I find it incredibly useful and have no hesitation in recommending you do something similar (i.e. an MSWin equivalent).

    By the way, it's unary not unitary (which means something different). In terms of operators:

    • + operand1 (unary)
    • operand1 + operand2 (binary)
    • condition ? true_value : false_value (ternary)

    perlop has multiple examples of these terms.

    — Ken