Re: Counting elements returned from expression

2016-10-05 Thread Chas. Owens
Yep, that is pretty much it. Infix operators can make things like that confusing. For instance, #!/usr/bin/perl use strict; use warnings; my @a = qw/a b c/; my @b = qw/d e f/; my $x = ("a", "b", "c", "d", "e", "f"); my $y = (@a, @b); my $z = (@a[0 .. $#a], @b[0 .. $#b]); print "x $x y $y z $

Re: Counting elements returned from expression

2016-10-05 Thread khalil zakaria Zemmoura
I think I had a problem with my approach. I never thought about assignment operator as returning something at all ! When we include that parameter in the "equation" everything is clear. Since the list assignment is in scalar context, it returns the number of items directly and that number is assig

Re: Counting elements returned from expression

2016-10-04 Thread Chas. Owens
You almost have it. What you are missing is that the list assignment operator is in scalar context and is returning the count, not the list being assigned to. Infix operators obscure things sometimes. It is easier to understand if we rewrite it as if list assignment was a function call instead o

Re: Counting elements returned from expression

2016-10-04 Thread zakaria
To summarize There is a list assignment and the difference between assigning to an empty list and an non empty list is the container(s) inside the liste that capture the different values (scalars or lists or hashes) for example () ans ($a, @b, %c... ) when we assign to an ampty list the values a

Re: Counting elements returned from expression

2016-10-04 Thread Chas. Owens
On Mon, Oct 3, 2016 at 10:45 PM Lawrence Statton wrote: snip > the =()= "operator" just does that without creating a temporary variable snip Almost, but not quite. You can see the difference when =()= is in list context: my @a = (my @temp) = get_clown_hat; my @b = () = get_clown_hat; @a will

Re: Counting elements returned from expression

2016-10-03 Thread Lawrence Statton
On 10/03/2016 06:17 PM, khalil zakaria Zemmoura wrote: Hi, I am reading modern Perl and despite the explanation of the author I couldn't understand: my $count = () = get_clown_hats() It's obvious to me that the function get_clown_hat() is evaluated in list context but what the author said is th

Re: Counting elements returned from expression

2016-10-03 Thread Chas. Owens
So, list assignment is my ($foo, $bar, $baz) = ("a", "b", "c"); $foo will be "a", $bar will be "b", etc. There can be more items on the right hand side and they won't be copied. This operation has a return value. In list context it is the list of values that got assigned. In scalar context it is

Re: Counting Word Occurances

