[23220] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5441 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 4 14:10:43 2003

Date: Thu, 4 Sep 2003 11:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 4 Sep 2003     Volume: 10 Number: 5441

Today's topics:
    Re: Small string problem <nospam@nospam.org>
    Re: Small string problem <nospam@nospam.org>
    Re: Small string problem <postmaster@castleamber.com>
    Re: Small string problem <kraut@ukrmdotnet.cut>
    Re: Small string problem <kraut@ukrmdotnet.cut>
    Re: Small string problem <kraut@ukrmdotnet.cut>
    Re: Small string problem <shondell@cis.ohio-state.edu>
    Re: Small string problem <nospam@nospam.org>
    Re: Small string problem <shondell@cis.ohio-state.edu>
    Re: Small string problem <nospam@nospam.org>
    Re: Strange OIDs returned for IBM 3584 v2c trap variabl (John Ramsden)
    Re: Telnet proxy <jwillmore@cyberia.com>
    Re: Telnet proxy news@roaima.freeserve.co.uk
    Re: Text File Processing <postmaster@castleamber.com>
    Re: View NG with Net::NNTP <jwillmore@cyberia.com>
    Re: What ever happened to comp.lang.perl ? <tcurrey@no.no.no.i.said.no>
    Re: What ever happened to comp.lang.perl ? (Helgi Briem)
    Re: What ever happened to comp.lang.perl ? (Tad McClellan)
    Re: Why does perl think there's a regex? <no_thanks@bms.umist.ac.uk>
    Re: Why does perl think there's a regex? (Tad McClellan)
    Re: Why qr// needs /o modifier, or bug in a documentati <this.is.invalid@yahoo.com>
    Re: Why qr// needs /o modifier, or bug in a documentati <this.is.invalid@yahoo.com>
    Re: Why qr// needs /o modifier, or bug in a documentati (Anno Siegel)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 4 Sep 2003 10:52:12 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: Small string problem
Message-Id: <bj7jis$a0c3@nrn2.NRCan.gc.ca>

"PeterT" <kraut@ukrmdotnet.cut> wrote in message
news:bj7ir8$gq$1@news.ox.ac.uk...
> I'm trying to extract the numerical part and the letter part of a short
> string.
>
> i.e.
>
> $mix = "6KL"  -->  $num = "6"  and $let = "KL"
>
> I can't find a way to do it with split, or substr
>
> anybody can give me a clue? ;-)
>

Easy solution:

($num = $mix) =~ s/[a-zA-Z]//g;
($let = $mix) =~ s/[0-9]//g;

Better solution: ?

HTH

Christian




------------------------------

Date: Thu, 4 Sep 2003 11:06:19 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: Small string problem
Message-Id: <bj7kdb$a0c4@nrn2.NRCan.gc.ca>


"Christian Caron" <nospam@nospam.org> wrote in message
news:bj7jis$a0c3@nrn2.NRCan.gc.ca...

> Easy solution:
>
> ($num = $mix) =~ s/[a-zA-Z]//g;
> ($let = $mix) =~ s/[0-9]//g;
>
> Better solution: ?
>

Please note my solution will work with mixed numbers and letters ($mix =
'6K8L'). You did not mention if you needed that capacity. Also, will it
contain other characters? What to do with them?

Christian




------------------------------

Date: Thu, 04 Sep 2003 17:29:43 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Small string problem
Message-Id: <3f575acb$0$198$58c7af7e@news.kabelfoon.nl>

PeterT wrote:

> I'm trying to extract the numerical part and the letter part of a short
> string.
> 
> i.e.
> 
> $mix = "6KL"  -->  $num = "6"  and $let = "KL"
> 
> I can't find a way to do it with split, or substr
> 
> anybody can give me a clue? ;-)

my ($num, $let) = $mix =~ /^(\d+)([A-Z]+)$/;

note that this matches one or more digits followed by one or more 
letters in caps. Use i if mixed case is ok.

