iThunder has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: flip flop operator and if statement
by GrandFather (Saint) on Sep 20, 2014 at 03:04 UTC | |
|
Re: flip flop operator and if statement
by Athanasius (Archbishop) on Sep 20, 2014 at 03:30 UTC | |
by iThunder (Beadle) on Sep 20, 2014 at 06:23 UTC | |
by Athanasius (Archbishop) on Sep 20, 2014 at 06:54 UTC | |
by iThunder (Beadle) on Sep 20, 2014 at 07:32 UTC | |
by Athanasius (Archbishop) on Sep 20, 2014 at 08:07 UTC | |
| |
by LanX (Saint) on Sep 20, 2014 at 08:01 UTC | |
| |
by Anonymous Monk on Sep 20, 2014 at 06:26 UTC | |
|
Re: flip flop operator and if statement
by Anonymous Monk on Sep 20, 2014 at 12:44 UTC |