Re: Counting elements returned from expression

2016-10-05 Thread Chas. Owens
gt; > > use strict; > > use Benchmark; > > use warnings; > > > > my $max_hats = 100; > > > > sub get_clown_hat { > > return (0 .. $max_hats); > > } > > > > # here, scalar context is causing the .. operator > > # to b

Re: Counting elements returned from expression

2016-10-05 Thread khalil zakaria Zemmoura
ax_hats); >> > } >> > >> > # here, scalar context is causing the .. operator >> > # to be the flip flop operator instead of the >> > # range operator, so we get 1E0 instead of >> > # 100 (the last item) or 101 (the count) >> > # when not compared to

Re: Counting elements returned from expression

2016-10-04 Thread Chas. Owens
ompares against $. (the line number of the last > > # line read from the currently selected file handle) > > my $flip_flop_result = get_clown_hat; > > > > print "wrong result: $flip_flop_result\n"; > > > > my %subs = ( > > array =>

Re: Counting elements returned from expression

2016-10-04 Thread zakaria
; > > print "wrong result: $flip_flop_result\n"; > > my %subs = ( > array => sub { > my @a = get_clown_hat; > return scalar @a; > }, > empty => sub { > my $count = () = get_clown_hat; >

Re: Counting elements returned from expression

2016-10-04 Thread Chas. Owens
unt; }, ); for my $sub (keys %subs) { print "$sub: ", $subs{$sub}(), "\n"; } for my $n (1_000, 10_000, 100_000) { $max_hats = $n; print "\n$n items\n\n"; Benchmark::cmpthese -2, \%subs; } Avoiding copying the data is about twice as fast for counting items:

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

Counting elements returned from expression

2016-10-03 Thread khalil zakaria Zemmoura
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 that the assignment to the empty list throws away all of th

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

Counting Word Occurances

2011-07-15 Thread Matt
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) orange (2) green (1) The contents

Would appreciate some help with a bit more counting problems

2009-04-21 Thread Brian
ot sure if resolving that will clear up other issues in my counting, but as you can see the page doesn't look too healthy. What I am attempting to do at this point is create 6 rows / 7 columns, ergo, count 42. I have forced $mystart to be a negative number. My aim... Print a non-value for $myst

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

counting number of multiple occurances in a row

