#!/usr/bin/perl use strict; use warnings; my $string = "00021"; $string=~ s/^0*//; # remove leading zero'es print "$string\n"; # prints: 21 $string = "00021"; $string += 0; # converts string to a numeric value print "$string\n"; # prints: 21 $string = "00021scores"; #$string += 0; # Warning: Argument "00021scores" isn't numeric in addition (+) print "$string\n"; # prints: 21 $string = "0 but true"; $string += 33; # Ha! A Perl special case! no warning! print "$string\n"; # prints: 33 $string = "0E0"; # "better" way for a "logically true but zero value" $string += 33; # print "$string\n"; # prints: 33 my $nothing; #print "$nothing\n"; # Use of uninitialized value $nothing in concatenation (.) or string $nothing //= ''; # set $nothing to '' if it was undefined, else no operation. print "$nothing\n"; # orint is ok, now.. my $nothing2; $nothing2 = '' if !defined $nothing2; # pre Perl 5.10 print "$nothing2\n";