Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] counting the words using perl programing

Expand Messages
  • Jonathan Dunn
    here s what I get: ##### script: #!/usr/local/bin/perl use CGI qw( :standard ) ; use CGI::Carp qw( fatalsToBrowser ) ; use strict ; my ( $category, %info ) ;
    Message 1 of 2 , Jun 2, 2003
    • 0 Attachment
      here's what I get:

      ##### script:

      #!/usr/local/bin/perl

      use CGI qw( :standard ) ;
      use CGI::Carp qw( fatalsToBrowser ) ;
      use strict ;

      my ( $category, %info ) ;

      print header ;
      print start_html ;
      print "<pre>\n" ;

      open( FILE, "<file.txt" ) ;

      while (<FILE>) {
      chomp;
      if ( is_header( $_ ) ) {
      $category = $_ ;
      } else {
      my ( @words ) = split( /\s+/, $_ ) ;
      for( @words ) {
      $_ = lc( $_ ) ; # ? your example has Lotus and lotus added
      together
      $info{ $category }{ $_ }++
      }
      }
      }

      for my $category ( sort keys %info ) {
      print "Header: $category\n" ;
      for my $word ( sort keys %{ $info{ $category } } ) {
      print "$word $info{ $category }{ $word }\n" ;
      }
      }

      print "END\n" ;

      print end_html ;

      sub is_header {
      # ?? just a letter & numbers? or hardcode these? or ... ?
      return m#^\w \d+$# ;
      }

      ##### output:

      Header: A 35
      bud 1
      flower 4
      lavender 3
      leaf 1
      rose 3
      Header: B 36
      bud 1
      flower 2
      leaf 1
      lotus 4
      END
    Your message has been successfully submitted and would be delivered to recipients shortly.