Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

What is truth? (Curiosity corner)

by robin (Chaplain)
on Dec 20, 2001 at 22:28 UTC ( #133554=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        sub explain {
            my $val = shift;
            print "Numeric value = ", 0+$val, "\n";
            print "String value = \"$val\"\n";
            print "Truth value = ", $val ? "true\n" : "false\n";
        }
    
  2. or download this
        # explain("23skidoo");
        Numeric value = 23
        String value = "23skidoo"
    ...
        Numeric value = 0
        String value = ""
        Truth value = false
    
  3. or download this
    [robin@robin robin]$ perl -wle 'print 0+"23skidoo"'
    Argument "23skidoo" isn't numeric in addition (+) at -e line 1.
    23
    
  4. or download this
    [robin@robin bits & pieces]$ perl -wle 'print 23+"0 but true"'
    23
    
  5. or download this
        # explain([1,2,3]);
        Numeric value = 25616
        String value = "ARRAY(0x6410)"
        Truth value = true
    
  6. or download this
        my $foo = *bar;
        our $bar = "hello\n";
        our @bar = ("Hello again!\n");
        print $$foo, @$foo;
        explain($foo);
    
  7. or download this
        hello
        Hello again!
        Numeric value = 0
        String value = "*main::bar"
        Truth value = true
    
  8. or download this
        # explain(bless {}, "SomePackage");
        Numeric value = 25616
        String value = "SomePackage=HASH(0x6410)"
        Truth value = true
    
  9. or download this
        explain(bless {}, "SomePackage");
        package SomePackage;
        use overload '""'   => sub {'string value'};
        use overload '0+'   => sub {23};
        use overload 'bool' => sub {""};
        use overload fallback => 1;
    
  10. or download this
        Numeric value = 23
        String value = "string value"
        Truth value = false
    
  11. or download this
        Numeric value = 0
        String value = "string value"
        Truth value = true
    
  12. or download this
        explain(bless {}, "SomePackage");
        package SomePackage;
        use overload '""'   => sub {''};
        use overload '0+'   => sub {23};
        use overload fallback => 1;
    
  13. or download this
        Numeric value = 23
        String value = ""
        Truth value = true
    
  14. or download this
        explain(bless {}, "SomePackage");
        package SomePackage;
        use overload '""'   => sub { '' };
        use overload '0+'   => sub {'00'};
        use overload fallback => 1;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://133554]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2015-07-04 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls