CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Weird issue with booleans in Perl

 



adityadennis
New User

Jul 15, 2009, 6:15 PM

Post #1 of 3 (553 views)
Weird issue with booleans in Perl Can't Post

This is strange. The following:

$sum = !0;
print $sum;

prints out 1 as you would expect. But this

$sum = !1;
print $sum;

prints out nothing. Why?


shawnhcorey
Enthusiast


Jul 16, 2009, 6:04 AM

Post #2 of 3 (545 views)
Re: [adityadennis] Weird issue with booleans in Perl [In reply to] Can't Post


In Reply To
This is strange. The following:

$sum = !0;
print $sum;

prints out 1 as you would expect. But this

$sum = !1;
print $sum;

prints out nothing. Why?


It is set to the zero-length string.

Code
#!/usr/bin/perl 

use strict;
use warnings;

# See `perldoc English`
use English qw( -no_match_vars ) ; # Avoids regex performance penalty

use Data::Dumper;
# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
$Data::Dumper::Maxdepth = 0;

my $var = !0;
print Dumper \$var;

$var = !1;
print Dumper \$var;


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


adityadennis
New User

Jul 16, 2009, 8:30 AM

Post #3 of 3 (540 views)
Re: [shawnhcorey] Weird issue with booleans in Perl [In reply to] Can't Post

Got it. Thanks!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives