Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: strong typing

by herveus (Prior)
on Dec 14, 2004 at 18:37 UTC ( [id://414807]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;  #try to catch as many type errors as possible
  2. or download this
    print $a+@b;     #coerce array into number
    
  3. or download this
    print $a+$ref_b; #coerce reference into number
    
  4. or download this
    my $d=eval %c;   #coerce hash into string
    print "d=$d";    #amusing result
    
  5. or download this
    my @e=%c;print "@e";  #hashes and arrays are different types.  Oh wait
    +...
    print "c=$_" for %c;
    
  6. or download this
    my @t=12;        #coerce number into array
    print @t;
    print 0+@t;
    
  7. or download this
    print "\\4 = ".(\4->{"what???"});  #???
    
  8. or download this
    print '\\4 = ' . \$4{'what???'};
    
  9. or download this
    sub test{ return ("a",123) }; #sub returns a list
    my $scalar_list=test(); #coerce into scalar
    my  @array_list=test(); #coerce into array
    my   %hash_list=test(); #coerce into hash
    print "\$scalar_list=$scalar_list\n\@array_list=@array_list";
    
  10. or download this
    no warnings;
    my %i=$ref_a;
    print %i;      #apparently hashes can be scalar refs...
    
  11. or download this
    my (%i) = $ref_a;
    
  12. or download this
    no strict;
    $$ref_a->[88]=7;
    print $$ref_a->[88]
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://414807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-18 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found