http://qs321.pair.com?node_id=11133448


in reply to Re^2: Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?
in thread Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?

Check your precedence. The code you showed does not do what you think.

$ perl -Mstrict -wE 'say -e "fooble" ? 1 : 0; open my $fh, "<", "foobl +e" || die $!' 0
$ perl -Mstrict -wE 'say -e "fooble" ? 1 : 0; open my $fh, "<", "foobl +e" or die $!' 0 No such file or directory at -e line 1.


The way forward always starts with a minimal test.
  • Comment on Re^3: Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please?
by perlfan (Vicar) on Jun 04, 2021 at 00:43 UTC
    Thank you, fixed.
      I always use or in such situations, and I dislike perldocs which do otherwise, because these are invitations for refactoring problems.

      Personally I use || only in

      • in arithmetic expressions $x = $y || $z
      • to override false defaults were $x ||= $y

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      update

      swapped $a, $b with $y,$z to appease hippo ;-)

        I always use or in such situations, and I dislike perldocs which do otherwise

        So do I. I also dislike the use of $a and $b in docs as metasyntactic variables as they are subsequently used in cargo-culted code and become the cause of errors. There are, after all, plenty of others to choose from.


        🦛