[29813] in Perl-Users-Digest
Perl-Users Digest, Issue: 1056 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 24 00:09:45 2007
Date: Fri, 23 Nov 2007 21:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 23 Nov 2007 Volume: 11 Number: 1056
Today's topics:
Can you detect that a process is waiting on stdin? <nospam@somewhere.com>
Re: float -> RGB <mgjv@tradingpost.com.au>
Re: How to clean up this ugly code? <ced@blv-sam-01.ca.boeing.com>
Re: How to generate radio buttons in Perl/CGI script wi <rkb@i.frys.com>
How to generate radio buttons in Perl/CGI script with c prelim_questions@yahoo.com
Re: How to get the string Cartesian Products of 2 list <tzz@lifelogs.com>
Re: How to get the string Cartesian Products of 2 list <rvtol+news@isolution.nl>
How to pass Arrays <amerar@iwc.net>
Re: How to pass Arrays <ben@morrow.me.uk>
Re: interesting case of data corruption, and its cause <smallpond@juno.com>
Re: interesting case of data corruption, and its cause <ben@morrow.me.uk>
Re: minicpan, CPAN/CPANPLUS and autobundles on linux <bik.mido@tiscalinet.it>
Re: Script to disconnect Linksys WRT54G wireless router <spamtrap@dot-app.org>
Re: Script to disconnect Linksys WRT54G wireless router <ben@morrow.me.uk>
Re: Script to disconnect Linksys WRT54G wireless router <markmcintyre@spamcop.net>
searching for a pattern for multiple matches <jhu4399@yahoo.com>
Re: searching for a pattern for multiple matches <ben@morrow.me.uk>
Re: searching for a pattern for multiple matches <jhu4399@yahoo.com>
Re: searching for a pattern for multiple matches <ben@morrow.me.uk>
Re: SvUOK always fails on 64bit platform <sisyphus359@gmail.com>
Re: SvUOK always fails on 64bit platform <ben@morrow.me.uk>
Re: SvUOK always fails on 64bit platform <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 23 Nov 2007 23:10:37 -0500
From: "Thrill5" <nospam@somewhere.com>
Subject: Can you detect that a process is waiting on stdin?
Message-Id: <LdOdnVPJfdmgOdranZ2dnUVZ_gSdnZ2d@comcast.com>
I have a Perl library that I wrote that I use to manage an application that
we have. The app has about 100 or so CLI's that you can use to get data
into the app, get data out, produce reports etc. Anyway, when the CLI's are
run, stdout and stderr are redirected to a file which I then parse for
informational and error messages after the CLI completes. Today I ran into
a situation where I did not pass all of the correct parameters and the CLI
then prompted for the required parameter. My Perl program then just waited
forever since it was waiting for the output that never came. Yes this was a
logic problem in my Perl program, but I would a way to detect this and end
the Perl program and report the error (this has happened before.) I can't
set an alarm and catch a signal for several reasons; the first is that the
module needs to be able to run on Win32 systems running Perl 5.6 which does
not support SIGALRM, and second, some of the CLI's can run for extremely
long periods of time (hours) while the CLI processes the data. The CLI's
are run from Perl using the "system" function.
Is there some way that I can hook into STDIN and then detect when the CLI is
waiting for input? If this is possible, then all I need to do is send it a
carriage return and it will then exit because not all the correct parameters
were passed. I will be able to then parse the error message and exit the
program. I don't think there is, but I figured I would ask the question
anyway. My other alternative is to add some more logic to ensure that all
the required parameters are there before invoking the CLI's. I don't want
to go down this path if at all possible because each CLI has different
required parameters, and some have situations where specifying certain
switches and parameters then require other switches and parameters and it
would get pretty ugly. I guess I could also redirect STDIN from a file that
has a bunch of CR's in it as well, but then I would need to create the file
(to ensure that it exists) and delete it when I'm done. Please keep in mind
that a solution must be able to run on Win32 systems.
Thanks!
------------------------------
Date: Sat, 24 Nov 2007 08:28:23 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: float -> RGB
Message-Id: <slrnfkehfn.gdg.mgjv@martien.heliotrope.home>
On Fri, 23 Nov 2007 05:00:13 -0800 (PST),
alexxx.magni@gmail.com <alexxx.magni@gmail.com> wrote:
> Greetings,
> I know this isnt a perlish problem,
> but I need to transform a float $x=0..1 in RGB values ($R,$G,$B)
> according to whichever palette you want...
> but I'm not expert at all in graphics problems, so it's not clear to
> me how to do it - hope somebody can drop down a couple of lines!
As others have said, it's a bit vague what exactly you're trying to do.
If you're trying to calculate coordinates in different colour spaces,
maybe you can have a look at this:
http://www.manning.com/verbruggen/
Chapter 1 of that book discusses colour spaces, and is available as a
free download from that page. Perl code implementations are discussed in
Appendix B, which is not available online, but the full source code for
the book is also available from the same page, which includes those
pieces of code.
Martien
PS. disclosure: If it wasn't already clear, I am the author of that
book. This post is not meant as an advertisement, which is why I made
sure all relevant content I refer to is available to you for free.
--
|
Martien Verbruggen | Since light travels faster than sound, is
| that why some people appear bright until you
| hear them speak?
------------------------------
Date: Fri, 23 Nov 2007 14:57:06 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: How to clean up this ugly code?
Message-Id: <fece82a4-1af9-4622-a3c4-5e442ddbee6d@a39g2000pre.googlegroups.com>
On Nov 23, 8:36 am, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> Ben Morrow wrote:
> > However, the first question is why you have
> > these methods at all. It would be much better to have one method
> > ->DisplayPage that took the page number as a parameter.
>
> Good Question, and unanswered as yet.
>
> All the other "direct" answers to OP's original
> post are interesting pieces of Perl, but
> don't address the largest flaw in the
> overall implementation.
>
With the trivial code shown, that's certainly true but since that
question is still not "answered", there may be some wiggle room...
Even if the methods could be housed together, separating them out
might be preferable due
to auto-generation of the methods, or complexity, or sheer
combinatorial bloat.
Or maybe this is a case of "easy on the eyes" winning out over over
efficiency.
--
Charles DeRykus
------------------------------
Date: Fri, 23 Nov 2007 21:05:39 -0800 (PST)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: How to generate radio buttons in Perl/CGI script with call to shell script?
Message-Id: <c4ebc77e-3a1a-4227-bdc4-da7effa703b3@d27g2000prf.googlegroups.com>
On Nov 23, 8:24 pm, prelim_questi...@yahoo.com wrote:
> My background: I am very new to Perl, CGI, and HTML. UNIX is okay.
>
> I want to generate many (say 50+) radio_groups, each occurring on a
> different webpage (like a quiz). The most convenient way for me to do
> this is for each radio group to reference a particular file in my
> directory which contains the appropriate question and possible answers
> (different file for each radio group).
>
> So for example:
>
> Instead of hand typing each radio group like this:
>
> print "<p><em>How far can they fly?</em><br>",
> radio_group(
> -name=>'how far',
> -values=>['10 ft','1 mile','10 miles','real
> far'],
> -default=>'1 mile'); # (example from
> perldoc)
>
> I want to automatically generate this form with something like:
>
> print "<p><em> $question </em><br>",
> radio_group(
> -name=>$id,
> -values=>[$value1,$value2,$value3,$value4],
> -default=>$value1);
>
> where $question=` cat /home/username/file1 | head -1` { or however
> you say the first line of a file in Perl}
>
> and [$value1,$value2,$value3,$value4] = {the remaining 4 lines in /
> home/username/file1}.
open my $file1 '<', '/home/username/file1' or die "file1 open failed
$!";
chomp(my @file1 = <$file1>);
close $file1;
my $question = shift @file1;
print "<p><em> $question </em><br>",
radio_group(
-name=>$id,
-values=>\@file1,
-default=>$file1[0]
);
>
> Now to make it slightly more complicated, each file is generated by a
> shell script which I would prefer to reference directly in my Perl
> script. In case that is not clear, say I use ./home/username/
> radio_script -option1 to generate file1
> ./home/username/radio_script -option2 to generate file2
> etc.
>
> I have tried many variations on the system command to do this without
> success. How do I do this?
for my $num (1..50) {
system("/home/username/radio_script -option$num");
}
>
> Undoubtedly, I have may have been unclear at times. Please ask, and I
> can clarify.
>
> Thanks!
Personally, I'd drop the indirection of using the cat command and
shell script, and instead do everything in Perl without creating the
50+ question files.
------------------------------
Date: Fri, 23 Nov 2007 20:24:23 -0800 (PST)
From: prelim_questions@yahoo.com
Subject: How to generate radio buttons in Perl/CGI script with call to shell script?
Message-Id: <4778b47b-eade-4352-825e-a4685bd42234@a39g2000pre.googlegroups.com>
My background: I am very new to Perl, CGI, and HTML. UNIX is okay.
I want to generate many (say 50+) radio_groups, each occurring on a
different webpage (like a quiz). The most convenient way for me to do
this is for each radio group to reference a particular file in my
directory which contains the appropriate question and possible answers
(different file for each radio group).
So for example:
Instead of hand typing each radio group like this:
print "<p><em>How far can they fly?</em><br>",
radio_group(
-name=>'how far',
-values=>['10 ft','1 mile','10 miles','real
far'],
-default=>'1 mile'); # (example from
perldoc)
I want to automatically generate this form with something like:
print "<p><em> $question </em><br>",
radio_group(
-name=>$id,
-values=>[$value1,$value2,$value3,$value4],
-default=>$value1);
where $question=` cat /home/username/file1 | head -1` { or however
you say the first line of a file in Perl}
and [$value1,$value2,$value3,$value4] = {the remaining 4 lines in /
home/username/file1}.
Now to make it slightly more complicated, each file is generated by a
shell script which I would prefer to reference directly in my Perl
script. In case that is not clear, say I use ./home/username/
radio_script -option1 to generate file1
./home/username/radio_script -option2 to generate file2
etc.
I have tried many variations on the system command to do this without
success. How do I do this?
Undoubtedly, I have may have been unclear at times. Please ask, and I
can clarify.
Thanks!
------------------------------
Date: Fri, 23 Nov 2007 15:38:54 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to get the string Cartesian Products of 2 list
Message-Id: <86y7cobq1d.fsf@lifelogs.com>
On Fri, 23 Nov 2007 07:59:26 -0800 (PST) xueweizhong@gmail.com wrote:
>> > perl glob in perl5.8 is not power enough than the bash3.0 glob, it
>> > doesn't support .. operator which is fatal to this issue:
>>
>> Why? In practice, the lists being globbed are likely to be variables,
>> not hard coded inside the glob call.
>>
>> {
>> local $" = ','; # List separator
>>
>> my @letters = 'a'..'c';
>> my @numbers = 1..3;
>>
>> my @globbed = glob "{@letters}{@numbers}";
>>
>> print "@globbed\n";
>>
>> }
x> I do think these lines are worse than using loop BLOCK. What I want is
x> an single expression, not statements with so many nosiy lines.
What you perceive as noise are actually good Perl programming
practices. If you don't like them, you could do:
# the original is much better code
print glob sprintf("{%s}{%s}", join(',', 'a'..'c'), join(',', 1..3));
# even more bash-like, using in-place interpolation hacks
local $" = ','; # List separator
print glob "{@{['a'..'c']}}{@{[1..3]}}\n";
You should realize that Perl is a programming language and thus does not
have all the shortcuts that bash offers. No Perl solution will satisfy
you if you just want bash. If you want bash, use bash.
Ted
------------------------------
Date: Sat, 24 Nov 2007 03:08:37 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How to get the string Cartesian Products of 2 list
Message-Id: <fi84of.1mc.1@news.isolution.nl>
Ted Zlatanov schreef:
> local $" = ','; # List separator
> print glob "{@{['a'..'c']}}{@{[1..3]}}\n";
Command line version:
$perl -wle '
$"=",";
print for glob "{@{[ q{a}..q{c} ]}}{@{[ 1..3 ]}}"
'
a1
a2
a3
b1
b2
b3
c1
c2
c3
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 23 Nov 2007 19:58:04 -0800 (PST)
From: "amerar@iwc.net" <amerar@iwc.net>
Subject: How to pass Arrays
Message-Id: <fcbacd8c-7f6d-43cd-8dfa-88e85f9510ee@w34g2000hsg.googlegroups.com>
Hi All,
I have a unix script which puts together an array:
set -A week_fnames $FILE5 $FILE6 $FILE7 $FILE8 $FILE9 $FILEA
How to I pass that array to a Perl program, and be able to use the
array in the Perl program??
Thanks!
------------------------------
Date: Sat, 24 Nov 2007 04:16:54 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to pass Arrays
Message-Id: <m6lk15-tn5.ln1@osiris.mauzo.dyndns.org>
Quoth "amerar@iwc.net" <amerar@iwc.net>:
>
> I have a unix script which puts together an array:
>
> set -A week_fnames $FILE5 $FILE6 $FILE7 $FILE8 $FILE9 $FILEA
>
> How to I pass that array to a Perl program, and be able to use the
> array in the Perl program??
perl script "$week_fnames[@]" (or whatever the appropriate syntax is for
your shell) will pass the values into @ARGV in your perl program, but I
presume you could work that out... If you are trying to have your Perl
program change the values of the array in a shell script that invokes
it, then in general that can't be done. One way round is to have perl
emit shell code which you can then eval, but it can be tricky getting
the quoting right.
Ben
------------------------------
Date: Fri, 23 Nov 2007 15:30:31 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: interesting case of data corruption, and its cause
Message-Id: <cc66ef0a-beca-4a89-a40f-847d457ebad6@v4g2000hsf.googlegroups.com>
On Nov 22, 3:41 pm, "Dr.Ruud" <rvtol+n...@isolution.nl> wrote:
> Dr.Ruud schreef:
>
> > smallpond:
> >> Assigning to $_ just changes the scalar global variable $_,
> >> not the thing that it refers to.
>
> > perl -wle '
> > @x = 1..3;
> > $_ = 42 for @x;
> > print for @x
> > '
> > 42
> > 42
> > 42
>
> Or maybe clearer:
>
> [root@peat attachments]# perl -wle'
> $_ = "foo";
> print;
>
> @x = 1..3;
> print for @x;
>
> $_ = 42 for @x;
> print for @x;
>
> print;
> '
> foo
> 1
> 2
> 3
> 42
> 42
> 42
> foo
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."
You are correct, but nothing special about $_
in that case. Inside a foreach, any assignment
to the loop variable changes the list element.
So instead of:
$_ = 42 for @x;
This would have the same effect:
for $j (@x) { $j = 42; }
------------------------------
Date: Sat, 24 Nov 2007 00:28:01 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: interesting case of data corruption, and its cause
Message-Id: <hp7k15-i4f.ln1@osiris.mauzo.dyndns.org>
Quoth smallpond <smallpond@juno.com>:
> On Nov 22, 3:41 pm, "Dr.Ruud" <rvtol+n...@isolution.nl> wrote:
> > Dr.Ruud schreef:
> >
> > > smallpond:
> > >> Assigning to $_ just changes the scalar global variable $_,
> > >> not the thing that it refers to.
> >
<snip: when $_ is an alias assigning to it assigns to the aliased value
as well>
>
> You are correct, but nothing special about $_
> in that case. Inside a foreach, any assignment
> to the loop variable changes the list element.
> So instead of:
> $_ = 42 for @x;
> This would have the same effect:
> for $j (@x) { $j = 42; }
Yes, of course. The point here is that the op had
map { extract(...) } ...;
and then, somewhere random down the call chain from extract,
while (<$FH>) { ... }
without localising $_. Since $_ is *global*, assigning to it anywhere
without localising it first can have unexpected side-effects elsewhere.
The bug was not in the map, but in the code that assigned to $_ (albeit
implicitly with while (<>)) without localising. As Uri pointed out,
using that construction is almost always a mistake.
Attempting to fix the problem by localising $_ is tricky, as well,
because C<local $_> doesn't always work due to some very boring bugs in
some versions of perl when $_ is an element of a tied array. The
workaround (local *_) doesn't buy you much, because you lose your sub
arguments. About the only time I use while (<>) is at the very top level
with -n, when it can't do any harm.
This problem only occurs with while loops. for loops implicitly localise
the loop variable if it isn't a fresh lexical, so don't end up stomping
on anything.
Ben
------------------------------
Date: Sat, 24 Nov 2007 01:06:12 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: minicpan, CPAN/CPANPLUS and autobundles on linux
Message-Id: <solek31k0r1pqfj1ki0pu0efmb7tuktfhs@4ax.com>
On Fri, 23 Nov 2007 10:04:38 -0600, brian d foy
<brian.d.foy@gmail.com> wrote:
>> Since it didn't receive any answers, I replicated your question with
>> proper attributions at
>
>Well, I took a break for an American holiday so I didn't have a chance
>to answer this one until today.
>
>Haven't we gone through this before? I certainly think reposting
>content without permission, even with attribution, is wrong. Several
>other people have told you the same thing.
Yes, we've gone through this before. None of the argumentations did
convince me. Do I risk a report to the abuse, a lawyer's notification
or anything of comparable severity? If so, then I'll stop forever
because there's not point in undergoing a loss for the desire to help
an individual, and the community. Sadly, this seems to be much a
clpmisc thing, because no one complained in PM when I did so before
and no one has complained today: nay, the node seems to have been
relatively well received -judging from its XP- and it's Friday
Afternoon... Of course you're also a member there and you can bash me
there too. OTOH Mirco Wahab, for one, *thanked* me for bringing a
problem from PM to clpmisc and is now an active poster in both places.
As far as reposting content without permission is concerned, let's be
serious: it happens all the time on the web and beyond. Just a quick
example:
http://www.osdir.com/ml/linux.distributions.crux.general/2006-12/msg00005.html
It's a copy of a message posted to a mailing list, of course, and I'm
the author. There even isn't a *clear* reference to me. I didn't know
that the mailing list was being replicated at that site: I just asked
Google.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 23 Nov 2007 16:54:36 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <m163zspqzn.fsf@dot-app.org>
Wilson <davewilson69@sbcglobal.net> writes:
> On Fri, 23 Nov 2007 10:47:50 -0500, Sherman Pendley wrote:
>> When someone who admits to not having any Perl knowledge, and to not being a
>> programmer at all, claims to know what Perl is capable of, I have serious
>> doubts about that claim. Someone who's at that level simply doesn't have the
>> experience or background to reasonably assess Perl's capabilities.
>
> Hi Sherman,
>
> I understand your argument, however, one (or all) of us is missing the main
> point (maybe I didn't make it well enough so I'll try again).
You claimed that Perl can't log into an https server and simulate a button
click. My point is that this claim is false; that kind of "web scraping" is
a very common use of Perl.
> I don't know if it will push this project forward to continue to "discuss"
> without actually progressing - but - my main point was there is no evidence
> in the literature that it has ever been done with a Linksys WRT54G router.
>
> ... no evidence in the literature that perl works for this purpose ...
Absence of proof is not proof of absence.
> At least nobody has ever posted a solution for logging into https Linksys
> WRT54G (other than me and my script didn't work) - so my main point is that
> there is absolutely no evidence that perl can do these two steps:
> a) Log into the Linksys WRT54G as https
> b) Press a button
In a generic sense, there are literally hundreds of examples of Perl doing what
you claim it can't do - just google for "WWW::Mechanize" or "perl web scraping"
to see them. There is absolutely no question that Perl is capable of logging
into an https web server and performing the moral equivalent of a button click.
> Either that, or just run my posted script and let us know if you get the
> SAME errors I posted.
I have a different model Linksys. I could adapt the script you posted to work
with my own router, and post that as "proof," but that wouldn't be useful for
you. It wouldn't work for *your* router, because mine is quite old and it's
quite likely that its admin interface is arranged differently.
The odds of your finding someone who owns the exact same model router, *and*
is capable of writing a script like this, are very small. You'll need to start
with a script that was originally written for another make and model router,
and adapt it to fit the admin interface for your own router.
I think your problem is one of unrealistic expectations. There is no standard
for browser-based router interfaces, and you can't reasonably expect a script
in *any* language that was written for a different router to work unchanged
with yours.
sherm--
--
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Fri, 23 Nov 2007 22:24:21 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <lh0k15-1q.ln1@osiris.mauzo.dyndns.org>
Quoth Wilson <davewilson69@sbcglobal.net>:
> On Fri, 23 Nov 2007 19:27:26 +0000, Ben Morrow wrote:
> >> At least nobody has ever posted a solution for logging into https Linksys
> >> WRT54G (other than me and my script didn't work)
> > About the only case where it's non-trivial to fake a browser's request
> > with Perl is when the page includes JavaScript that changes what is
> > about to be submitted in a non-trivial way.
>
> I turned off javascript and java in my browser and guess what? I
> could log into my Linksys WRT54G router but I could NOT access any of the
> buttons. The web page was "garbled" (for lack of a better description)
> without Javascript and/or Java.
>
> Hmmmm... does this mean that Perl can "impersonate" java somehow?
Do you understand how http works? The client makes a request, and the
server returns a response. There is no way the server can tell if the
client is IE with javascript or something else that just happens to make
the same requests in the same order. For the last time: *you need to
find out what requests your browser is actually making*. Then you can
begin working out how to reproduce them from Perl, which will almost
certainly be straightforward.
Ben
------------------------------
Date: Fri, 23 Nov 2007 23:36:51 +0000
From: Mark McIntyre <markmcintyre@spamcop.net>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <13kep0f19l9dseb@corp.supernews.com>
Wilson wrote:
> On Thu, 22 Nov 2007 08:27:27 -0500, Sherman Pendley wrote:
>> Perl - what makes you think that something is impossible simply because *you*
>> can't figure it out?
>
> I'd like to agree with you Sherman, but, it's pretty simple to prove my
> point. Nobody else has figured it out either.
FWIW this isn't a proof. It merely shows that /to date/ nobody smart
enough or interested enough has looked into it.
For three hundred years Fermat's Last Theorem stood unproven. That
doesn't mean it was impossible to prove. Someday someone will prove the
Riemann Hypothesis too.
------------------------------
Date: Fri, 23 Nov 2007 17:32:36 -0800 (PST)
From: jhu <jhu4399@yahoo.com>
Subject: searching for a pattern for multiple matches
Message-Id: <bfca2dd6-8ef6-4ae2-ba56-75059402f419@i29g2000prf.googlegroups.com>
Can anyone tell me using Perl how to find all matching patterns. So if
I have this one big string of say a html web page which contains
multiple IP's and my pattern which is \d{1,3}\.\d{1,3}\.\d{1,3}\.
\d{1,3} then how do I go about setting up my code in some sort of
while loop to find all instances of matches ? Also can someone in
simple terms explain what a back reference is ? Is it simply the
pattern found ?
Thanks in advance
------------------------------
Date: Sat, 24 Nov 2007 02:35:27 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: searching for a pattern for multiple matches
Message-Id: <f8fk15-sqk1.ln1@osiris.mauzo.dyndns.org>
Quoth jhu <jhu4399@yahoo.com>:
> Can anyone tell me using Perl how to find all matching patterns. So if
> I have this one big string of say a html web page which contains
> multiple IP's and my pattern which is \d{1,3}\.\d{1,3}\.\d{1,3}\.
> \d{1,3} then how do I go about setting up my code in some sort of
> while loop to find all instances of matches ?
Use the /g modifier. See 'Regexp Quote-Like Operators' in perldoc
perlop, particularly the section starting "In scalar context, each
execution of "m//g...".
> Also can someone in
> simple terms explain what a back reference is ? Is it simply the
> pattern found ?
perldoc perlretut
Ben
------------------------------
Date: Fri, 23 Nov 2007 19:13:21 -0800 (PST)
From: jhu <jhu4399@yahoo.com>
Subject: Re: searching for a pattern for multiple matches
Message-Id: <98ad872f-5098-42b9-9736-5c2b6ca087e2@y43g2000hsy.googlegroups.com>
On Nov 23, 6:35 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth jhu <jhu4...@yahoo.com>:
>
> > Can anyone tell me using Perl how to find all matching patterns. So if
> > I have this one big string of say a html web page which contains
> > multiple IP's and my pattern which is \d{1,3}\.\d{1,3}\.\d{1,3}\.
> > \d{1,3} then how do I go about setting up my code in some sort of
> > while loop to find all instances of matches ?
>
> Use the /g modifier. See 'Regexp Quote-Like Operators' in perldoc
> perlop, particularly the section starting "In scalar context, each
> execution of "m//g...".
>
> > Also can someone in
> > simple terms explain what a back reference is ? Is it simply the
> > pattern found ?
>
> perldoc perlretut
>
> Ben
Ben thanks but I'm not on Unix or Linux but rather on Windows and
MV6.0.
------------------------------
Date: Sat, 24 Nov 2007 04:11:52 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: searching for a pattern for multiple matches
Message-Id: <8tkk15-tn5.ln1@osiris.mauzo.dyndns.org>
Quoth jhu <jhu4399@yahoo.com>:
> On Nov 23, 6:35 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth jhu <jhu4...@yahoo.com>:
> >
> > > Can anyone tell me using Perl how to find all matching patterns. So if
> > > I have this one big string of say a html web page which contains
> > > multiple IP's and my pattern which is \d{1,3}\.\d{1,3}\.\d{1,3}\.
> > > \d{1,3} then how do I go about setting up my code in some sort of
> > > while loop to find all instances of matches ?
> >
> > Use the /g modifier. See 'Regexp Quote-Like Operators' in perldoc
> > perlop, particularly the section starting "In scalar context, each
> > execution of "m//g...".
> >
> > > Also can someone in
> > > simple terms explain what a back reference is ? Is it simply the
> > > pattern found ?
> >
> > perldoc perlretut
>
> Ben thanks but I'm not on Unix or Linux but rather on Windows and
> MV6.0.
Huh? What difference does that make? Do you mean you can't find the
perldocs? perldoc works perfectly well on Win32, or ActivePerl installs
a nice HTMLified version in c:\perl\html.
If you mean 'I'm not actually using Perl, but some other system that
provides Perlish regexen' then: sorry, go ask somewhere else. This
newsgroup is for discussing Perl.
Ben
------------------------------
Date: Fri, 23 Nov 2007 15:55:58 -0800 (PST)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: SvUOK always fails on 64bit platform
Message-Id: <b54530d6-0577-49fd-88a6-35a1a17e3c61@s8g2000prg.googlegroups.com>
On Nov 24, 4:20 am, Ben Morrow <b...@morrow.me.uk> wrote:
.
.
> 64bit value SvUOK
> 0 .. (1<<63 - 1) false
> (1<<63) .. (1<<64 - 1) true
>
There's an interesting little catch here. On many 64-bit builds of
perl you'll find that whilst SvUOK returns true for 1<<63, it returns
false for 2**63 (because, on perls that don't also have long double
support, 2**63 is an NV). If your perl is also built with long double
support, then this issue does not arise.
I personally find that behaviour quite annoying ... but I seem to be
the only one, and it has been put to me that this would *not* be
trivial to fix .... so I reckon the behaviour is here to stay :-)
Cheers,
Rob
------------------------------
Date: Sat, 24 Nov 2007 02:29:42 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: SvUOK always fails on 64bit platform
Message-Id: <mtek15-sqk1.ln1@osiris.mauzo.dyndns.org>
Quoth sisyphus <sisyphus359@gmail.com>:
> On Nov 24, 4:20 am, Ben Morrow <b...@morrow.me.uk> wrote:
> > 64bit value SvUOK
> > 0 .. (1<<63 - 1) false
> > (1<<63) .. (1<<64 - 1) true
>
> There's an interesting little catch here. On many 64-bit builds of
> perl you'll find that whilst SvUOK returns true for 1<<63, it returns
> false for 2**63 (because, on perls that don't also have long double
> support, 2**63 is an NV). If your perl is also built with long double
> support, then this issue does not arise.
Yes: I noticed 2**63 was a NV, which is why I used << instead :). It
seems that since ** is pow(3), it counts as a floating-point function.
This all illustrates another point, which is that depending on Perl
passing a particular representation of data to XS is usually a bad
idea, *especially* with IV/UV/NV which aren't even distinguishable from
Perl-space.
> I personally find that behaviour quite annoying ... but I seem to be
> the only one, and it has been put to me that this would *not* be
> trivial to fix .... so I reckon the behaviour is here to stay :-)
Well, yeah: given that ** is a floating-point operation, you no longer
have integer precision in the result:
~% perl -le'print for (1<<55)-1, sprintf "%.0f", 2**55-1'
36028797018963967
36028797018963968
though I have to say I don't really understand why this does a
floating-point subtract, when there's a whole lot of careful code in
both pp_pow and pp_subtract that tries to do arithmetic in integers where
possible... Hmmm. The logic in pp_pow goes something like
if (base or power non-integral)
use pow(3)
if (power negative)
use pow(3)
if (base is a power of 2) {
calculate by hand, in NVs
This gives a NV-only result when the result doesn't fit in a NV
with integer precision.
}
else {
if (
x**power fits in an UV, where x is the smallest power of 2
greater than base
) {
calculate by hand, in UVs
This gives a IV/UV result.
}
else
use pow(3)
}
}
but I don't really understand why the 'power of 2' branch isn't moved
inside the second 'else', so small powers of 2 to small powers are
calculated in UVs where possible.
For that matter, even if you are going to calculate in NVs, the result
is always going to be accurate (since it's a power of 2) so when the
result fits in an IV/UV at all the result should be I/UOK. That seems
like an easy bug to fix, so I must be missing something...
Ben
------------------------------
Date: Sat, 24 Nov 2007 04:08:17 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: SvUOK always fails on 64bit platform
Message-Id: <hmkk15-tn5.ln1@osiris.mauzo.dyndns.org>
Quoth Ben Morrow <ben@morrow.me.uk>:
>
> possible... Hmmm. The logic in pp_pow goes something like
>
> if (base or power non-integral)
> use pow(3)
>
> if (power negative)
> use pow(3)
>
> if (base is a power of 2) {
> calculate by hand, in NVs
>
> This gives a NV-only result when the result doesn't fit in a NV
> with integer precision.
> }
> else {
> if (
> x**power fits in an UV, where x is the smallest power of 2
> greater than base
> ) {
> calculate by hand, in UVs
>
> This gives a IV/UV result.
> }
> else
> use pow(3)
> }
> }
>
> but I don't really understand why the 'power of 2' branch isn't moved
> inside the second 'else', so small powers of 2 to small powers are
> calculated in UVs where possible.
Sorry to be responding to myself, but having checked perlbrowse I now
think this was simply an oversight. The if(power of 2) logic is older
than the inner if, and was added to give a sane result for 2**n on
machines that have slightly insane long doubles. The latter logic was
added later, to make things like 3**33 that fit in a 64bit UV give
integer results. It looks like the possibility of doing the same for
powers of 2 was overlooked. Maybe I'll report a bug after 5.10's out.
Ben
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1056
***************************************