--- Paul <[EMAIL PROTECTED]> wrote:
> 
> --- Bill Lawry <[EMAIL PROTECTED]> wrote:
> > Pretty cool but when used on a file it breaks hyphenated words into
> > their components and counts them separately:
> > 
> > 17 occurrences of 'Acct'
> > 3 occurrences of 'Authentic'
> > etc
> > 
> > instead of:
> > 
> > 3 occurrences of Acct-Authentic
> > 3 occurrences of Acct-Delay-Time
> > 1 occurrences of Acct-Input-Octets
> > 1 occurrences of Acct-Input-Packets
> > 1 occurrences of Acct-Output-Octets
> > 1 occurrences of Acct-Output-Packets
> > 3 occurrences of Acct-Session-Id
> > 1 occurrences of Acct-Session-Time
> > 3 occurrences of Acct-Status-Type
> 
> Not what you want? Then let's edit the pattern. =o)
> 
> Instead of
>   map { $count{$_}++ } $data =~ /(\w+)/sog;
> 
> try 
>    $count{$_}++ } for $data =~ /([\w-]+)/sog;

OOOOps............^    Make that:

    $count{$_}++ for $data =~ /([\w-]+)/sog;


> > ----- Original Message -----
> > From: "Michael Lamertz" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Cc: "Chris Brown" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Tuesday, April 24, 2001 1:03 PM
> > Subject: Re: [BPQ] help!! any idea whats wrong with this??
> > 
> > 
> > > Paul ([EMAIL PROTECTED]) wrote:
> > > >
> > > >  #!/usr/local/bin/perl -w
> > > >
> > > >  use strict
> > > >  open (FILE,$0) or die $!; # this reads itself
> > > >  my($data,%count);
> > > >  { local $/ = undef;       # erases the record seperator for
> this
> > block
> > > >    $data = <FILE>;         # slurps in the whole file to $data
> > > >  }
> > > >  close(FILE);              # good habit
> > > >  map { $count{$_}++ } $data =~ /(\w+)/sog; # watch the context!
> > > >  print map { "$count{$_} occurances of '$_'\n" } sort keys
> > %count;
> > > >
> > > > Perl is a wonderfully concise language.
> > > > The above is strictly given as an example of a few performance
> > tricks
> > > > that are worth researching. =o)
> > >
> > > I agree printing the map output, but I disagree using map to
> > calculate
> > > the sums.  map always generates a new array that immediately gets
> > dumped
> > > since it's not assigned.  A foreach would be nicer to system
> > resources
> > > and better to read.  To make it short, use it postfix:
> > >
> > >     $count{$_}++ foreach ($data=~ /.../);
> > >
> > > Check 'perldoc perlfaq6' for reference.
> > >
> > > --
> > >                      If we fail, we will lose the war.
> > >
> > > Michael Lamertz          | [EMAIL PROTECTED] /
> > [EMAIL PROTECTED]
> > >     Nordstr. 49          | http://www.lamertz.net
> > >     50733 Cologne        | Work: +49 221 3091-121
> > >     Germany              | Priv: +49 221 445420 / +49 171 6900
> 310
> > >
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to