in reply to What is the * postfix operator, pre-'feature postderef'?

wsanders:

No, it's a shortcut. It turns out that:

$uptime *= 2;

is a shortcut for:

$uptime = $uptime * 2;

There's also +=, etc. See perldoc perlop for all the details.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: What is the * postfix operator, pre-'feature postderef'?
by wsanders (Novice) on Sep 10, 2014 at 20:56 UTC
    Gaaak I feel STUPID! Of course you are correct. The lack of spaces threw off my disused spatial recognition skills. And I just got new glasses, sheesh .... But it also threw me off that multiplying a string containing spaces by 1 results in the first "field" of the string, the same as 's/\s.*//'. One really ought to use:
    $uptime=`cat /proc/uptime`; print ref(\$uptime)," $uptime\n"; $uptime =~ s/\s.*//; print ref(\$uptime)," $uptime\n";

      If you want the first numeric field I'd use:

      ($uptime) = $uptime =~ /(\d+)/;

      which makes the intent much clearer. What's with the ref(\$uptime)?

      Perl is the programming world's equivalent of English