If it always has this form: exactly one digit followed by exactly 2 
letters you could use substr:

$num = substr($mix, 0, 1);
$let = substr($mix, 1);

IIRC

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



------------------------------

Date: Thu, 4 Sep 2003 16:41:26 +0100
From: "PeterT" <kraut@ukrmdotnet.cut>
Subject: Re: Small string problem
Message-Id: <bj7mf7$1tv$1@news.ox.ac.uk>

"Christian Caron" <nospam@nospam.org> wrote in message
news:bj7kdb$a0c4@nrn2.NRCan.gc.ca...
>
> "Christian Caron" <nospam@nospam.org> wrote in message
> news:bj7jis$a0c3@nrn2.NRCan.gc.ca...
>
> > Easy solution:
> >
> > ($num = $mix) =~ s/[a-zA-Z]//g;
> > ($let = $mix) =~ s/[0-9]//g;
> >
> > Better solution: ?
> >
>
> Please note my solution will work with mixed numbers and letters ($mix =
> '6K8L'). You did not mention if you needed that capacity. Also, will it
> contain other characters? What to do with them?

Thanks a lot already, and a good point brought to my attention.

I didn't clarify my problem enough, even to myself.

Sometimes I have one or two digits following, which I don't want with $num
but with $let . The leading number, which is not always there, needs to be
seperated from the following string, which always starts with a letter but
can have numbers at the end.

$mix = "17HD21" -->  $num = "17" , $let = "HD21"

possible examples are:

 "HN" => " ","HN"

 "7HN" => "7","HN"

 "132HD3" => "132","HD3"

-- 
petert




------------------------------

Date: Thu, 4 Sep 2003 16:43:05 +0100
From: "PeterT" <kraut@ukrmdotnet.cut>
Subject: Re: Small string problem
Message-Id: <bj7mib$1ub$1@news.ox.ac.uk>

"Lao Coon"
> "PeterT"

> > I'm trying to extract the numerical part and the letter part of a short
> > string.
> >
> > i.e.
> >
> > $mix = "6KL"  -->  $num = "6"  and $let = "KL"
> >
> > I can't find a way to do it with split, or substr
> >
> > anybody can give me a clue? ;-)
>
> Read  perldoc perlre
>
> E.g.
>
> my ($num,$let) = $mix =~ / ( \d+ ) ( [[:alpha:]]+ ) /x;

Thanks, I assume that would do it fine, but as I expanded in my reply to
Christian, I haven't looked at all permutations of my problem.

-- 
petert




------------------------------

Date: Thu, 4 Sep 2003 16:44:42 +0100
From: "PeterT" <kraut@ukrmdotnet.cut>
Subject: Re: Small string problem
Message-Id: <bj7mlb$1ut$1@news.ox.ac.uk>

"John Bokma"
> "PeterT"

> > I'm trying to extract the numerical part and the letter part of a short
> > string.
> >
> > i.e.
> >
> > $mix = "6KL"  -->  $num = "6"  and $let = "KL"
> >
> > I can't find a way to do it with split, or substr
> >
> > anybody can give me a clue? ;-)
>
> my ($num, $let) = $mix =~ /^(\d+)([A-Z]+)$/;
>
> note that this matches one or more digits followed by one or more
> letters in caps. Use i if mixed case is ok.

Ta, similar to the suggestion Lao made, though my problem expanded as
I stated earlier. ;-)

-- 
petert




------------------------------

Date: 04 Sep 2003 12:30:06 -0400
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Small string problem
Message-Id: <xcw8yp4ikj5.fsf@psi.cis.ohio-state.edu>

"PeterT" <kraut@ukrmdotnet.cut> writes:
(snip)

> Sometimes I have one or two digits following, which I don't want with $num
> but with $let . The leading number, which is not always there, needs to be
> seperated from the following string, which always starts with a letter but
> can have numbers at the end.
>
> $mix = "17HD21" -->  $num = "17" , $let = "HD21"
> 
> possible examples are:
> 
>  "HN" => " ","HN"
> 
>  "7HN" => "7","HN"
> 
>  "132HD3" => "132","HD3"

