[BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Chris Brown
so...this is suposed to count the words in FILE and return how many occourances of each word there were...its not working for me thoughits only returning the count for the last word in the file...help #!/usr/local/bin/perl open (FILE,"../www/main.php3"); @lines=; close(FILE); foreach $i (

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Timothy Kimball
: so...this is suposed to count the words in FILE and return how many occourances of :each word there were...its not working for me thoughits only returning the count :for the last word in the file...help Think: In the first loop, what happens to the first line when you move to the second?

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Casey West
On Tue, Apr 24, 2001 at 10:17:02AM -0500, Chris Brown wrote: : so...this is suposed to count the words in FILE and return how many occourances of :each word there were...its not working for me thoughits only returning the count :for the last word in the file...help The following is a genera

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Collin Rogowski
The problem is that you override the (global) array @words for each line. You go through @lines and the split overrides @words! While we are at it... ;-) You do not need that many loops. The programm will be much simpler like that: open(FILE, "yourFileName"); while ($line = ) { #no need to read

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Sean O'Leary
At 11:17 AM 4/24/2001, you wrote: >so...this is suposed to count the words in FILE and return how many >occourances of each word there were...its not working for me thoughits >only returning the count for the last word in the file...help > >#!/usr/local/bin/perl > >open (FILE,"../www/main.ph

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Paul
--- Chris Brown <[EMAIL PROTECTED]> wrote: > so...this is suposed to count the words in FILE and return how many > occourances of each word there were...its not working for me > thoughits only returning the count for the last word in the > file...help > > #!/usr/local/bin/perl > > open (FIL

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Kevin Meltzer
Hi Chris, You are getting only the last line of the file because of this: > foreach $i (@lines) { > @words = split(/\s+/, $i); > } You reassign the @words array each time, and end up with the last line only when exiting the foreach loop. You may want to look at 'perldoc -f push' to see how to a

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Michael Lamertz
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 = ; # slurps in the whole file to $data > } > cl

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Paul
Agreed, and thanks for pointing that out! --- Michael Lamertz <[EMAIL PROTECTED]> wrote: > 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 t

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-26 Thread Bill Lawry
CTED]> 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

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-26 Thread Paul
" <[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 ([EMA

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-26 Thread Paul
; map { $count{$_}++ } $data =~ /(\w+)/sog; > > try >$count{$_}++ } for $data =~ /([\w-]+)/sog; ps^Make that: $count{$_}++ for $data =~ /([\w-]+)/sog; > > - Original Message - > > From: "Michael Lamertz" <[EMAIL PROTE

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-27 Thread Bill Lawry
;[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, April 26, 2001 6:59 PM Subject: Re: [BPQ] help!! any idea whats wrong with this?? > > --- Paul <[EMAIL PROTECTED]> wrote: > > > > --- Bill Lawry <[EMAIL PROTECTED]> wrote: > > > Pretty coo

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-27 Thread Paul
- > From: "Paul" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]>; "Bill Lawry" <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Thursday, April 26, 2001 6:59 PM > Subject: Re: [BPQ] help!! any idea whats wrong with this?? > >

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-27 Thread Timothy Kimball
: Because someone (and with apologies to all, I don't recall off the top : of my head who)correctly pointed out to me earlier in this thread that : using map() here was inefficient. map() builds and returns an array, so : there's no point in using it in this void context. Aside from that, : both

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-27 Thread Michael Lamertz
Timothy Kimball ([EMAIL PROTECTED]) wrote: > > : Because someone (and with apologies to all, I don't recall off the top > : of my head who)correctly pointed out to me earlier in this thread that > : using map() here was inefficient. map() builds and returns an array, so > : there's no point in us

Re: [BPQ] help!! any idea whats wrong with this??

2001-04-27 Thread Timothy Kimball
: Ah, a Heisenbug. There's a problem with your benchmarking: Yep, you're right. map is slightly slower when it actually has something to do. I stand corrected... again. So the moral of the story is: If you want your code to run really fast, make it do nothing. ;) That's what I love about Per