Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: flip-flop interpolation

by choroba (Archbishop)
on May 13, 2015 at 10:02 UTC ( #1126535=note: print w/replies, xml ) Need Help??

in reply to flip-flop interpolation

Range Operators says:
If either operand of scalar .. is a constant expression, that operand is considered true if it is equal (==) to the current input line number (the $. variable).
So, if you're not using constants, you have to do the comparison yourself:
print if ($. == $i) .. ($. == $j); # The parentheses are optional.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: flip-flop interpolation
by Anonymous Monk on May 13, 2015 at 10:31 UTC
    Thank you.
    And can't I say to Perl to use my $i and $j as constants?

      That is like asking to draw a red line using green ink :)

      The way to do it is to use the green ink to define a universe containing hardcoded red lines:

      #untested, and quite silly eval "print $_ if $i .. $j;";

      You could use the constant pragma but it is not really saving you anything.

      $ seq 1 6 > lines $ cat lines 1 2 3 4 5 6 $ perl -ne ' > use constant { I => 3, J => 5 }; > print if I .. J;' lines 3 4 5 $

      I hope this is of interest.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2022-01-27 05:52 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.