Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Perl logical operators

by tobyink (Canon)
on Jul 18, 2018 at 07:23 UTC ( [id://1218723]=note: print w/replies, xml ) Need Help??


in reply to Perl logical operators

In addition to what choroba said, if you really want to be able to use the keywords true and false in your script, there are a few CPAN modules which will provide them for you, such as boolean. Or you can just define them as constants.

use constant {qw( true 1 false 0 )};

Replies are listed 'Best First'.
Re^2: Perl logical operators
by tweetiepooh (Hermit) on Jul 10, 2019 at 13:38 UTC

    When did this form become valid? I used on my dev box (5.28) but on production (5.16) I get a syntax error and need to use

    use constant {true=>1,false=>0}
      Interestingly, it's a difference in Perl parser, not in constant. As usually, help the parser by telling it the { doesn't start a block, but a hash reference:
      use constant +{ qw( true 1 false 0 ) };

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      perldelta for 5.18.0 says:

      use no longer tries to parse its arguments as a statement, making use constant { () }; a syntax error (perl #114222).

      which I believe refers to this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found