[23212] in Perl-Users-Digest
Perl-Users Digest, Issue: 5433 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 3 14:07:20 2003
Date: Wed, 3 Sep 2003 11:05:12 -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 Wed, 3 Sep 2003 Volume: 10 Number: 5433
Today's topics:
Re: [newbie] how to get just the first value of a hash? <nospam@please.com>
Re: [newbie] how to get just the first value of a hash? <guest1@deskpro192.internal.sanger.ac.uk>
Re: [newbie] how to get just the first value of a hash? <uri@stemsystems.com>
Re: [newbie] how to get just the first value of a hash? <noreply@gunnar.cc>
Re: [newbie] how to get just the first value of a hash? <postmaster@castleamber.com>
Re: [newbie] how to get just the first value of a hash? <usenet@expires12.2003.tinita.de>
Re: [newbie] how to get just the first value of a hash? <bharnish@technologist.com>
Re: [newbie] how to get just the first value of a hash? <noreply@gunnar.cc>
Re: [newbie] how to get just the first value of a hash? <nospam@please.com>
Modify during a while statement mechanicscart@hotmail.com
Re: Modify during a while statement <mazdack@list.ru>
Re: newbie question. how to assign an array to a hash t (Tad McClellan)
perl CGI related: form post failure (Wenjie)
Re: Redirecting via LWP <mbudash@sonic.net>
Re: View NG with Net::NNTP (Randal L. Schwartz)
Re: View NG with Net::NNTP <jwillmore@cyberia.com>
Re: View NG with Net::NNTP (Randal L. Schwartz)
Re: Why qr// needs /o modifier, or bug in a documentati <pinyaj@rpi.edu>
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 (Sam Holden)
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: Wed, 03 Sep 2003 15:13:54 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <Syn5b.17429$t%2.799836@phobos.telenet-ops.be>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Gunter Schelfhout wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> On Wed, 03 Sep 2003 14:14:26 +0000, Gunter Schelfhout wrote:
>
>> Mina Naguib wrote:
> [snip...]
>>> -----BEGIN xxx SIGNATURE-----
>>> Version: GnuPG v1.2.1 (GNU/Linux)
>>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>>
>>> iD8DBQE/VfVieS99pGMif6wRAlP1AJ9hD06J8DtMctfiJWNjpD1HlJt9xwCgyFGx
>>> jmMWbG/iGJMYyI/BXxfkkLw=
>>> =+nrC
>>> -----END PGP SIGNATURE-----
>>
>> Is this PGP-sig really nescessary on usenet? It's ugly like hell. And a
>> lot of work if you want to remove it on reply.
blabla.
> Yes, it is nescessary, it's the only way of telling who really sent the
> message. And, the signatures are roughly the acceptable size for usenet
> .sig's.
blabla
> - Brian Harnish (bharnish@technologist.com)
> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.2.2 (GNU/Linux)
>
> iD8DBQE/Vf9RiK/rA3tCpFYRAnLaAJ9v8G2m44TI61KxVoCjmLwW6AOsugCgmzSv
> BDUAWRPfYJqdoTUfOVdhEw0=
> =oNJC
> -----END PGP SIGNATURE-----
I know where it is used for. IMHO, it doesn't make sense to use it on
usenet.
Look at the mess after only a couple of messages.
- --
Blood, sweat & tears
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE/VgUrtGqwJj9zNs4RAtMEAJ4mgu8utdi1uG7bFQKw8GdhfnekQACdGwfT
T4DXvc3eAxdt89zOXZlK6lc=
=yj94
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 3 Sep 2003 16:25:30 +0100
From: Guest1 <guest1@deskpro192.internal.sanger.ac.uk>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <Pine.LNX.4.44.0309031618470.7152-100000@deskpro192.internal.sanger.ac.uk>
I have a hash of arrays, and I would like to get the length of any of
these arrays. I said first instead to say any of them (because all the
arrays have the same length), More clear my question now?
On the future I will try to be more clear from the begining.
Thanks
P
On Wed, 3 Sep 2003, Brian Harnish wrote:
> On Wed, 03 Sep 2003 14:52:22 +0100, Guest1 wrote:
>
> >
> > Thanks in advance
> > Pedro
>
> define first
>
> - Brian
>
------------------------------
Date: Wed, 03 Sep 2003 15:43:57 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <x7d6ehswqq.fsf@mail.sysarch.com>
>>>>> "G" == Guest1 <guest1@deskpro192.internal.sanger.ac.uk> writes:
<don't top post>
G> I have a hash of arrays, and I would like to get the length of any of
G> these arrays. I said first instead to say any of them (because all the
G> arrays have the same length), More clear my question now?
perldoc -f each
G> On the future I will try to be more clear from the begining.
that is always helpful
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Wed, 03 Sep 2003 17:51:39 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj52rb$f93qj$1@ID-184292.news.uni-berlin.de>
Guest1 wrote:
> I have a hash of arrays, and I would like to get the length of any
> of these arrays. I said first instead to say any of them (because
> all the arrays have the same length), More clear my question now?
Suppose so. Assuming that you by "length" mean the number of elements,
this is one way:
print scalar @{$myhash{(keys %myhash)[0]}};
> On the future I will try to be more clear from the begining.
Good. Also, in the future, please don't top post.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 03 Sep 2003 17:59:33 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <3f561048$0$204$58c7af7e@news.kabelfoon.nl>
Bigus wrote:
> There is no "first value of a hash". That is, a hash just consists of keys
> and values. If you want the lowest value in a hash, assuming the values are
> all numbers of course, then you could do it something like this:
>
> @keys = sort {$hash{$a} <=> $hash{$b}} keys %hash;
> print $hash{$keys[0]};
technically this is O(n log n) while just looping over all keys and
finding the lowest is O(n).
my @keys = keys %hash;
my $min = $hash{shift @keys}; # assign "first" as minimum
foreach my $key (@keys) {
$min = $hash{$key} if $hash{$key} < $min; # try to find better one
}
assuming %hash has values :-)
HTH
--
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: 3 Sep 2003 16:12:35 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj53tj$fh15v$1@ID-24002.news.uni-berlin.de>
Gunnar Hjalmarsson wrote:
> Guest1 wrote:
>> I have a hash of arrays, and I would like to get the length of any
>> of these arrays. I said first instead to say any of them (because
>> all the arrays have the same length), More clear my question now?
> Suppose so. Assuming that you by "length" mean the number of elements,
> this is one way:
> print scalar @{$myhash{(keys %myhash)[0]}};
or maybe one of these:
print scalar @{ (values %myhash)[0] };
print $#{ (values %myhash)[0] }+1;
print $#{ (each %myhash)[1] }+1;
print @{ (%myhash)[1] }+0;
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -
------------------------------
Date: Wed, 03 Sep 2003 16:16:27 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <pan.2003.09.03.16.16.45.357371@technologist.com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On Wed, 03 Sep 2003 15:13:54 +0000, Gunter Schelfhout wrote:
> Gunter Schelfhout wrote:
>
>> On Wed, 03 Sep 2003 14:14:26 +0000, Gunter Schelfhout wrote:
>>
>>> Mina Naguib wrote:
>> [snip...]
>>>
>>> Is this PGP-sig really nescessary on usenet? It's ugly like hell. And a
>>> lot of work if you want to remove it on reply.
>
> blabla.
>
>> Yes, it is nescessary, it's the only way of telling who really sent the
>> message. And, the signatures are roughly the acceptable size for usenet
>> .sig's.
>
> blabla
>
>> - Brian Harnish (bharnish@technologist.com)
>
> I know where it is used for. IMHO, it doesn't make sense to use it on
> usenet.
> Look at the mess after only a couple of messages.
> - --
> Blood, sweat & tears
Well, we're all entitled to oppinions. I don't think it's difficult to
jump to the end of the message and delete a few lines when replying. And
the only reason it got so ugly in our quoting is because we quoted the
sigs, because thats what we were discussing. Ususally, you strip out any
text that isn't relevant to the conversation (such as pgpsigs). If someone
wants to verify that the quoted message came from the right person, they
can check the original message.
BTW: My news reader doesn't support pgp signing, so I copy/paste sign.
Takes an extra couple of seconds, but I find it worthy, so that people
know w/o a doubt that a message came from me.
- Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/VhPRiK/rA3tCpFYRAte+AKCX4RXVkmbuKExeYURUeKxMnAdntACfWfMm
bcxJnKy9QK4cRKQnUE86KeM=
=E618
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 03 Sep 2003 18:23:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <bj54nb$f9te5$1@ID-184292.news.uni-berlin.de>
Tina Mueller wrote:
> Gunnar Hjalmarsson wrote:
>>Assuming that you by "length" mean the number of elements,
>>this is one way:
>>
>> print scalar @{$myhash{(keys %myhash)[0]}};
>
> or maybe one of these:
> print scalar @{ (values %myhash)[0] };
> print $#{ (values %myhash)[0] }+1;
> print $#{ (each %myhash)[1] }+1;
> print @{ (%myhash)[1] }+0;
Yes. TMTOWTDI. But I have to admit that all your suggestions are more
straight-forward than mine. I forgot about the values function. And
each... Oh, well. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 03 Sep 2003 17:47:40 GMT
From: Gunter Schelfhout <nospam@please.com>
Subject: Re: [newbie] how to get just the first value of a hash??
Message-Id: <0Pp5b.17750$MU1.650299@phobos.telenet-ops.be>
Brian Harnish wrote:
>
> Well, we're all entitled to oppinions.
Certainly.
> I don't think it's difficult to
> jump to the end of the message and delete a few lines when replying.
And on top.
> And
> the only reason it got so ugly in our quoting is because we quoted the
> sigs, because thats what we were discussing. Ususally, you strip out any
> text that isn't relevant to the conversation (such as pgpsigs). If someone
> wants to verify that the quoted message came from the right person, they
> can check the original message.
OK. I don't have your public key. How should I check it? Via a key-server?
You used my name, but not my headers. These should be enough to check the
postings, no?
> BTW: My news reader doesn't support pgp signing, so I copy/paste sign.
> Takes an extra couple of seconds, but I find it worthy, so that people
> know w/o a doubt that a message came from me.
>
Maybe you can put it after '-- ', so it will be cut by the readers which has
the option set to cut signatures?
Anyway, enough off-topic postings.
--
Blood, sweat & tears
------------------------------
Date: 3 Sep 2003 08:33:16 -0700
From: mechanicscart@hotmail.com
Subject: Modify during a while statement
Message-Id: <68f77a66.0309030733.1c7620d5@posting.google.com>
Hey all
Trying to modify a html file with a while statement and can't
see to get it to work just right. Here's what I'm trying to do
$change .= s/\%%$option_d_name%%/ ${$option_v_name}/g,;
# $changes will be multi lines
open (FILE, "<./$location") ||
&errorcode(__FILE__, __LINE__, "./
$location", "$!", "print", "FILE OPEN ERROR", "0");
while (<FILE>)
{
$changes;
s/\%%$option_d_name%%/ ${$option_v_name}/g;
#why does s/\%%$option_d_name%%/ ${$option_v_name}/g; work,
# but $changes does not?
$database_fields[$db{"options"}] .= $_;
}
close (FILE);
}
Thanks
------------------------------
Date: Wed, 3 Sep 2003 20:22:00 +0400
From: "Mazdack" <mazdack@list.ru>
Subject: Re: Modify during a while statement
Message-Id: <bj54d2$i12$1@news.rol.ru>
<mechanicscart@hotmail.com> ???????/???????? ? ???????? ?????????:
news:68f77a66.0309030733.1c7620d5@posting.google.com...
> Hey all
> Trying to modify a html file with a while statement and can't
> see to get it to work just right. Here's what I'm trying to do
>
>
> $change .= s/\%%$option_d_name%%/ ${$option_v_name}/g,;
> # $changes will be multi lines
> open (FILE, "<./$location") ||
> &errorcode(__FILE__, __LINE__, "./
> $location", "$!", "print", "FILE OPEN ERROR", "0");
>
> while (<FILE>)
> {
> $changes;
> s/\%%$option_d_name%%/ ${$option_v_name}/g;
> #why does s/\%%$option_d_name%%/ ${$option_v_name}/g; work,
> # but $changes does not?
>
> $database_fields[$db{"options"}] .= $_;
> }
> close (FILE);
> }
>
> Thanks
$changes=~s/\%%$option_d_name%%/${$option_v_name}/g;
------------------------------
Date: Wed, 3 Sep 2003 10:58:53 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie question. how to assign an array to a hash table?
Message-Id: <slrnblc3tt.45l.tadmc@magna.augustmail.com>
Guest1 <guest1@deskpro192.internal.sanger.ac.uk> wrote:
> my @values = split(' ',$hap{$key});
> $splitted_hap{$key} = \@values;
You do not need the @values temporary array.
If you use an anonymous array you can replace those 2 lines with this:
$splitted_hap{$key} = [ split(' ',$hap{$key}) ];
[ snip TOFU. Please quote your followups properly ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 3 Sep 2003 10:26:16 -0700
From: gokkog@yahoo.com (Wenjie)
Subject: perl CGI related: form post failure
Message-Id: <d2804eb3.0309030926.5137bb32@posting.google.com>
Hello,
I am not sure it is a good question for the group(s):
I encountered a problem for my website form (method="post"):
people have a different ISP encountered text posting
problems when their text size is more than handreds of
characters. The phenomena is that the post keeps 'connecting
or whatever', then the browser reports page unavailable
errors.
I think it could be that name server of my ISP is slow?
Or my web server is slow? What could be tuned here to
resolve the problem?
Thanks for your help,
Wenjie
------------------------------
Date: Wed, 03 Sep 2003 15:21:01 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Redirecting via LWP
Message-Id: <mbudash-A9E3A6.08210103092003@typhoon.sonic.net>
In article <bj47pd$k5o@newton.cc.rl.ac.uk>,
"Bigus" <someone@somewhere.com> wrote:
> "Michael Budash" <mbudash@sonic.net> wrote in message
> news:mbudash-1164EB.23580201092003@typhoon.sonic.net...
>
> > look into the <base href="..."> html tag, then do this:
> >
> > $response = $resp->content;
> > $response =~
> > s{(</head>)}{<base href="http://mydomain.com/files/$listname/">$1}i;
> >
> > it's what i do and it works like a champ.
>
> Thanks.. this does work and is what I've employed for now, although it is a
> browser dependant solution. Having said that, I checked a compatibility
> chart and it seems <base href..> is supported by pretty much every browser
> since the dawn of time :)
glad it works for you. (btw - i wouldn't've suggested it as a solution
unless i was pretty darn sure it would work with most or all modern
browsers...)
--
Michael Budash
------------------------------
Date: Wed, 03 Sep 2003 16:17:46 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: View NG with Net::NNTP
Message-Id: <49dabebf52a6c612c15ab16f500663ed@news.teranews.com>
>>>>> "Mike" == Mike <csdude@hotmail.com> writes:
Mike> I have a client that would really benefit from allowing his visitors
Mike> to read a specific newsgroup on his site. I've been looking through
Mike> some modules, and even though a lot of the standard modules mention
Mike> this, I haven't been able to find any actual references so I think I
Mike> might be misunderstanding the wording in the modules.
Consider the code given in my column as a starting point:
<http://www.stonehenge.com/merlyn/WebTechniques/col62.html>
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 03 Sep 2003 17:20:29 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: View NG with Net::NNTP
Message-Id: <20030903132024.3cf6a667.jwillmore@cyberia.com>
On Wed, 03 Sep 2003 05:28:14 GMT
James Willmore <jwillmore@cyberia.com> wrote:
> On 2 Sep 2003 21:39:39 -0700
> csdude@hotmail.com (Mike) wrote:
> ==untested==
> #!/usr/bin/perl -w
>
> use strict;
> use Net::NNTP;
>
> my($SERVER, $nntp, $articles, $first, $last, $ng_name);
>
> $SERVER = 'localhost';
> $nntp = Net::NNTP->new($SERVER, Debug=>0)
> or die "Can't connect to server $SERVER: $!\n";
>
> ($articles,$first,$last,$ng_name) =
> $nntp->group('comp.lang.perl.misc');
> printf("%s: %5d articles (%-5d to
> %-5d)\n",$ng_name,$articles,$first,$last);
>
> while(my $fh = $nntp->articlefh){
> while(<$fh>){
> print;
> }
> $nntp->next;
> }
>
> $nntp->quit;
> ==untested==
>
> This will print each message in the newsgrop indicated. It takes
> some re-reading of the Net::NNTP documentation to get a full
> understanding of it.
I should follow my own advise :)
The above code will cause an infinite loop - opps! The below code
(tested and with comments) works :)
#!/usr/bin/perl -w
use strict;
use Net::NNTP;
#set lexical variables
my($SERVER, $nntp, $articles, $first, $last, $ng_name);
#define NNTP server
$SERVER = 'localhost';
#declare new Net::NNTP object - or die with a connection failure
#message
$nntp = Net::NNTP->new($SERVER, Debug=>0)
or die "Can't connect to server $SERVER: $!\n";
#define what newsgroup to use -
#get the newsgroup name, amount of article, the first article number
#and last article number
($articles,$first,$last,$ng_name) =
$nntp->group('comp.lang.perl.misc');
#print the information out
printf("%s: %5d articles (%-5d to
%-5d)\n",$ng_name,$articles,$first,$last);
#declare a messages counter
my $x = 1;
#set the nntpstat marker to the last message in the newsgroup
$nntp->last;
#while we can go to the next message ....
while($nntp->next){
#print what number message we're on
print "num: $x\n";
#declare a file handle for the article
my $fh = $nntp->articlefh;
#print the file handle
while(<$fh>){
print;
}
#limit how many messages you want
last if $x == 1;
#increment messages counter
$x++;
}
#close the connection to the NNTP server
$nntp->quit;
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 ...
Iron Law of Distribution: Them that has, gets.
------------------------------
Date: Wed, 03 Sep 2003 18:02:54 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: James Willmore <jwillmore@cyberia.com>
Subject: Re: View NG with Net::NNTP
Message-Id: <e9ca193e6376da43d325b5930dccb391@news.teranews.com>
>>>>> "James" == James Willmore <jwillmore@cyberia.com> writes:
James> I should follow my own advise :)
James> The above code will cause an infinite loop - opps! The below code
James> (tested and with comments) works :)
And to keep from seeing the same messages twice, you can even combine
it with News::Newsrc, as I did in my column article at:
<http://www.stonehenge.com/merlyn/UnixReview/col22.html>
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 3 Sep 2003 11:45:13 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <Pine.SGI.3.96.1030903114213.32571B-100000@vcmr-64.server.rpi.edu>
On 3 Sep 2003, Anno Siegel wrote:
>ddtl <this.is.invalid@yahoo.com> wrote in comp.lang.perl.misc:
>>
>> Hello everybody,
>>
>> I have some difficulty to understand why does qr// operator needs
>> 'o' modifier. There seems to be a disagreement between perlop manpage
>> and "Programming Perl" (3rd edition - i will use PP for short from now
>> on).
>
>The qr// operator doesn't need the /o modifier, you must have misunder-
>stood what the documentation is saying. The relation is that qr// can
>be used to achieve what /o would be needed for without it.
But the qr// operator can take the /o modifier. Perhaps it's a super rare
condition, but you can use it.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Wed, 03 Sep 2003 18:52:18 +0400
From: ddtl <this.is.invalid@yahoo.com>
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <utvblvgea4viqelei0c1s1b72u4o32q78q@4ax.com>
>The qr// operator doesn't need the /o modifier, you must have misunder-
>stood what the documentation is saying. The relation is that qr// can
>be used to achieve what /o would be needed for without it.
Maybe i have chosen rather wrong wording. qr// certainly does not
*need* the /o operator in a sense that it is syntactically correct to
write a statement containing qr// operator without writing an /o
modifier, but if you don't add /o modifier, RE will be compiled every
time it is evaluated, that is what manpage says.
First of all, operator's signature is (everything between double
quotes is quoted from perlop manpage):
"qr/STRING/imosx"
that is, obviously there *is* /o modifier for qr//.
"Options are:
i Do case-insensitive pattern matching.
m Treat string as multiple lines.
o Compile pattern only once.
s Treat string as single line.
x Use extended regular expressions.
"
As the quote above says, if you use /o, pattern is compiled only once,
which obviously means that if you don't use /o - pattern would be
compiled more then once, which is exactly what happens when instead of
using 'qr//'ed expression you use a plain variable in m// or s//.
So, obviously qr// operator *does* need the /o modifier in order to
be equivalent to the usual RE with /o modifier, which means that the
question is still valid.
Maybe you have another explanation to the above quotes from the manpage?
For the time being i don't see any other way to understand it...
ddtl.
------------------------------
Date: 3 Sep 2003 17:35:19 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <slrnblc9im.itm.sholden@flexal.cs.usyd.edu.au>
On Wed, 03 Sep 2003 18:52:18 +0400, ddtl <this.is.invalid@yahoo.com> wrote:
>
>>The qr// operator doesn't need the /o modifier, you must have misunder-
>>stood what the documentation is saying. The relation is that qr// can
>>be used to achieve what /o would be needed for without it.
>
> Maybe i have chosen rather wrong wording. qr// certainly does not
> *need* the /o operator in a sense that it is syntactically correct to
> write a statement containing qr// operator without writing an /o
> modifier, but if you don't add /o modifier, RE will be compiled every
> time it is evaluated, that is what manpage says.
The manpage does not say that. In fact the manpage says almost the opposite:
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:
[snip example that doesn't use /o]
Precompilation of the pattern into an internal representation at the
moment of qr() avoids a need to recompile the pattern every time a
match "/$pat/" is attempted.
- perldoc perlop
> First of all, operator's signature is (everything between double
> quotes is quoted from perlop manpage):
>
> "qr/STRING/imosx"
>
> that is, obviously there *is* /o modifier for qr//.
>
> "Options are:
>
> i Do case-insensitive pattern matching.
> m Treat string as multiple lines.
> o Compile pattern only once.
> s Treat string as single line.
> x Use extended regular expressions.
> "
>
> As the quote above says, if you use /o, pattern is compiled only once,
> which obviously means that if you don't use /o - pattern would be
> compiled more then once, which is exactly what happens when instead of
> using 'qr//'ed expression you use a plain variable in m// or s//.
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, obviously qr// operator *does* need the /o modifier in order to
> be equivalent to the usual RE with /o modifier, which means that the
> question is still valid.
>
> Maybe you have another explanation to the above quotes from the manpage?
> For the time being i don't see any other way to understand it...
The o on qr//o doesn't do anything, since qr// precompiles already.
For example:
$needle = 'foo';
$re = qr/$needle/;
$reo = qr/$needle/o;
sub check {
print "\$needle = $needle\n";
for (@_) {
print ' /$needle/ matches ',"$_\n" if /$needle/;
print ' /$needle/o matches ',"$_\n" if /$needle/o;
print ' /$re/ matches ', "$_\n" if /$re/;
print ' /$reo/ matches ', "$_\n" if /$reo/;
}
}
check('barbaz');
$needle = 'bar';
check('barbaz');
Obviously qr// *does not* need the /o modifier in order to be
equivalent to the usual RE with the /o modifier, as evidenced
by the fact that /$needle/o, /$re/, and /$reo/ all fail to match
'barbaz' even though $needle is set to 'bar' in the above code.
--
Sam Holden
------------------------------
Date: 3 Sep 2003 18:00:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why qr// needs /o modifier, or bug in a documentation.
Message-Id: <bj5a72$cia$1@mamenchi.zrz.TU-Berlin.DE>
ddtl <this.is.invalid@yahoo.com> wrote in comp.lang.perl.misc:
>
> >The qr// operator doesn't need the /o modifier, you must have misunder-
> >stood what the documentation is saying. The relation is that qr// can
> >be used to achieve what /o would be needed for without it.
>
> Maybe i have chosen rather wrong wording. qr// certainly does not
> *need* the /o operator in a sense that it is syntactically correct to
> write a statement containing qr// operator without writing an /o
> modifier, but if you don't add /o modifier, RE will be compiled every
> time it is evaluated, that is what manpage says.
>
> First of all, operator's signature is (everything between double
> quotes is quoted from perlop manpage):
>
> "qr/STRING/imosx"
>
> that is, obviously there *is* /o modifier for qr//.
>
> "Options are:
>
> i Do case-insensitive pattern matching.
> m Treat string as multiple lines.
> o Compile pattern only once.
> s Treat string as single line.
> x Use extended regular expressions.
> "
>
> As the quote above says, if you use /o, pattern is compiled only once,
> which obviously means that if you don't use /o - pattern would be
> compiled more then once, which is exactly what happens when instead of
> using 'qr//'ed expression you use a plain variable in m// or s//.
>
>
> So, obviously qr// operator *does* need the /o modifier in order to
> be equivalent to the usual RE with /o modifier, which means that the
> question is still valid.
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.
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.
> Maybe you have another explanation to the above quotes from the manpage?
> For the time being i don't see any other way to understand it...
You have made a wrong assumption: That qr// goes where the regex used to be.
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 5433
***************************************