2011-07-16 Thread Dr.Ruud
On 2011-07-15 17:58, Matt wrote: I have a file with lines like so but the number of them is in the thousands instead of seven lines: blue red red red orange orange green I want it to count the occurances of each word it finds in the file. So output on this small file would be: blue (1) red (3

Re: Counting Word Occurances

2011-07-15 Thread Rob Dixon
On 15/07/2011 16:58, Matt wrote: I have a file with lines like so but the number of them is in the thousands instead of seven lines: blue red red red orange orange green I want it to count the occurances of each word it finds in the file. So output on this small file would be: blue (1) red (3)

Re: Counting Word Occurances

2011-07-15 Thread jbiskofski
my %words; while (<>) { # read input line by line... # remove trailing new line chomp; my $word = $_; $words{$word}++; } foreach my $word (sort keys %words) { print "$word ($words{$word})\n"; } -- you can run the script like this : cat file.txt | perl script.pl

Re: Counting Word Occurances

2011-07-15 Thread Shawn H Corey
On 11-07-15 11:58 AM, Matt wrote: The contents of the file are sorted already. Any ideas how to do this? Thanks. Yes, see attached. -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communicatio

Re: counting number of multiple occurances in a row

2008-08-16 Thread Dr.Ruud
Rob Dixon schreef: > Mr. Shawn H. Corey wrote: >> SELECT company, COUNT(*) >> FROM commitCurrent >> GROUP BY company; > > Someone else has personal standards for SQL! Thank you Shawn! Do you keep a list of them? I would write it as SELECT c.company , COUNT(*) AS n FROM commitCurrent

Re: counting number of multiple occurances in a row

2008-08-15 Thread Mr. Shawn H. Corey
On Fri, 2008-08-15 at 15:57 +0100, Rob Dixon wrote: > Mr. Shawn H. Corey wrote: > > > > SELECT company, COUNT(*) > > FROM commitCurrent > > GROUP BY company; > > Someone else has personal standards for SQL! Thank you Shawn! > > Rob > Personal standards? I find that to be an oxymoron and a lit

Re: counting number of multiple occurances in a row

2008-08-15 Thread Rob Dixon
Mr. Shawn H. Corey wrote: > > SELECT company, COUNT(*) > FROM commitCurrent > GROUP BY company; Someone else has personal standards for SQL! Thank you Shawn! Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: counting number of multiple occurances in a row

2008-08-15 Thread Mr. Shawn H. Corey
On Fri, 2008-08-15 at 13:57 +0100, Pat Rice wrote: > hi > I would like know how to count multiple occurances in a sql query. > > eg. > > row would be: > tom, tom , tom, john,pat,pat > > and this would produce > tom 3 > john 1 > pat 2 > > > I've tried this but I am only gettting 1 back > select

Re: Counting keys in an array of hashes?

2008-02-22 Thread jamesdon
On Feb 21, 9:46 am, [EMAIL PROTECTED] (Chas. Owens) wrote: > On Wed, Feb 20, 2008 at 11:03 PM, <[EMAIL PROTECTED]> wrote: > > snip> Oh - I wanted to eliminate all members of the array that had more than > > 10 instances of the same port. I was hoping that you could do > > something like "count

Re: Counting keys in an array of hashes?

2008-02-21 Thread Chas. Owens
On Wed, Feb 20, 2008 at 11:03 PM, <[EMAIL PROTECTED]> wrote: snip > Oh - I wanted to eliminate all members of the array that had more than > 10 instances of the same port. I was hoping that you could do > something like "count keys where port = gi1/1/49". After knowing how > many gi1/1/49 th

Re: Counting keys in an array of hashes?

2008-02-21 Thread jamesdon
On Feb 20, 10:26 pm, [EMAIL PROTECTED] wrote: > Hi, thank you all for your input - I managed to get what I wanted > done. Sorry I was not very clear on the issue, but it helped to write > it out. > > Jim Please ignore this post ^, I do not have a end solution yet. -- To unsubscribe, e-mail: [E

Re: Counting keys in an array of hashes?

2008-02-21 Thread jamesdon
> I have a feeling that I am going about this in the wrong > way. Can I use hashes in a better way to sort the data based on the > keys? Better yet, can I evaluate the number of keys that match each > other? I don't understand what that means. John Oh - I wanted to eliminate all members of

Re: Counting keys in an array of hashes?

2008-02-21 Thread jamesdon
Hi, thank you all for your input - I managed to get what I wanted done. Sorry I was not very clear on the issue, but it helped to write it out. Jim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Counting keys in an array of hashes?

2008-02-20 Thread Chas. Owens
On Feb 19, 2008 11:12 PM, <[EMAIL PROTECTED]> wrote: > I am reading in a file, building an array of information that I need > to evaluate: > > while () { > if ($_ =~ m/stuff/) { > push(@data, {'vlan' => $vlan, 'host' => $host, 'mac' => $mac, 'port' > => $port}); > } > } > > Small sample of @da

Re: Counting keys in an array of hashes?

2008-02-20 Thread John W. Krahn
[EMAIL PROTECTED] wrote: I am reading in a file, building an array of information that I need to evaluate: while () { if ($_ =~ m/stuff/) { push(@data, {'vlan' => $vlan, 'host' => $host, 'mac' => $mac, 'port' => $port}); } } Small sample of @data: vlan hostmac

Re: Counting & arrays

2006-05-22 Thread JupiterHost.Net
for my $action (keys %actionrule) { print "Action is: $action\n"; for my $rule (keys %{ $actionrule{$action} }) { print "\tRule is: $rule\n"; print "\t\tand its count is: $actionrule{$action}{$rule}\n"; } } THANK YOU!! This works beautifully! I was pulling my

RE: Counting & arrays

2006-05-22 Thread Michael Gargiullo
-Original Message- From: JupiterHost.Net [mailto:[EMAIL PROTECTED] Sent: Monday, May 22, 2006 6:12 PM To: beginners@perl.org Subject: Re: Counting & arrays Michael Gargiullo wrote: > It's been a while since I've used Perl and I need some help with a > multidimen

Re: Counting & arrays

2006-05-22 Thread JupiterHost.Net
Michael Gargiullo wrote: It's been a while since I've used Perl and I need some help with a multidimensional array. AKA a HASH :) You want a hash not an array :) I have a file that I need to compile some stats on. I need to keep track of 'actions' and 'rules'. Yes, stats from a firewall.

Re: Counting & arrays

2006-05-22 Thread Dave Gray
On 5/22/06, Michael Gargiullo <[EMAIL PROTECTED]> wrote: It's been a while since I've used Perl and I need some help with a multidimensional array. I have a file that I need to compile some stats on. I need to keep track of 'actions' and 'rules'. Yes, stats from a firewall. Both 'actions' and

Re: Counting specific elements in a XML object

2006-03-30 Thread Hans Meier (John Doe)
Bob Showalter am Donnerstag, 30. März 2006 23.32: > Chas Owens wrote: > > If we are going to pick nits then it should be > > > > grep -c "" fn > > Note that grep -c counts matching *lines*. There is no formal > requirement that these elements appear on separate lines. Dave, my first one-liner su

Re: Counting specific elements in a XML object

2006-03-30 Thread Bob Showalter
Chas Owens wrote: If we are going to pick nits then it should be grep -c "" fn Note that grep -c counts matching *lines*. There is no formal requirement that these elements appear on separate lines. Here's a slightly more complex Perl one-liner that counts *occurences* perl -lne '$n++ f

Re: Counting specific elements in a XML object

2006-03-30 Thread Hans Meier (John Doe)
Chas Owens am Donnerstag, 30. März 2006 22.35: > > > cat fn | grep | wc [...] > > grep fn | wc [...] > If we are going to pick nits then it should be > > grep -c "" fn too much work. c "" fn But your alias may be different ;-) Hans -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional

Re: Counting specific elements in a XML object

2006-03-30 Thread Chas Owens
On 3/30/06, Hans Meier (John Doe) <[EMAIL PROTECTED]> wrote: > Gavin Bowlby am Donnerstag, 30. März 2006 21.45: > > How about: > > > > cat fn | grep | wc > > When I posted a "cat | grep" the first (and last) time, several people got a > well known heart attack :-) > > grep fn | wc > > > as a non-