I think this seems to do what you're looking for:

my ($num, $let) = $mix =~ /^(\d+)?(.*)/;

It appears to work when $mix is any of your examples.


Ryan
-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


------------------------------

Date: Thu, 4 Sep 2003 12:43:10 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: Small string problem
Message-Id: <bj7q2u$a093@nrn2.NRCan.gc.ca>


"Ryan Shondell" <shondell@cis.ohio-state.edu> wrote in message
news:xcw8yp4ikj5.fsf@psi.cis.ohio-state.edu...
> "PeterT" <kraut@ukrmdotnet.cut> writes:
> (snip)
>
> > Sometimes I have one or two digits following, which I don't want with
$num
> > but with $let . The leading number, which is not always there, needs to
be
> > seperated from the following string, which always starts with a letter
but
> > can have numbers at the end.

>
> I think this seems to do what you're looking for:
>
> my ($num, $let) = $mix =~ /^(\d+)?(.*)/;
>
> It appears to work when $mix is any of your examples.

This would work:

($let = $mix) =~ s/^(\d+)//;
$num = $1;

It would catch any numbers (if they are at the beginning of the string) and
put them in $1 (later assigned to $num), and also remove these numbers from
$let.

Christian




------------------------------

Date: 04 Sep 2003 13:15:51 -0400
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Small string problem
Message-Id: <xcw4qzsiiew.fsf@psi.cis.ohio-state.edu>

"Christian Caron" <nospam@nospam.org> writes:

> "Ryan Shondell" <shondell@cis.ohio-state.edu> wrote in message
> news:xcw8yp4ikj5.fsf@psi.cis.ohio-state.edu...
> > "PeterT" <kraut@ukrmdotnet.cut> writes:
> > (snip)
> >
> > > Sometimes I have one or two digits following, which I don't want with
> $num
> > > but with $let . The leading number, which is not always there, needs to
> be
> > > seperated from the following string, which always starts with a letter
> but
> > > can have numbers at the end.
> 
> >
> > I think this seems to do what you're looking for:
> >
> > my ($num, $let) = $mix =~ /^(\d+)?(.*)/;
> >
> > It appears to work when $mix is any of your examples.
> 
> This would work:
> 
> ($let = $mix) =~ s/^(\d+)//;
> $num = $1;
> 
> It would catch any numbers (if they are at the beginning of the string) and
> put them in $1 (later assigned to $num), and also remove these numbers from
> $let.

