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 haukex (Archbishop) 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.

Re: Checking whether a value is between two limits: Useless use of private variable in void context
by Perlbotics (Archbishop) 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