Linked Questions

13 votes
3 answers
27k views

Possible Duplicate: How do I use boolean variables in Perl? [root@ ~]$ perl -e 'if(true){print 1}' 1 [root@ ~]$ perl -e 'if(false){print 1}' 1 I'm astonished both true and false passes the if...
asker's user avatar
  • 2,209
1 vote
2 answers
180 views

Below perl one-liner outputs hello to console, so how is false interpreted here since it is not a variable or literal string? perl -e"if (false) {print 'hello'}"
Thomson's user avatar
  • 21.9k
-5 votes
2 answers
163 views

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.
SangoProductions's user avatar
1 vote
1 answer
109 views

Am doing this on mac, perl version is This is perl 5, version 16, subversion 3 (v5.16.3) built for darwin-thread-multi-2level $ perl -e "$t=false;while(!($t)){print 1}" $ perl -e "$t=true;while(!($t)...
Qiang Li's user avatar
  • 10.9k
1 vote
3 answers
111 views

I am learning scripting in perl. I have encountered an example which I don't understand: my $num = 50; if ($num) { print "True: $num\n"; } else { print "False: $num\n"; } This is very simple ...
Homap's user avatar
  • 2,224
0 votes
0 answers
58 views

#! /usr/bin/perl $var1 = 20; $var2 = 15; print ("var1 = ", $var1, "\n"); print ("var2 = ", $var2, "\n"); # Comparing numbers print ("var1 == var2 : ", ($var1 == $var2), "\n"); print ("var1 != var2 :...
Hari Krishna's user avatar
  • 3,588
12 votes
7 answers
975 views

This is a piece of common example code: while (1) { print "foo\n"; } which prints 'foo' forever. perl foo.pl foo foo foo ... and while (0) { print "foo\n"; } dies quietly as you expect: ...
shigeta's user avatar
  • 1,779
18 votes
5 answers
4k views

When evaluating an expression in a scalar (boolean) context, Perl uses the explicit value 1 as a result if the expression evaluates to true and the empty string if the expression evaluates to false. I'...
Piotr Dobrogost's user avatar
6 votes
9 answers
23k views

What does the syntax if (1) {} do? I can't find documentation for this syntax and 1 is not being treated as a boolean. Am I right?.
user2521358's user avatar
13 votes
3 answers
9k views

I'm looking for ways to express this Python snippet in Perl: data = {"A": None, "B": "yes", "C": None} key_list = [k for k in data if data[k]] # in this case the same as filter(lambda k: data[k], ...
conny's user avatar
  • 10.2k
4 votes
4 answers
387 views

I come from C++ background and am trying to learn perl with Beginning Perl. However, this code in the second chapter has left me confused: #!/usr/bin/perl use warnings; print"Is two equal to four? ", ...
Worse_Username's user avatar
1 vote
3 answers
3k views

I recently had to maintain a legacy project, the code was a mess with no coding pattern however one thing caught my attention, in some cases Boolean types were created in three different ways: const ...
1fabiopereira's user avatar
2 votes
2 answers
151 views

if ( $2 && $3 && $3 != 0 ) what is the above logic in Perl? I've never seen an if condition like this in other languages. $2 and $3 are just capturing groups of some regex. or this: ...
user2521358's user avatar
0 votes
1 answer
2k views

I am using the below code. On the right of and is a grep without a numerical comparison. Does that make sense? if ( scalar( grep { $_ eq $ServerTypeId } keys %ServerTypes ) > 0 and grep { ...
Syam Kumar's user avatar
5 votes
1 answer
573 views

Please help me understand the following snippets: my $count = @array; my @copy = @array; my ($first) = @array; (my $copy = $str) =~ s/\\/\\\\/g; my ($x) = f() or die; my $count = () = f(); print($x = $...
ikegami's user avatar
  • 391k

15 30 50 per page