Yoda_Oz has asked for the wisdom of the Perl Monks concerning the following question:
hi, the code above searches through a text file and spits out how many of each puntuation character it finds (according to each ASCII octet i have put in the regular expression bit). im after a different way of doing this second loop. so that instead of actually printing out the character it finds it prints out the word equivalent, ie "." equals fullstop, and "," equals comma. i guess id have to use some sort of hash to create a database of ,=comma and .=fullstop and (=open brackets etc. but im not quite sure how to do this... and then relate it to what it finds in the punctuation search. ie - what it does now:#!usr/local/bin/perl print ("Enter filename to search to punctuation characters: "); $path=<STDIN>; print ("\n"); open(DATA, "<$path") || die "Couldn't open $path for reading: $!\n"; while (<DATA>) { while (s/([\041-\057]|[\72-\100]|[\133-\140]|[\173-\176])(.*)/$2/) { $char = $1; $wordHash{$char}++; } } while ( ($punctuation, $count) = each(%wordHash) ) { $wordArray[$i] = "$punctuation\t$count"; $i++; print ("$punctuation\t$count\n"); }
what i want it to look like:? 1 . 6 , 5 ( 10 ) 10 ; 21 $ 19
cheers, PS sorry about the ambiguity of my last post!question mark 1 fullstop 6 comma 5 open bracket 10 close bracket 10 colon 21 dollar sign 19
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: punctuation search (different!)
by davido (Cardinal) on Jan 30, 2006 at 03:21 UTC | |
|
Re: punctuation search (different!)
by bobf (Monsignor) on Jan 30, 2006 at 03:25 UTC | |
|
Re: punctuation search (different!)
by thundergnat (Deacon) on Jan 30, 2006 at 18:43 UTC |