Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: compute the occurrence of words

by Tux (Abbot)
on Feb 13, 2013 at 14:27 UTC ( #1018546=note: print w/replies, xml ) Need Help??


in reply to Re^2: compute the occurrence of words
in thread compute the occurrence of words

In which case you will also have to define "numbers" :) integers?, floats? e-notation? Roman? Only ASCII-digits, or also other Unicode numerals?

Let me assume simple integers and floats represented in ASCII (no triad-sep, radix-sep = '.', so valid numbers include 1234 and 0.23, but not DCVII, 2.34e12 or 1,234,567.00

my %count; while (<FH>) { $count{lc $_}++ for grep { !m{^[0-9]+(\.[0-9]+)?$} } m/\w+/g; }

For a complete regular expression to integers and reals, I'd like to refer to Regexp::Common (see $RE{num}).

update: /me just realized that it is overly complex, as \w+ can only match integers without a triad-sep, as . is not included in \w, reducing the loop-line to

$count{lc $_}++ for grep { !m{^[0-9]+$} } m/^\w+$/g;

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^4: compute the occurrence of words
by BigGer (Novice) on Feb 13, 2013 at 14:40 UTC

    Thanks H.Merijn That's perfect. I will go and read up on the hash function. G

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018546]
help
Chatterbox?
[Lady_Aleena]: I don't want to have to do: alpha_menu($hash, undef, $type);
[Lady_Aleena]: Or what Discipulus said.
[shmem]: Lady_Aleena: geany supports ctags.
[Discipulus]: a good compromise can be my ($need, $opts_ref) = @_ a scalar and an hash reference
[Discipulus]: see you monks!
[Lady_Aleena]: shmem, let me get this sub rewritten, then I will look into how to use ctags in geany. Deal? 8)
[shmem]: Discipulus: yeah, that might eventually prepare the path for OO ;-)
[Lady_Aleena]: See you, Discipulus.
[shmem]: Lady_Aleena: that's up to you. I only wanted to show you a path that might be more comforting than command line grep ;-)
[Lady_Aleena]: shmem, I don't think any of my modules could be converted to OO. They are too procedural.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-27 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (506 votes). Check out past polls.