Hello,

Can someone please help that how value of p is coming out as 1 through 17.

My understanding is p should be equal to $. (line number) and it should be printed from 3 to 19 rather 1 to 17.

Thanks in advance!

#!/usr/bin/perl ##use warnings; while(<>){ if($p=3..1) { print "p is $p\n"; } }

When i run the same code on a file that has fifteen lines, it returns following

p is 1

p is 2

p is 3

p is 4

p is 5

p is 6

p is 7

p is 8

p is 9

p is 10

p is 11

p is 12

p is 13

p is 14

p is 15

p is 16

p is 17

Also what is difference when i have $p=3..1 vs ($p=3)..1 in if statement above


In reply to flip flop operator and if statement by iThunder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.