2008-08-15 Thread Pat Rice
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 count(*) from commitCurrent where company =(select distinct company from commitCur

Re: problem with the script in counting

2008-04-05 Thread ken Foskey
On Sun, 2008-04-06 at 05:39 +0530, pradeep reddy wrote: > Can this impletemented in shell script alsso? Why do you ask this in a perl list? look at `uniq -c`. -- Ken Foskey FOSS developer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http:/

Re: problem with the script in counting

2008-04-05 Thread pradeep reddy
Hi, Thanks for the reply. Can this impletemented in shell script alsso? - Original Message From: Gunnar Hjalmarsson <[EMAIL PROTECTED]> To: beginners@perl.org Sent: Saturday, 5 April, 2008 3:01:41 PM Subject: Re: problem with the script in counting pradeep reddy wrote: > I

Re: problem with the script in counting

2008-04-05 Thread John W. Krahn
pradeep reddy wrote: Hi, Hello, I have a script which greps for a word in a file contains records. I grabbed a particular column & sent the colomn values to a file. I need to find each column value, the times it appeared in the file. My script is: grep sceneority | cut -f 6

Re: problem with the script in counting

2008-04-05 Thread Gunnar Hjalmarsson
pradeep reddy wrote: I am stuck at how to find the occurance of column values in "swi" file. The file has following column values: 123 324 123 123 435 435 The output should be 123 is 3 times 324 is 1 time 435 is 2 times Use a hash. open my $fh, '<', 'swi' or die $!; my %cnt;

problem with the script in counting

2008-04-05 Thread pradeep reddy
Hi, I have a script which greps for a word in a file contains records.. I grabbed a particular column & sent the colomn values to a file. I need to find each column value, the times it appeared in the file. My script is: grep sceneority | cut -f 6 >> swi I am stuck at how to fi

problem with the script in counting

2008-04-05 Thread pradeep reddy
Hi, I have a script which greps for a word in a file contains records.. I grabbed a particular column & sent the colomn values to a file. I need to find each column value, the times it appeared in the file. My script is: grep sceneority | cut -f 6 >> swi I am stuck at how to fi

problem with the script in counting

2008-04-05 Thread pradeep reddy
Hi, I have a script which greps for a word in a file contains records. I grabbed a particular column & sent the colomn values to a file. I need to find each column value, the times it appeared in the file. My script is: grep sceneority | cut -f 6 >> swi I am stuck at how to fin

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

Counting keys in an array of hashes?

2008-02-20 Thread jamesdon
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 hostmacport 13 switch-1

Re: Question abount counting the total number of lines and put to an variable?

2007-12-01 Thread Marco
Hi Patmarbidon, Thanks for your help. you do help me a lot...thanks... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Question abount counting the total number of lines and put to an variable?

2007-11-30 Thread Marco
Hi Ruud, your script is fantastic..this is the data I really need. Thank you... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Question abount counting the total number of lines and put to an variable?

2007-11-30 Thread patmarbidon
Try this : my $number = 0 ; open (MYFILE, '123.txt'); while () { if ($_ =~ /^User:/) { ++$number ; print $_; } } close (MYFILE); print "Number:$number\n" ; Marco a écrit : Hi.. I have a question about how to count the total of line that shows on the screen. Here below is my code

Re: Question abount counting the total number of lines and put to an variable?

2007-11-30 Thread Marco
Here blow is the code I did.. open (MYFILE, '123.txt'); while () { if ($_ =~ /^User:/){ $count = $_+1; print "$count\n"; } } close (MYFILE); But it shows the result below, 1 1 1 How can I add those together become 3 ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional com

Re: Question abount counting the total number of lines and put to an variable?

2007-11-29 Thread Dr.Ruud
Marco schreef: > I have a question about how to count the total of line that shows on > the screen. Here below is my code.. > > open (MYFILE, '123.txt'); > while () { > if ($_ =~ /^User:/) { > print $_; > } > } > close (MYFILE); > > then it will shows the following on the screen, > > Us

Re: Question abount counting the total number of lines and put to an variable?

2007-11-29 Thread Tom Phoenix
On 11/29/07, Marco <[EMAIL PROTECTED]> wrote: > The code will show 2 line liek below, how can I get the a number "2" > and save to the variable? thanks. > > User: ABC > User: DEF It sounds as if you want to count each print operation. You can do that if you set a variable to zero before you begi

Re: Question abount counting the total number of lines and put to an variable?

2007-11-29 Thread Marco
Hi.. Thank you...But how can I do that ? The code will show 2 line liek below, how can I get the a number "2" and save to the variable? thanks. User: ABC User: DEF -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Question abount counting the total number of lines and put to an variable?

2007-11-29 Thread Tom Phoenix
On 11/29/07, Marco <[EMAIL PROTECTED]> wrote: > Is there any way that I can get the total of lines that show on the > screen and put to a variable? Yes; you can keep a running count as you print the lines. Each time you print a line, you add one to the count of lines. Is that all you needed? Chee

Question abount counting the total number of lines and put to an variable?

2007-11-29 Thread Marco
Hi.. I have a question about how to count the total of line that shows on the screen. Here below is my code.. open (MYFILE, '123.txt'); while () { if ($_ =~ /^User:/) { print $_; } } close (MYFILE); then it will shows the following on the screen, User: ABC User: DEF Is there any way th

Re: word counting

2006-09-05 Thread Mumia W.
On 09/05/2006 03:47 AM, Andrew Kennard wrote: Hi all I'm looking for a good word counting module/sub routine I've found this so far http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=562&lngWId=6 but it counts things like the "Item1,Item2,Item3"

Re: word counting

2006-09-05 Thread Dr.Ruud
"Andrew Kennard" schreef: > I need a word counter to count the number of words in a scientific > paper. I know it wont be 100% accurate due to formulas etc echo 'I,Item1,Item2,Item3,a' | sed 's/[^A-Za-z0-9]/ /g' | wc If you want to count only strings with a specific minimum length, use `st

word counting

2006-09-05 Thread Andrew Kennard
Hi all I'm looking for a good word counting module/sub routine I've found this so far http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=562&lngWId=6 but it counts things like the "Item1,Item2,Item3" as one word I've had a search on CPAN but that

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

Counting & arrays

2006-05-22 Thread Michael Gargiullo
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 'rules' need to be dynamic so if a rule is added, it's au

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

Counting specific elements in a XML object

2006-03-30 Thread Dave Adams
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 the number of employees or in other words, the number occurences of ""? I guess

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, $v

RE: counting scalar array elements question

2006-03-08 Thread Timothy Johnson
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 to easily count the number of elements in the array? I've tried creating a new array and pushing the original

counting scalar array elements question

2006-03-08 Thread Graeme McLaren
Hi all, I have an array question: 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 that creates an array of arrays. Basically I have: my

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

Counting Multiple lines of data with a unique column of information

2005-03-08 Thread Wilson, Josh --- Systems Analyst --- GO
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. The problem is that one shipment might have more

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

Counting occurences of a char in a line

2005-01-17 Thread Tor Hildrum
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 will be reused and probably m

Re: Extracting Directories and Sub Directories and Counting

2004-11-03 Thread Ron Smith
--- Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > Ron Smith wrote: > > If I wanted to add more fields to my output, which > construct would I > > use to create more fields; something like the > following? > > > > basenamecountextensionsize > > > > ...maybe 'HoH', or just expand on

Re: Extracting Directories and Sub Directories and Counting

2004-11-02 Thread Gunnar Hjalmarsson
Ron Smith wrote: Gunnar Hjalmarsson wrote: You multi-posted basically the same question to comp.lang.perl.misc (see below). Any comments on that, Ron? Pardon me Gunnar, etal, I'm new and thought that the 'comp.lang.perl.misc' post was entirely separate from '[EMAIL PROTECTED]', reaching an entirely

Re: Extracting Directories and Sub Directories and Counting

2004-11-02 Thread Gunnar Hjalmarsson
Ron Smith wrote: Gunnar Hjalmarsson wrote: You multi-posted basically the same question to comp.lang.perl.misc (see below). Any comments on that, Ron? Pardon me Gunnar, etal, I'm new and thought that the 'comp.lang.perl.misc' post was entirely separate from '[EMAIL PROTECTED]', reaching an entirely

Re: Extracting Directories and Sub Directories and Counting

2004-11-02 Thread Chris Devers
On Tue, 2 Nov 2004, Ron Smith wrote: > I'm new and thought that the 'comp.lang.perl.misc' post was entirely > separate from '[EMAIL PROTECTED]', reaching an entirely different > audience. I eanestly appologize to everyone on both lists. It's a separate list, but a lot of the same people read bo

Re: Extracting Directories and Sub Directories and Counting

2004-11-02 Thread Ron Smith
..maybe 'HoH', or just expand on the 'HoA? You multi-posted basically the same question to comp.lang.perl.misc (see below). Any comments on that, Ron? ---- Original Message Subject: Re: Extracting Directories and Sub Directories and Counting Date: Tue, 02 Nov 2004 13:40:2

Re: Extracting Directories and Sub Directories and Counting

2004-11-02 Thread Gunnar Hjalmarsson
.perl.misc (see below). Any comments on that, Ron? Original Message Subject: Re: Extracting Directories and Sub Directories and Counting Date: Tue, 02 Nov 2004 13:40:21 +0100 From: Gunnar Hjalmarsson <[EMAIL PROTECTED]> Newsgroups: comp.lang.perl.misc References: <[EMA

Re: Extracting Directories and Sub Directories and Counting

2004-11-02 Thread Gunnar Hjalmarsson
Ron Smith wrote: If I wanted to add more fields to my output, which construct would I use to create more fields; something like the following? basenamecountextensionsize ...maybe 'HoH', or just expand on the 'HoA? I suppose that you are not really talking about the output now, but rathe

Re: Extracting Directories and Sub Directories and Counting

2004-11-01 Thread Ron Smith
Hey Gunnar, and list, ---snip print "\n"; my %HoA; for ( `dir /b/s` ) { push @{ $HoA{$1} }, $2 if /(.+)\\(\w+)\.\d+\.\w+$/; } for my $dir ( sort keys %HoA ) { print join ( "\n", $dir ), "\n\n"; my @basenames = @{ $HoA{$d

Re: Extracting Directories and Sub Directories and Counting

2004-10-29 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote: for my $dir ( sort keys %HoA ) { print "$dir\n"; my @basenames = @{ $HoA{$dir} }; my %count; for my $frames ( @basenames ) { $count{$frames} += 1; } for ( sort keys %count ) { printf "%30s\t%04d\n"

Re: Extracting Directories and Sub Directories and Counting

2004-10-29 Thread Gunnar Hjalmarsson
Ron Smith wrote: The following is the re-worked script: snip- #!/usr/bin/perl -w use strict; my %HoA; for ( `dir /b/s` ) { push @{ $HoA{$1} }, $2 if /(.+)\\(\w+)\.(\d+)\.(\w+)$/; } The two last pairs of parentheses are redundant. my %count; for my $dir (

Re: Extracting Directories and Sub Directories and Counting

2004-10-29 Thread Ron Smith
27;m attempting to play around with this new tool > to get it to do > > different things, but I'm running into another > problem. I can't > > seem to pull the elements back out from the arrays > properly. I'm > > tring to count the basenames now. I get

Re: Extracting Directories and Sub Directories and Counting// LÖSCHEN von WALLBANGER@t-online.de als" PERLER "!!!!!

2004-10-28 Thread sonja
r schon TOD !! mit lieben Gruß Sonjaseine Frau! - Original Message - From: "Gunnar Hjalmarsson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, October 29, 2004 1:19 AM Subject: Re: Extracting Directories and Sub Directories and Counting &

Re: Extracting Directories and Sub Directories and Counting

2004-10-28 Thread Gunnar Hjalmarsson
em. I can't seem to pull the elements back out from the arrays properly. I'm tring to count the basenames now. I get what looks like memory addresses instead. I think these are the references to the actual arrays that you were eluding to. Sounds plausible. :) I was using parts of the script

RE: Recursively counting a matching pattern on a single line.

2004-10-28 Thread Dan Jones
On Wed, 2004-10-27 at 20:07, S.A. Birl wrote: > On Oct 27, [EMAIL PROTECTED] ([EMAIL PROTECTED]: > > Brian: > Brian: If you want to make sure they are alternating like <><><> etc... I would do > Brian: this: > Brian: > Brian: $_ = $line; > Brian: > Brian: @syms = m/[<>]/g; > Brian: $string =

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote: print "Oops!\n" unless $string =~ /^[^<>]*(?:(?:<[^<>]*>)*[^<>]*)*$/; Hmm.. That got unnecessarily complicated. Make it: print "Oops!\n" unless $string =~ /^[^<>]*(?:<[^<>]*>[^<>]*)*$/; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubs

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread Zeus Odin
What I think you are actually saying is that you want to know when you encounter two <'s or two >'s in a row You then want the program to alert and exit. The following accomplishes this. Apologies if I misunderstood. -ZO - #!/usr/bin/perl use warnings; use strict; my $count; my $text = 'http

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread John W. Krahn
S.A. Birl wrote: On Oct 27, [EMAIL PROTECTED] ([EMAIL PROTECTED]: Brian: The regular expression: Brian: Brian: m/^<(><)*>$/ Brian: Brian: will ensure that it starts with < and ends with > and anything in between Brian: will be "><" which I think should do the trick. That logic is pretty hairy B

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Assign each line to the $_ variable and try this to get the number of instances of < and > The match operator works on $_ by default. If you match on < or > globally and assign it to an array like so: @rights = m/\/g; See the FAQ for a more efficient way to do this. perldoc

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread Gunnar Hjalmarsson
< and 3 > and the pattern is basically <><><> and not <<>> or >><, etc. Assuming that you are actually not interested in *counting* them, this is one approach: print "Oops!\n" unless $string =~ /^[^<>]*(?:(?:<[^<>]*>)*[^<

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread brian . barto
Wouldnt m/[<>]/g literally match <> and not ? Why wouldnt it be m/[<.+>]/g ? Thanks Birl --- Someone correct me if I'm wrong but putting characters inside brackets [] defines a character class. Or a group of characters you want to match on, not necessarily in that order. For instan

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread S.A. Birl
On Oct 27, [EMAIL PROTECTED] ([EMAIL PROTECTED]: Brian: Brian: If you want to make sure they are alternating like <><><> etc... I would do Brian: this: Brian: Brian: $_ = $line; Brian: Brian: @syms = m/[<>]/g; Brian: $string = join("", @syms); Brian: if ($strings !~ m/^<(><)*>$/) Brian: { B

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread brian . barto
Correction: "$strings" in the if statement should be "$string" -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 27, 2004 4:04 PM To: [EMAIL PROTECTED] Subject: RE: Recursively counting a matching pattern on a single line.

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread brian . barto
Great! That works. But I was looking to get a little trickier with it. If you want to make sure they are alternating like <><><> etc... I would do this: $_ = $line; @syms = m/[<>]/g; $string = join("", @syms); if ($strings !~ m/^<(><)*>$/) { ## Scream here! } The re

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread S.A. Birl
On Oct 27, [EMAIL PROTECTED] ([EMAIL PROTECTED]: Brian: Assign each line to the $_ variable and try this to get the number of Brian: instances of < and > Brian: Brian: The match operator works on $_ by default. If you match on < or > globally Brian: and assign it to an array like so: Brian: Br

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread brian . barto
t: Wednesday, October 27, 2004 3:23 PM To: [EMAIL PROTECTED] Subject: Recursively counting a matching pattern on a single line. Given a bookmark: http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html"; ADD_DATE="897592292" LAST_VISIT="982769648" LAST_MODIFIED="982769648

RE: Recursively counting a matching pattern on a single line.

2004-10-27 Thread Bob Showalter
S.A. Birl wrote: > Given a bookmark: > > HREF="http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html"; > ADD_DATE="897592292" LAST_VISIT="982769648" LAST_MODIFIED="982769648" > ID="rdf:#$rsy5Z">PERL FAQ > > > Wondering if it's possible to have 2 counters that would keep track > of the >

Recursively counting a matching pattern on a single line.

2004-10-27 Thread S.A. Birl
Given a bookmark: http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html"; ADD_DATE="897592292" LAST_VISIT="982769648" LAST_MODIFIED="982769648" ID="rdf:#$rsy5Z">PERL FAQ Wondering if it's possible to have 2 counters that would keep track of the number of < and > encountered. Im looking to

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

  1   2   3   >