Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Checking whether a value is between two limits: Useless use of private variable in void context

by Bloehdian (Beadle)
on Dec 11, 2019 at 18:47 UTC ( #11109988=perlquestion: print w/replies, xml ) Need Help??

Bloehdian has asked for the wisdom of the Perl Monks concerning the following question:

I simply want to check, whether a numeric value is between an upper and a lower limit using the following one liner:

perl -we 'use strict; my $value=1; my $lower_limit = 0; my $upper_limi +t = 2; if ( ( $value <= $upper_limit ) && ( $value => $lower_limit ) +) { print "the value is in the range!\n"}' Useless use of private variable in void context at -e line 1.

Currently it seems that I am kind of blind, since I cannot see what is wrong with the condition. I guess here is somebody out who has better eyes. ;-)

  • Comment on Checking whether a value is between two limits: Useless use of private variable in void context
  • Download Code

Replies are listed 'Best First'.
Re: Checking whether a value is between two limits: Useless use of private variable in void context
by Fletch (Bishop) on Dec 11, 2019 at 18:51 UTC

    You've got => which is a fancy comma not the greater than or equals operator >= (see perlop). This means the second half of your if check is ... ( $value, $lower_limit ) which is why you're getting that warning.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Checking whether a value is between two limits: Useless use of private variable in void context
by Perlbotics (Bishop) on Dec 11, 2019 at 18:54 UTC

    ( $value => $lower_limit )
    is somewhat like
    ( $value , $lower_limit )
    which is essentially
    ( $lower_limit )
    making $value irrelevant. You don't need the fat comma => but the greater or equal operator >= .

      Oh my dear! Nasty typo.

      Hm, at least I learned new terms: "fat comma" and "fancy comma"

      THX to all

Re: Checking whether a value is between two limits: Useless use of private variable in void context
by haukex (Bishop) on Dec 11, 2019 at 18:56 UTC

    Note B::Deparse can be a useful tool:

    $ perl -MO=Deparse -we 'use strict; my $value=1; my $lower_limit = 0; my $upper_limit = 2; if ( ( $value <= $upper_limit ) && ( $value => $lower_limit ) ) { print "the value is in the range!\n"}' Useless use of private variable in void context at -e line 4. BEGIN { $^W = 1; } use strict; my $value = 1; my $lower_limit = 0; my $upper_limit = 2; if ($value <= $upper_limit and $value, $lower_limit) { print "the value is in the range!\n"; } -e syntax OK

    Say perl -MO=Deparse,-p ... to add parentheses and see the precedence better.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11109988]
Approved by haukex
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-06-29 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (96 votes). Check out past polls.

    Notices?