Using value fields to print output. : Field « Report « Perl






Using value fields to print output.

   
#!/usr/local/bin/perl 

while ($line = <STDIN>) { 
   $line =~ s/[^aeiou]//g; 
   @vowels = split(//, $line); 
   foreach $vowel (@vowels) { 
      $vowelcount{$vowel} += 1; 
   } 
} 
$~ = "VOWELFORMAT"; 
write; 

format VOWELFORMAT = 
----------------------------------------------------------- 
Number of vowels found in text file: 
a: @<<<<< e: @<<<<< 
$vowelcount{"a"}, $vowelcount{"e"} 
i: @<<<<< o: @<<<<< 
$vowelcount{"i"}, $vowelcount{"o"} 
u: @<<<<< 
$vowelcount{"u"} 
-----------------------------------------------------------

. 

   
    
    
  








Related examples in the same category

1.Format Field Types
2.Multiline fields
3.Split a long field over multiple lines
4.Field Designator Symbols
5.Field Display Symbols
6.Different types of fields
7.Writes a string using the multiline field format.
8.Valid value-field formats.
9.Limitations of the @* value field.
10.A program that uses a value field that does formatting.