Re: Counting specific elements in a XML object

2006-03-30 Thread Hans Meier (John Doe)
Gavin Bowlby am Donnerstag, 30. März 2006 21.45: > How about: > > cat fn | grep | wc When I posted a "cat | grep" the first (and last) time, several people got a well known heart attack :-) grep fn | wc > as a non-Perl approach to the problem... [...] Agreed, but OT here ;-) Hans -- To uns

RE: Counting specific elements in a XML object

2006-03-30 Thread Gavin Bowlby
How about: cat fn | grep | wc as a non-Perl approach to the problem... -Original Message- From: Hans Meier (John Doe) [mailto:[EMAIL PROTECTED] Sent: Thursday, March 30, 2006 11:38 AM To: beginners@perl.org Subject: Re: Counting specific elements in a XML object Dave Adams am

Re: Counting specific elements in a XML object

2006-03-30 Thread Hans Meier (John Doe)
Dave Adams am Donnerstag, 30. März 2006 21.12: > If I have a xml file like the following: > > > > John Doe > 43 > M > Recieving > > > Bob Gordon > 50 > M > Shipping > > > > Is there some perl module out there that can help me get

Re: counting scalar array elements question

2006-03-09 Thread Hans Meier (John Doe)
John W. Krahn am Donnerstag, 9. März 2006 03.36: > Hans Meier (John Doe) wrote: [...] > > my @array; > > #or: > > my @array=(); [v--- this sidenote is wrong] > > (sidenote: the second form must be used in contexts where the code is > > persistent/preloaded and used several times, to ensure that @

Re: counting scalar array elements question

2006-03-08 Thread John W. Krahn
Hans Meier (John Doe) wrote: >>>From: Graeme McLaren [mailto:[EMAIL PROTECTED] >>> >>> If I have a variable, $var, and it contains an array how would I be >>> able to easily count the number of elements in the array? I've tried >>> creating a new array and pushing the original array on to it but t

Re: counting scalar array elements question

2006-03-08 Thread Hans Meier (John Doe)
> > From: Graeme McLaren [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, March 08, 2006 3:57 PM > > To: beginners@perl.org > > Subject: counting scalar array elements question > > > > Hi all, I have an array question: > > > > If I have a variable, $var, and it contains an array how would I be able >

RE: counting scalar array elements question

2006-03-08 Thread Timothy Johnson
You need to dereference your array ref. my $count = @{$var}; Or in some circumstances it might make more sense to explicitly use scalar context: my $count = scalar @{$var}; -Original Message- From: Graeme McLaren [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 08, 2006 3:57 PM T

Re: Counting Multiple lines of data with a unique column of information

2005-03-08 Thread Willy West
forgot to reply to all for the following *laugh* -- Forwarded message -- From: Willy West <[EMAIL PROTECTED]> Date: Tue, 8 Mar 2005 19:20:24 -0500 Subject: Re: Counting Multiple lines of data with a unique column of information To: "Wilson, Josh --- Systems Ana

Re: Counting Multiple lines of data with a unique column of information

2005-03-08 Thread John W. Krahn
Wilson, Josh --- Systems Analyst --- GO wrote: I have a scenario in which palettes are weighed prior to delivery and then that data is submitted to a server. Once the data is transferred, I have to parse a batch file and strip out information for each shipment number and format it for print. Th

Re: Counting occurences of a char in a line

2005-01-17 Thread Tor Hildrum
On Tue, 18 Jan 2005 01:08:56 +0100, Jenda Krynicky <[EMAIL PROTECTED]> wrote: > foreach my $line () { > if ( $line =~ /^[^,]*(?:,[^,]*){10}$/) ) { > print OUT $line; > } > } > > That is check whether the full string is "something not containing > comma followed by ten times comma

Re: Counting occurences of a char in a line

2005-01-17 Thread Jenda Krynicky
From: Tor Hildrum <[EMAIL PROTECTED]> > I have the following code in a script I'm writing: > > foreach my $line () { > if ( 10 == ($line =~ s/,/,/g) ) { > print OUT $line; > } > } > > Is this poor style? It looks a bit ugly, but I can't figure out a > better way to do it. I'm sure

Re: Counting occurences of a char in a line

2005-01-17 Thread John W. Krahn
Tor Hildrum wrote: Hi, Hello, I have the following code in a script I'm writing: foreach my $line () { if ( 10 == ($line =~ s/,/,/g) ) { print OUT $line; } } Is this poor style? It looks a bit ugly, but I can't figure out a better way to do it. I'm sure there is :) The script will b

RE: Counting occurences of a char in a line

2005-01-17 Thread Bakken, Luke
> Hi, > > I have the following code in a script I'm writing: > > foreach my $line () { > if ( 10 == ($line =~ s/,/,/g) ) { > print OUT $line; > } > } > > Is this poor style? It looks a bit ugly, but I can't figure out a > better way to do it. I'm sure there is :) > The script wil

Re: Counting gaps in sequence data revisited.

2004-10-26 Thread Zeus Odin
"Michael S. Robeson II" <[EMAIL PROTECTED]> wrote in message ... > open(DNA_SEQ, $dna_seq) Due to precedence, the parens are optional here. > open(OUTFILE, ">indel_list_"."$dna_seq") ^ ">indel_list_$dna_seq" or ">indel_list_".$dna_seq > foreach (keys

Re: counting gaps in sequence data

2004-10-24 Thread Zeus Odin
This is a really cool problem. See solution below. Michael, next time post some code please. Thanks, ZO -- #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my(%gap, $animal); while () { if (/>(\w+)/) { $animal = $1; } else { while (/(-+)/) { $gap{$animal

Re: Counting gaps in sequence data revisited.

2004-10-17 Thread Michael S. Robeson II
I cleaned up the code a little. So, here it is for anyone interested: #!usr/bin/perl # By Michael S. Robeson II with the help from the folks at lernperl.org and bioperl.org # 10/16/2004 # Last updated: 10/17/2004 # This script was made for the purpose of searching for indels (gaps) in aligned # D

Re: counting gaps in sequence data

2004-10-15 Thread Michael Robeson
Errin, Thanks so much! I will spend the weekend going over what you've posted. Looks like I will learn a lot from this post alone. This stuff is so addictive. I can spend hours doing this and not realize it. If I am successful or not is another story! :-) I'll definitely let you know if I have

Re: counting gaps in sequence data

2004-10-15 Thread Errin Larsen
On Thu, 14 Oct 2004 16:11:42 -0600, Michael Robeson <[EMAIL PROTECTED]> wrote: > Yeah, I have just submitted that same question verbatim to the bio-perl > list. I am still running through some ideas though. I have both > Bioinformatics perl books. They are not very effective teaching books. > > Th

Re: counting gaps in sequence data

2004-10-14 Thread Philipp Traeder
On Thursday 14 October 2004 21:44, Michael Robeson wrote: > Here is as far as I can get with some real code and pseudo code. This > is just to show you that I am actually trying. :-) Hi Michael, this looks quite promising - I'll try to sketch a solution without giving everything away ;-) > > Ps

Re: counting gaps in sequence data

2004-10-14 Thread Michael Robeson
Yeah, I have just submitted that same question verbatim to the bio-perl list. I am still running through some ideas though. I have both Bioinformatics perl books. They are not very effective teaching books. The books spend too much time on using modules. Though while I understand the usefulness

Re: counting gaps in sequence data

2004-10-14 Thread Paul Johnson
On Thu, Oct 14, 2004 at 04:50:30PM -0500, Errin Larsen wrote: > Hi Paul, > I think you missed a critical part of Mike's post!: No, I didn't miss it. I just thought it likely that Mike could get to there from where I left off, so I gave a solution to the bit that seemed most troublesome. >

Re: counting gaps in sequence data

2004-10-14 Thread Errin Larsen
On Thu, 14 Oct 2004 23:23:48 +0200, Paul Johnson <[EMAIL PROTECTED]> wrote: > On Thu, Oct 14, 2004 at 11:02:06AM -0600, Michael Robeson wrote: > > > I have a set of data that looks something like the following: > > > So, my problem is that I think I know some of the bits of code to put > > into p

Re: counting gaps in sequence data

2004-10-14 Thread Michael Robeson
Here is as far as I can get with some real code and pseudo code. This is just to show you that I am actually trying. :-) Pseudo - code # open DNA sequence file print "Enter in the name of the DNA sequence file:\n"; chomp (my $dna_s

Re: counting gaps in sequence data

2004-10-14 Thread Paul Johnson
On Thu, Oct 14, 2004 at 11:02:06AM -0600, Michael Robeson wrote: > I have a set of data that looks something like the following: > So, my problem is that I think I know some of the bits of code to put > into place the problem is I am getting lost on how to structure it all > together. >

Re: counting gaps in sequence data

2004-10-14 Thread Errin Larsen
On Thu, 14 Oct 2004 16:08:44 -0400, Willy West <[EMAIL PROTECTED]> wrote: > On Thu, 14 Oct 2004 14:47:57 -0500, Errin Larsen <[EMAIL PROTECTED]> wrote: > > > > > > bio-informatics is a big area in which Perl is involved... there's even > > > a book from O'reilly on the subject... > > > If what

Re: counting gaps in sequence data

2004-10-14 Thread Willy West
On Thu, 14 Oct 2004 14:47:57 -0500, Errin Larsen <[EMAIL PROTECTED]> wrote: > > > bio-informatics is a big area in which Perl is involved... there's even > > a book from O'reilly on the subject... > If what you say is true, then maybe Mike needs to take his questions > to those list? I mean

Re: counting gaps in sequence data

2004-10-14 Thread Errin Larsen
On Thu, 14 Oct 2004 15:40:24 -0400, Willy West <[EMAIL PROTECTED]> wrote: > > PS: is this a common problem/exercise in some class somewhere? I keep > > seeing requests for help having to do with those exact strings of DNA > > data. Is there a bunch of people working on DNA projects using Perl > >

Re: counting gaps in sequence data

2004-10-14 Thread Willy West
> PS: is this a common problem/exercise in some class somewhere? I keep > seeing requests for help having to do with those exact strings of DNA > data. Is there a bunch of people working on DNA projects using Perl > somewhere? Or, is this some homework? bio-informatics is a big area in which Pe

Re: counting gaps in sequence data

2004-10-14 Thread Errin Larsen
On Thu, 14 Oct 2004 11:02:06 -0600, Michael Robeson <[EMAIL PROTECTED]> wrote: > I have a set of data that looks something like the following: > <> > > So, any suggestions would be greatly appreciated. If anyone can help me > out with all or even just bits of this I would greatly appreciate it.

Re: Counting characters in a thread

2004-08-15 Thread Zeus Odin
The fastest would probably be: $text = '' if $text =~ tr/%// > 10; -ZO <[EMAIL PROTECTED]> wrote ... > How would I empty $string if it contained more than ten % characters? In > other words -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Counting characters in a thread

2004-07-09 Thread John W . Krahn
On Friday 09 July 2004 04:26, Ricardo SIGNES wrote: > * [EMAIL PROTECTED] [2004-07-09T07:20:57] > > > How would I empty $string if it contained more than ten % > > characters? In other words > > $string = "" if split(/%/, $string) > 10; That will produce the warning: Use of implicit split to @_ is

Re: Counting characters in a thread

2004-07-09 Thread John W . Krahn
On Friday 09 July 2004 04:20, [EMAIL PROTECTED] wrote: > $string = > "a%3A2%3A%7Bi%3A0%3Bs%3A3%3A%22489%22%3Bi%3A1%3Bs%3A32%3A%22a85a44c18 >81523798bc155a5369e1226%22%3B%7D" > > How would I empty $string if it contained more than ten % characters? > In other words > > $string = > "a%3A2%3A%7Bi%3A0%

Re: Counting characters in a thread

2004-07-09 Thread Ricardo SIGNES
* [EMAIL PROTECTED] [2004-07-09T07:20:57] > How would I empty $string if it contained more than ten % characters? In > other words $string = "" if split(/%/, $string) > 10; -- rjbs pgpO8nLAuJ7WJ.pgp Description: PGP signature

Re: Counting help

2004-06-16 Thread Rakhitha Karunarathne
$q->execute(); while (my @row=$q->fetchrow_array()){ $data{$row[2]}->{$row[1]} = $row[0]; } $q->finish(); LRMK - Original Message - From: "Wiggins d Anconia" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, June 16, 2004 9:59 PM Subject:

RE: Counting help

2004-06-16 Thread Wiggins d Anconia
> [..] > > I will try and explain again what I am trying to do. > > I read in a file with a list of > > roomsThen im trying to list the room once and then count > > how many records match for the select statement and only > > print the building once with a count in front of it.. > > > >

RE: Counting help

2004-06-16 Thread Traeder, Philipp
[..] > I will try and explain again what I am trying to do. > I read in a file with a list of > roomsThen im trying to list the room once and then count > how many records match for the select statement and only > print the building once with a count in front of it.. > > db: > date build

Re: Counting help

2004-06-16 Thread rmck
D:211 11BLD:333 For 20 : 1BLD:1544 2BLD:1544 My goal was to have this output: For 30 : 10BLD:211 1BLD:333 For 20 : 2BLD:1544 Thanks.. -Original Message- From: Wiggins d Anconia <[EMAIL PROTECTED]> Sent: Jun 16, 2004 7:23 AM To: rmck <[EMAIL PROTECTED]>, [EMAIL PROTECTED] Subj

Re: Counting help

2004-06-16 Thread Wiggins d Anconia
> Im trying to list a record once and then count how many records. But I keep getting a list of all the records and it counts those?? I read in a file with a list of rooms and then look for each one that matches dept 22 and Im trying to show it once and then count how many for the building? > > >

Re: Counting frequency of words.

2004-02-25 Thread WC -Sx- Jones
[... an oldie but a goodie -- don't remember the original author. -Sx-] =pod #!C:\perl\bin\perl.exe #!/usr/bin/perl # A Perl filter that will take the selected text, sort the # words, put into a column, remove duplicates, then output a # word count by each. use strict; my %count; while () {

Re: Counting frequency of words.

2004-02-25 Thread Rob Dixon
Vishal Vasan wrote: > > I have to find the frequency of occurance of all (mail code: This is the > first 8 characters of the line) in a huge file. Instead of doing it in C > I am trying it out in perl. I am trying hashes for this. Whenever a new > code comes, the count has to be incremented. > > Th

Re: counting down in a for

2003-12-12 Thread drieux
On Dec 11, 2003, at 1:20 PM, [EMAIL PROTECTED] wrote: [..] Why not Open the directory with say opendir() and get the list of files in it? then use the readdir() and 'grep' type tricks: opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @today_files = grep {$_ =~ /^pollerAudit.$fileDa

Re: counting down in a for

2003-12-12 Thread Rob Dixon
<[EMAIL PROTECTED]> wrote: > > At 20:45 11/12/2003, you wrote: > > >On Dec 11, 2003, at 11:49 AM, [EMAIL PROTECTED] wrote: > >[..] > >> there is probably a much better way of doing all this i am working on > >>the checkResults sub. > >>it should find the pollerAudit log created by the main process

Re: counting down in a for

2003-12-11 Thread DrOwl
At 20:45 11/12/2003, you wrote: >On Dec 11, 2003, at 11:49 AM, [EMAIL PROTECTED] wrote: >[..] >> there is probably a much better way of doing all this i am working on >>the checkResults sub. >>it should find the pollerAudit log created by the main process >>(discover) the file format for the log

Re: counting down in a for

2003-12-11 Thread drieux
On Dec 11, 2003, at 11:49 AM, [EMAIL PROTECTED] wrote: [..] there is probably a much better way of doing all this i am working on the checkResults sub. it should find the pollerAudit log created by the main process (discover) the file format for the log file is pollerAudit.M.D.Y.h.m.s.lan (MDYhms

Re: Counting (easy!) - select???

2003-11-16 Thread Rob Dixon
Joseph wrote: > > Rob Dixon wrote: > > > > Not exactly a transparent piece of code though is it. Especially > > if your base system isn't Unix! > > Works jusat fine on Windows, although it helps to have a longer list, > since this gets p[rocessed really fast, too fast to see what's going > on. Try

Re: Counting (easy!) - select???

2003-11-16 Thread Rob Dixon
R. Joseph Newton wrote: > > Rob Dixon wrote: > > > > > Not exactly a transparent piece of code though is it. Especially > > if your base system isn't Unix! > > Works jusat fine on Windows, although it helps to have a longer list, since this > gets p[rocessed really fast, too fast to > see what's g

Re: Counting (easy!) - select???

2003-11-15 Thread R. Joseph Newton
Rob Dixon wrote: > > Not exactly a transparent piece of code though is it. Especially > if your base system isn't Unix! Works jusat fine on Windows, although it helps to have a longer list, since this gets p[rocessed really fast, too fast to see what's going on. Try increasing the loop count to

Re: Counting (easy!)

2003-11-14 Thread R. Joseph Newton
Steve Grazzini wrote: > > What do you think is happening under the hood for something like > > > > print for (0..0, 1, 2..5, func(6)..func(99)) > > I think the whole list would have to be generated. The optimization > only applies to the case where there's just one range in place of the > LIST.

Re: Counting (easy!)

2003-11-14 Thread Tim
You need to escape the '@' in your variable: /*** open(FILE, " $email = "[EMAIL PROTECTED]"; while () { print; print if (/$email/); # $OK = 1 if /$email/; } */ At 04:19 PM 11/13/03 -0500, you wrote: I have a list of email addresses in a text file one to a line.

RE: Counting (easy!)

2003-11-13 Thread LoBue, Mark
> -Original Message- > From: Tore Aursand [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 13, 2003 3:50 PM > To: [EMAIL PROTECTED] > Subject: Re: Counting (easy!) > > > On Thu, 13 Nov 2003 16:19:32 -0500, Jimstone77 wrote: > > I have a list of email add

Re: Counting (easy!)

2003-11-13 Thread Tore Aursand
On Thu, 13 Nov 2003 16:19:32 -0500, Jimstone77 wrote: > I have a list of email addresses in a text file one to a line. How would I > seach for a particular email address? > > $email = "[EMAIL PROTECTED]"; > > while { >if ($email eq $_) { > $OK = 1; >} > } Doesn't this work? I wou

Re: Counting (easy!)

2003-11-13 Thread Steve Grazzini
On Thu, Nov 13, 2003 at 09:16:59PM -, Rob Dixon wrote: > Steve Grazzini wrote: >> This is a documented optimization w/r/t foreach() loops, but the same >> thing applies to the foreach() modifier. > > What the code is optimised to is a touch OT, but I've never seen this > documented Steve. Can

search for email address in file, was Re: Counting (easy!)

2003-11-13 Thread Wiggins d Anconia
Please choose a subject that is reflective of your post and start a new thread when appropriate... > > I have a list of email addresses in a text file one to a line. How would I > seach for a particular email address? > > $email = "[EMAIL PROTECTED]"; > The @ in the above does need to be esca

Re: Counting (easy!)

2003-11-13 Thread Jimstone77
I have a list of email addresses in a text file one to a line. How would I seach for a particular email address? $email = "[EMAIL PROTECTED]"; while { if ($email eq $_) { $OK = 1; } } It seems the @ symbol somehow doesn't work in this search. What would be a better (or right) way t

Re: Counting (easy!)

2003-11-13 Thread Rob Dixon
Steve Grazzini wrote: > > On Thu, Nov 13, 2003 at 12:09:24PM -0800, John W. Krahn wrote: > > Rob Dixon wrote: > > > For the subscribers who don't already know, > > > what are the differences between my > > > > > > print for 1..5 > > > > for iterates over the list 1..5 and sets $_ with each value

Re: Counting (easy!)

2003-11-13 Thread John W. Krahn
Steve Grazzini wrote: > > On Thu, Nov 13, 2003 at 12:09:24PM -0800, John W. Krahn wrote: > > Rob Dixon wrote: > > > For the subscribers who don't already know, > > > what are the differences between my > > > > > > print for 1..5 > > > > for iterates over the list 1..5 and sets $_ with each value

Re: Counting (easy!)

2003-11-13 Thread Rob Dixon
John W. Krahn wrote: > > > > > For the subscribers who don't already know, > > what are the differences between my > > > > print for 1..5 > > for iterates over the list 1..5 and sets $_ with each value and then > print is called for each item and print out the value in $_. > > > and Tore's > > >

Re: Counting (easy!)

2003-11-13 Thread Steve Grazzini
On Thu, Nov 13, 2003 at 12:09:24PM -0800, John W. Krahn wrote: > Rob Dixon wrote: > > For the subscribers who don't already know, > > what are the differences between my > > > > print for 1..5 > > for iterates over the list 1..5 and sets $_ with each value and then > print is called for each it

Re: Counting (easy!)

2003-11-13 Thread John W. Krahn
Rob Dixon wrote: > > Tore Aursand wrote: > > > > On Thu, 13 Nov 2003 09:05:45 -0600, Dan Muey wrote: > > >> In Perl that is usually written as: > > >> > > >> for $count ( 1 .. 5 ) { > > >> print "$count\n"; > > >> } > > > > > Or even easier: > > > for(1..5) { print; } > > > > Or _even_ easier;

Re: Counting (easy!)

2003-11-13 Thread Rob Dixon
Tore Aursand wrote: > > On Thu, 13 Nov 2003 09:05:45 -0600, Dan Muey wrote: > >> In Perl that is usually written as: > >> > >> for $count ( 1 .. 5 ) { > >> print "$count\n"; > >> } > > > Or even easier: > > for(1..5) { print; } > > Or _even_ easier; > > print 1..5; For the subscribers who d

RE: Counting (easy!)

2003-11-13 Thread Tore Aursand
On Thu, 13 Nov 2003 09:05:45 -0600, Dan Muey wrote: >> In Perl that is usually written as: >> >> for $count ( 1 .. 5 ) { >> print "$count\n"; >> } > Or even easier: > for(1..5) { print; } Or _even_ easier; print 1..5; Hah! :-) -- Tore Aursand <[EMAIL PROTECTED]> -- To unsubscribe,

Re: Counting (easy!)

2003-11-13 Thread Rob Dixon
Dan Muey wrote: > > > > > In Perl that is usually written as: > > > > for $count ( 1 .. 5 ) { > > print "$count\n"; > > } > > Or even easier: > for(1..5) { print; } > Or if you nee the newline: > for(1..5) { print "$_\n"; } If we're competing, then there's print for 1..5 ;) Rob -- To

Re: Counting (easy!) - select???

2003-11-13 Thread Rob Dixon
Kevin Old wrote: > > On Thu, 2003-11-13 at 09:33, Rob Dixon wrote: > > "Bob Showalter" <[EMAIL PROTECTED]> wrote in message > > > > > > Christiane Nerz wrote: > > > > Kevin Old wrote: > > > > ... > > > > > select undef, undef, undef, 0.25 or print $_ > > > > > for 1 .. 5; > > > > ... > > > > quit

RE: Counting (easy!)

2003-11-13 Thread Dan Muey
> In Perl that is usually written as: > > for $count ( 1 .. 5 ) { > print "$count\n"; > } Or even easier: for(1..5) { print; } Or if you nee the newline: for(1..5) { print "$_\n"; } HTH DMuey > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTE

Re: Counting (easy!) - select???

2003-11-13 Thread Kevin Old
On Thu, 2003-11-13 at 09:33, Rob Dixon wrote: > "Bob Showalter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Christiane Nerz wrote: > > > Kevin Old wrote: > > > ... > > > > select undef, undef, undef, 0.25 or print $_ > > > > for 1 .. 5; > > > ... > > > quite interesting chunk

Re: Counting (easy!) - select???

2003-11-13 Thread Rob Dixon
"Bob Showalter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Christiane Nerz wrote: > > Kevin Old wrote: > > ... > > > select undef, undef, undef, 0.25 or print $_ > > > for 1 .. 5; > > ... > > quite interesting chunk of code - but what the hell does select does > > here? Yeah -

RE: Counting (easy!) - select???

2003-11-13 Thread Bob Showalter
Christiane Nerz wrote: > Kevin Old wrote: > ... > > select undef, undef, undef, 0.25 or print $_ > > for 1 .. 5; > ... > quite interesting chunk of code - but what the hell does select does > here? Yeah - I rtfm - but didn't understand it - maybe one could > explain it in more simple words? It's

Re: Counting (easy!) - select???

2003-11-13 Thread Christiane Nerz
quite interesting chunk of code - but what the hell does select does here? Yeah - I rtfm - but didn't understand it - maybe one could explain it in more simple words? Jane Kevin Old wrote: What I wanted to do was to make each number appear in sequence like you see in a countdown (or up, in

Re: Counting (easy!)

2003-11-12 Thread John W. Krahn
Trent Rigsbee wrote: > > I'm sure this is easy but I'm a newbie. I was doing control statements (for, > while,etc.) like this: > > for ($count = 1; $count <= 5; $count++) { > print "$count\n"; > } In Perl that is usually written as: for $count ( 1 .. 5

Re: Counting (easy!)

2003-11-12 Thread Tore Aursand
On Thu, 13 Nov 2003 01:05:37 +, Trent Rigsbee wrote: > for ($count = 1; $count <= 5; $count++) { > print "$count\n"; > } This is very C'ish. In Perl we tend to: for ( 1..5 ) { print $_ . "\n"; # sleep( 1 ); } Uncomment the sleep() thing if you want Perl to sleep for 1 se

  1   2   >