You know that feeling, when the big program you've been working on approaches completion, and you're scanning for those invisible bugs the others will find when running your code. That's when I saw something like this somewhere between lines 6000 and 7000:
my $one = 1; my $six = my $nine = 9; print $six; # prints 9
I didn't know you could chain lexical declarations like that! The bug survived for months because $nine was 0 and $six was supposed to be an empty string. Playing around with it reveals more questionable behavior:
#!/usr/bin/perl -l use strict; use warnings; use diagnostics; print my $J = my $A = my $P = my $H = 'Just',' Another ','Perl',' Hacker';
Does that look strict? :-)

Replies are listed 'Best First'.
Re: If 6 Was 9
by haukex (Archbishop) on Oct 15, 2018 at 19:29 UTC
    BEGIN { require overload; overload::constant( integer => sub { (my $r=shift)=~tr/0-9/3412789056/;$r } ) } print "<",6,",",9,">\n";
      nice! ;)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: If 6 Was 9
by LanX (Saint) on Oct 15, 2018 at 18:16 UTC
    > Does that look strict? :-)

    It does: = is an assignment operator, and has higher precedence than comma , .

    I haven't run your code, but I suppose it's just printing the JAPH phrase after assigning "Just" to 4 variables.

    Since I'm using auto-indentation - which is emphasizing multi-line commands, I would have noticed your bug immediately.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    update

    s/Yet/Just/

      > = is an assignment operator, and has higher precedence than comma , .

      probably a better demonstration:

      >perl use strict; use warnings; my $J='Just', my $A='Another', my $P='Perl', my $H='Hacker'; print "$J $A $P $H"; __END__ Just Another Perl Hacker

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: If 6 Was 9
by tybalt89 (Monsignor) on Oct 15, 2018 at 18:13 UTC

    yes

      I got a good laugh when I clicked on your reply directly, not having the context of the OP on the screen :)

Re: If 6 Was 9
by holli (Abbot) on Oct 17, 2018 at 00:53 UTC
    I already brought the popcorn for yet another Perl 6 renaming thread (why not, I thought. Nine would be a good name) and then ... this.


    holli

    You can lead your users to water, but alas, you cannot drown them.
Re: If 6 Was 9
by ikegami (Patriarch) on Dec 06, 2018 at 03:48 UTC

    Scalar assignment in scalar context returns its LHS (as an lvalue), as documented here.

    It's very very common to take advantage of this.

    while (defined( $_ = <> )) { ... }
    my $sock = IO::Socket::INET->new(...) or die(...);
    ( my $copy = $str ) =~ s/\\/\\\\/g;

    etc.

Re: If 6 Was 9
by jdporter (Paladin) on Dec 05, 2018 at 17:26 UTC