First, why would you use the search and replace operator (s///), when
you really just want a match? But more importantly, this solution
could have some problems if you have previously put something in $1,
but there are no numbers in your string.

$mix = "132HD5";
($let = $mix) =~ s/^(\d+)//;
$num = $1;

# $num = 132 and $let = HD5

$mix = "YO";
($let = $mix) =~ s/^(\d+)//;
$num = $1;

# $num = 132 and $let = YO 
# whoops...


Ryan
-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


------------------------------

Date: Thu, 4 Sep 2003 13:32:56 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: Small string problem
Message-Id: <bj7t08$a094@nrn2.NRCan.gc.ca>


> First, why would you use the search and replace operator (s///), when
> you really just want a match? But more importantly, this solution
> could have some problems if you have previously put something in $1,
> but there are no numbers in your string.

Fair.

$num = $1 if ($mix =~ /^(\d+)/);
$let = $1 if ($mix =~ /^\d*(.+)/);

Then if $mix doesn't contain numbers at the beginning, it will just skip it.

Christian




------------------------------

Date: 4 Sep 2003 08:33:50 -0700
From: john_ramsden@sagitta-ps.com (John Ramsden)
Subject: Re: Strange OIDs returned for IBM 3584 v2c trap variables
Message-Id: <d27434e.0309040733.124743b4@posting.google.com>

Michael Kirkham <NOSPAM.mikek-cpsnmp@muonics.com.NOSPAM> wrote in message news:<MPG.19c06cfbdd33230e989748@news.sf.sbcglobal.net>...
>
> [...]

(replied to in news://comp.protocols.snmp, which is a more appropriate
group in which to continue this discussion (if any))

Cheers

J Ramsden


------------------------------

Date: Thu, 04 Sep 2003 15:24:13 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Telnet proxy
Message-Id: <20030904112408.734172e5.jwillmore@cyberia.com>

On Thu, 04 Sep 2003 12:03:58 GMT
"Shuttermutt" <shuttermutt@nospam.com> wrote:
> Good day all! I'm looking to write a prog that sits in between a
> telnet client and server. In other words, the telnet client of the
> user's choice would connect to my prog which would, in turn, connect
> to the telnet server. My prog would move data back and forth between
> the client and the server without manipulating it.
> 
> I've started playing with Net::Telnet and IO::Socket, but before I
> go too far, I'd like to know if anyone's run across this and/or if
> somebody might have suggestions as to how I might proceed.

Don't use telnet :)  Use SSH.  Unless you're using telnet on the
client end and then using SSH to communicate with the server.  Telnet
sends everything clear text - SSH does not.

There is Net::SSH and a few other SSH modules for Perl to aid in
development.

HTH
-- 
Jim
---
Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.
---
a real quote ...
Linus Torvalids: "They are somking crack ...."  
(http://www.eweek.com/article2/0,3959,1227150,00.asp)
---
a fortune quote ...
X-rated movies are all alike ... the only thing they leave to the
imagination is the plot. 


------------------------------

Date: Thu, 4 Sep 2003 17:18:37 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Telnet proxy
Message-Id: <t75k21-d8n.ln1@moldev.cmagroup.co.uk>

Shuttermutt <shuttermutt@nospam.com> wrote:
> Good day all! I'm looking to write a prog that sits in between a
> telnet client and server. In other words, the telnet client of the
> user's choice would connect to my prog which would, in turn, connect
> to the telnet server. My prog would move data back and forth between
> the client and the server without manipulating it.

A simple network proxy, in other words?

> I'd like to know if anyone's run across this and/or if
> somebody might have suggestions as to how I might proceed.

In the general case, google for telnet proxy. In the perl specific case,
check out the first hit on google for "perl telnet application proxy".

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


------------------------------

Date: Thu, 04 Sep 2003 17:39:04 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Text File Processing
Message-Id: <3f575cfc$0$199$58c7af7e@news.kabelfoon.nl>

Tad McClellan wrote:

> John Bokma <postmaster@castleamber.com> wrote:
> 
> 
>>>while ( $buffer = <INPUT> ) {
>>
>>IIRC defined($buffer = <INPUT>) ..
> 
> 
> 
> You do not recall correctly.

What happens if $buffer reads 0 ?

Has this been changed?


-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



------------------------------

Date: Thu, 04 Sep 2003 15:24:30 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: View NG with Net::NNTP
Message-Id: <20030904112427.589720fe.jwillmore@cyberia.com>

On 4 Sep 2003 03:50:01 -0700
tom@ztml.com (Tom) wrote:
> James Willmore <jwillmore@cyberia.com> wrote in message
> news:<20030904000048.5f4ee84e.jwillmore@cyberia.com>...
> > 
> > I'm at a loss.  I tested against leafnode as the NNTP server and
> > it worked.  According to the documentation, using the 'last'
> > method sets the marker to the last message.  
> > 
> 
> Perhaps you might have misinterpreted the documentation. The LAST
> method does not set the marker to the last message; rather it moves
> the pointer to the PREVIOUS entry.

Yes, you're right. :(

Does it work for you (the code I posted)?  Anything else in error?
Comments welcomed.

-- 
Jim
---
Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.
---
a real quote ...
Linus Torvalids: "They are somking crack ...."  
(http://www.eweek.com/article2/0,3959,1227150,00.asp)
---
a fortune quote ...
One nice thing about egotists: they don't talk about other
people. 


-- 
Jim
---
Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.
---
a real quote ...
Linus Torvalids: "They are somking crack ...."  
(http://www.eweek.com/article2/0,3959,1227150,00.asp)
---
a fortune quote ...
"A radioactive cat has eighteen half-lives." 



------------------------------

Date: Thu, 4 Sep 2003 08:01:56 -0700
From: "Trent Curry" <tcurrey@no.no.no.i.said.no>
Subject: Re: What ever happened to comp.lang.perl ?
Message-Id: <bj7kd6$feb$1@news.astound.net>

"Trent Curry" <tcurrey@no.no.no.i.said.no> wrote in message
news:bj7jai$f41$1@news.astound.net...
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:bj6qjb$984$2@mamenchi.zrz.TU-Berlin.DE...
> > Trent Curry <tcurrey@no.no.no.i.said.no> wrote in comp.lang.perl.misc:
> > > "Tad McClellan" <tadmc@augustmail.com> wrote in message
> >
> > [...]
> >
> > > > The secondary indication was your proclivity for transposing
> > > > letters and other signs of carelessness in composition.
> > > >
> > > > Those 2 heuristics where enough for me, even without the jsut.
> > >
> > > Rubbish. Complete rubbish. You are try again to miss label me with non
> >                                          ^^^^^
> >
> > Again, right?  Oh boy, this is hard to pull off, isn't it?
>
> You make no sense.
>
> http://dictionary.reference.com/search?q=again

You truely are a silly bunch if you can't see that that should of read "You
are trying again", it is of matter of fact, another semi common typo, which
I am not the first. But sure you are all pristine, perfect typists?




------------------------------

Date: Thu, 04 Sep 2003 15:29:48 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: What ever happened to comp.lang.perl ?
Message-Id: <3f57599a.270998745@News.CIS.DFN.DE>

On Thu, 4 Sep 2003 08:01:56 -0700, "Trent Curry"
<tcurrey@no.no.no.i.said.no> wrote:

>You truely are a silly bunch if you can't see that that 
>should of read "You are trying again", it is of matter 
>of fact, another semi common typo, which I am not the 
>first. But sure you are all pristine, perfect typists?

You really are a funny little man, Manny.  Every six
months or so you come here with a few new names
and fake e-mail addresses, throw a tantrum over
something silly, then get tired and go away.

What is your beef?  Why do you keep coming back
for more?  You are so bad at hiding your identity
that it is usually obvious  in your first post.


------------------------------

Date: Thu, 4 Sep 2003 11:08:26 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What ever happened to comp.lang.perl ?
Message-Id: <slrnbleorq.6ko.tadmc@magna.augustmail.com>

Trent Curry <tcurrey@no.no.no.i.said.no> wrote:
> "Trent Curry" <tcurrey@no.no.no.i.said.no> wrote in message
> news:bj7jai$f41$1@news.astound.net...
>> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
>> news:bj6qjb$984$2@mamenchi.zrz.TU-Berlin.DE...
>> > Trent Curry <tcurrey@no.no.no.i.said.no> wrote in comp.lang.perl.misc:

>> > > Rubbish. Complete rubbish. You are try again to miss label me with non
>> >                                          ^^^^^
>> >
>> > Again, right?  Oh boy, this is hard to pull off, isn't it?
>>
>> You make no sense.


You missed the point.


> You truely are a silly bunch if you can't see that that should of read "You
> are trying again"


"again" implies that I did this to you before.

I have never done this to Trent Curry before, I have done it
to one of your other names. You can't keep straight what happened
to which of your persona...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 04 Sep 2003 16:23:56 +0100
From: Chris <no_thanks@bms.umist.ac.uk>
Subject: Re: Why does perl think there's a regex?
Message-Id: <3f57624f$1@news.umist.ac.uk>

Brian Harnish wrote:
>>
>>I have a (fairly complicated) script which unmasks a string (or protein 
>>sequence, for those who are interested) where it has previously been 
>>partially masked by Xs. BTW not all lines are masked.
> 
> 
> You're supposed to make a sample script that can be ran and shows your
> problem. The script you provided doesn't run, because all it is is a
> subroutine that is never called. Usually when you try creating the smaller
> script, you figure the problem out for yourself.
> 
Sorry, it's been a hard day. You're right of course, that snippet of 
code was of no use to anyone. By paring the program down to the 
subroutine I found that the problem wasn't the subroutine afterall, doh! 
Looks like I just needed someone to tell me the obvious ;-)

Thanks,
Chris.



------------------------------

Date: Thu, 4 Sep 2003 11:02:59 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why does perl think there's a regex?
Message-Id: <slrnbleohj.6ko.tadmc@magna.augustmail.com>

Chris <no_thanks@bms.umist.ac.uk> wrote:
> Brian Harnish wrote:

>> You're supposed to make a sample script that can be ran and shows your
>> problem. 

> You're right of course

> Looks like I just needed someone to tell me the obvious ;-)


Looks like you just need to see the Posting Guidelines.  :-)  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 04 Sep 2003 19:39:39 +0400
From: ddtl <this.is.invalid@yahoo.com>
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <bflelvkj3gke806d1sib1s3sr8cp7aqgap@4ax.com>


>Your question seems to be: If qr// is supposed to be used when /o can't
>be (because the pattern changes occasionally), why is it allowed to
>recompile each time (without /o).
>
>The answer is, you are not supposed to just replace /.../o by qr/.../
>literally.  qr// allows you to compile a regex in one place, and apply
>it in another.  So you recompile (using qr//) when needed, and replace
>the /.../o with a variable that holds the value where you want to apply
>the regex.

But that does not explain why /o is needed! Yes, qr// allows you to 
compile a regex in one place, and apply it in another, because if
it wasn't possible your RE would be recompiled every time it is evaluated,
and we want to be able to compile RE only once, so we use qr//. But
if we use qr// with /o, RE would be compiled every time RE is evaluated,
which defeats the whole reason for usage of qr//o.

Maybe you could give an example when it makes difference between
using qr//o and plain quoted string, that is, between:

-----------------
my $re = qr/hello/o;
 ...
 ...
/$re/;
 ...
 ...
/$re/;
-----------------

and:

-----------------
my $re = /hello/;
 ...
 ...
/$re/;
 ...
 ...
/$re/;
-----------------

According to the manpage, whenever "/$re/;" is evaluated, RE would be
recompiled in both examples, so why would i use qr//o at all - exactly 
the same thing happens when qr//o is not used!

That is without the fact that in the first example RE actually compiled
only once (when "my $re = qr/hello/o;" is being evaluated - and there is
no difference whether you use /o or not - which means that /o does not
has *any* effect on compilation of RE, which is not what documentation says), 
while in the second example RE compiled every time it is evaluated (that is,
every time "/$re/;" executed), though according to the manpage qr//o
is supposed to be recompiled every time RE is evaluated.


>Look again at the examples, which you quoted in your first post.  They
>make pretty clear how qr// is supposed to solve the //o problem.

It is clear to me what problem qr// is supposed to solve, it is not
clear why

1) would somebody use /o modifier, 

and 

2) what is the difference between using qr// and qr//o - according 
to the messages from debugger there is none at all and /o modifier does
not has any effect (try running an examples with "use re "debug";").


ddtl.


------------------------------

Date: Thu, 04 Sep 2003 19:51:02 +0400
From: ddtl <this.is.invalid@yahoo.com>
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <uqnelv4fmorrd6bb52dcq14lf12c67jdaj@4ax.com>

>Just because A -> B, does not mean that !A -> !B.
>
>Just because the pattern is compiled once with /o, does not mean that
>the pattern is not compiled once without /o.

So what that means? Do you mean that when it is said:

"o   Compile pattern only once."

means that when you *do not* use 'o', pattern is also compiled only 
once?? If A -> B does not mean that !A -> !B (and what you want to say
is that when !A there is still B), means that A is not the only reason 
for B. If so, why do you need A at all - it is surely not because
you want B, because B exists even without A. And that is just rephrasing
of my question *why* do you need /o???

ddtl.


------------------------------

Date: 4 Sep 2003 17:58:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <bj7ufu$5ek$1@mamenchi.zrz.TU-Berlin.DE>

ddtl  <this.is.invalid@yahoo.com> wrote in comp.lang.perl.misc:
> 
> >Your question seems to be: If qr// is supposed to be used when /o can't
> >be (because the pattern changes occasionally), why is it allowed to
> >recompile each time (without /o).
> >
> >The answer is, you are not supposed to just replace /.../o by qr/.../
> >literally.  qr// allows you to compile a regex in one place, and apply
> >it in another.  So you recompile (using qr//) when needed, and replace
> >the /.../o with a variable that holds the value where you want to apply
> >the regex.
> 
> But that does not explain why /o is needed! Yes, qr// allows you to 
> compile a regex in one place, and apply it in another, because if
> it wasn't possible your RE would be recompiled every time it is evaluated,
> and we want to be able to compile RE only once, so we use qr//. But
> if we use qr// with /o, RE would be compiled every time RE is evaluated,
> which defeats the whole reason for usage of qr//o.
> 
> Maybe you could give an example when it makes difference between
> using qr//o and plain quoted string, that is, between:
> 
> -----------------
> my $re = qr/hello/o;
> ...
> ...
> /$re/;
> ...
> ...
> /$re/;
> -----------------

Well, as the documentation assures us, no re-compilation happens in this
case.  Why are you assuming the opposite?  The /o is irrelevant here,
because the statement is executed only once anyway.  To be sure that
no re-compilation *can* happen, rewrite it as

    my $re = qr/hello/;
    # ...
    # ...
    $_ =~ $re;
    # ...
    # ...
    $_ =~ $re;

Now we don't have a regex literal in the match, so no compilation happens.

> and:
> 
> -----------------
> my $re = /hello/;

You mean 'hello', not /hello/.

> ...
> ...
> /$re/;
> ...
> ...
> /$re/;
> -----------------

In fact, even this may not re-compile the regex, if $re hasn't been
changed.  The regex compiler has become rather clever about these things.
But that's beside the point.  Originally, the regex would be recompiled,
and that's one of the reasons why qr// has been invented.

It is perhaps unfortunate that the Camel doesn't show an example of a
non-literal (bare-variable) pattern match, it could make things clearer.

> According to the manpage, whenever "/$re/;" is evaluated, RE would be
> recompiled in both examples, so why would i use qr//o at all - exactly 
> the same thing happens when qr//o is not used!

According to what manpage?  Quoting "perldoc perlop":

               Since Perl may compile the pattern at the moment
               of execution of qr() operator, using qr() may have
               speed advantages in some situations, notably if
               the result of qr() is used standalone:

                   sub match {
                       my $patterns = shift;
                       my @compiled = map qr/$_/i, @$patterns;
                       grep {
                           my $success = 0;
                           foreach my $pat (@compiled) {
                               $success = 1, last if /$pat/;
                           }
                           $success;
                       } @_;
                   }

               Precompilation of the pattern into an internal
               representation at the moment of qr() avoids a need
               to recompile the pattern every time a match ...

This clearly states that a qr//-pattern, used stand-alone in m// does
*not* cause re-compilation.

The use of /o with qr// is a red herring.  It rarely makes sense.
Either the qr// is run only once, then it doesn't matter.  Or you
run over it again, but then you usually do so because you want another
regex compiled, and /o would defeat the purpose.

[snip argument about /o]

Anno


------------------------------

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5441
***************************************


home help back first fref pref prev next nref lref last post