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
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
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 =>
;
>
> 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;
>
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:
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
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
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
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
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)
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
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
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
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
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
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
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/
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
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
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:/
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
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
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;
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
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
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
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
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
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
> 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
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/
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
[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
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
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/
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/
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
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
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
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
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/
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
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
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"
"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
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
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
-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
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.
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
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
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
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
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
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-
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
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
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
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
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 @
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
> > 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
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
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
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
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
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
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
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
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
> 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
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
--- 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
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
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
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
..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
.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
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
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
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"
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 (
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
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
&
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
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 =
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
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
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
[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
< 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 =~ /^[^<>]*(?:(?:<[^<>]*>)*[^<
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
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
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.
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
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
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
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
>
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
"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 - 100 of 291 matches
Mail list logo