Using tr to retrieve the length of a string. : tr « Regular Expression « Perl






Using tr to retrieve the length of a string.

     
#!/usr/local/bin/perl 

$string = "here is a string"; 
$_ = $string; 
$length = tr/a-zA-Z /a-zA-Z /; 
print ("the string is $length characters long\n"); 

   
    
    
    
    
  








Related examples in the same category

1.Counting using tr.
2.$text =~ tr/a-z/d-za-c/;
3.$text =~ tr/d-za-c/a-z/;
4.Using tr to count the occurrences of specific characters.
5.tr/a-z/A-Z/
6.tr/i/o/;
7.tr/o/i/;