Is it while ($x > 3 || $y < 2)
like in other programming languages? I literally can't find anywhere online that tells me how to do this in Perl.
Asked
Active
Viewed 136 times
-6

zoul
- 102,279
- 44
- 260
- 354

SangoProductions
- 129
- 8
-
https://users.cs.cf.ac.uk/Dave.Marshall/PERL/node35.html http://www.perlmonks.org/?node_id=990 – AbhiNickz Nov 09 '16 at 11:32
-
6@AbhiNickz that tutorial is incredibly out of date. While the general information is correct, it contains a lot of information that rings my alarm bells. It declares variables without `my`, it tells you it's ok to use strings with the number comparison operators and it uses _PERL_ as the name of the language, which is outright wrong. Please don't use this resource. It's overstayed its usefulness. Thank you. – simbabque Nov 09 '16 at 11:40
-
Yeah, I checked again, I just wanted to show OP that there are lots of online resource that I found in just one google search. – AbhiNickz Nov 09 '16 at 12:34
-
@SangoProductions: Why don't you try it? – Borodin Nov 09 '16 at 15:12
2 Answers
3
Try perldoc perlop
. There’s both C-style ||
+ &&
available and or
+ and
with different operator priority.

zoul
- 102,279
- 44
- 260
- 354
3
Is it while ($x > 3 || $y < 2) like in other programming languages?
Yes it's the same.
Let's put it into an example.
#!/usr/bin/perl
use strict;
use warnings;
my $x = 10;
my $y = 0;
while ($x > 3 || $y < 2){
print "X is $x, Y is $y\n";
$x--;
$y++;
}
Output:
X is 10, Y is 0
X is 9, Y is 1
X is 8, Y is 2
X is 7, Y is 3
X is 6, Y is 4
X is 5, Y is 5
X is 4, Y is 6
Pretty easy, right?

Chankey Pathak
- 21,187
- 12
- 85
- 133