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
S.A. Birl wrote:
Wondering if it's possible to have 2 counters that would keep track
of the number of < and > encountered.
Im looking to see if there's a balance of < and >, and scream as soon
as there isnt a balance.
So given the above bookmark, I know that there's 3 < and 3 > and
the pattern is
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
14 matches
Mail list logo