[31102] in Perl-Users-Digest
Perl-Users Digest, Issue: 2347 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 17 16:09:49 2009
Date: Fri, 17 Apr 2009 13:09:15 -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 Fri, 17 Apr 2009 Volume: 11 Number: 2347
Today's topics:
Re: Capture only first match in regular expression <noreply@gunnar.cc>
Re: Capture only first match in regular expression <tadmc@seesig.invalid>
Re: Capture only first match in regular expression sln@netherlands.com
Re: effienct way to select random value from the hash <darkon.tdo@gmail.com>
Re: effienct way to select random value from the hash <someone@example.com>
Re: effienct way to select random value from the hash <darkon.tdo@gmail.com>
Re: effienct way to select random value from the hash <ben@morrow.me.uk>
Re: If not match and naked block question <tadmc@seesig.invalid>
Re: If not match and naked block question <alfonso.baldaserra@gmail.com>
Re: perls popularity <1usa@llenroc.ude.invalid>
Re: perls popularity <g3rc4n@gmail.com>
Re: perls popularity <james@agentultra.com>
Re: perls popularity <darkon.tdo@gmail.com>
Re: perls popularity <cartercc@gmail.com>
Re: Recognizing a regex reference <bol@adv.magwien.gv.at>
Re: Recognizing a regex reference <ben@morrow.me.uk>
Replacing text containing parenthesis (Mark Hobley)
Re: Replacing text containing parenthesis <1usa@llenroc.ude.invalid>
Re: Replacing text containing parenthesis <ben@morrow.me.uk>
Re: Replacing text containing parenthesis <someone@example.com>
Re: Replacing text containing parenthesis (Mark Hobley)
Re: Replacing text containing parenthesis (Mark Hobley)
Specifyig username and password in PERL tandon.sourabh@gmail.com
Re: Specifyig username and password in PERL <ben@morrow.me.uk>
Re: using SSH without modules <news123@free.fr>
Re: What does `my' do?! <bol@adv.magwien.gv.at>
Re: What does `my' do?! <bol@adv.magwien.gv.at>
Re: What does `my' do?! <ben@morrow.me.uk>
Re: What does `my' do?! (Tim McDaniel)
Re: What does `my' do?! <ben@morrow.me.uk>
Re: What does `my' do?! (Tim McDaniel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 17 Apr 2009 15:51:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Capture only first match in regular expression
Message-Id: <74rfs2F159csqU1@mid.individual.net>
Peter Tuente wrote:
> the default behaviour of regular expression terms is to be "greedy", so to
> suppress this behaviour to become "not greedy" you have to apply a single
> question mark "?" right after the desired expression(s). Sounds some kind of
> complex, but I hope you get me ;-)
>
> In your case the following should be sufficient:
>
> # old: if($content =~ /.*(<a.*<\/a>).*/i){
> $anchorContent = $1;
>
> # new:
> if($content =~ /.*?(<a.*?<\/a>).*/i){
------------------------^^^------------^^
Your suggestion probably works. I just don't understand the point with
.*? at the beginning (of any m// PATTERN)
and
.* at the end (of any m// PATTERN)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 17 Apr 2009 09:35:32 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Capture only first match in regular expression
Message-Id: <slrnguh4tk.cu4.tadmc@tadmc30.sbcglobal.net>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Peter Tuente wrote:
>> # new:
>> if($content =~ /.*?(<a.*?<\/a>).*/i){
> Your suggestion probably works.
--------------------
#!/usr/bin/perl
use warnings;
use strict;
my $content = 'Perl can <abbr title="Do What I Mean">DWIM</abbr>'
. '<a href="perl.org">Perl Homepage</a>trailing';
if($content =~ /.*?(<a.*?<\/a>).*/i){
print "matched '$1'\n";
}
--------------------
or the canonical example of where pattern matching will fail while
a Real Parser will not fail:
--------------------
#!/usr/bin/perl
use warnings;
use strict;
my $content =<<ENDHTML;
<!--
uncomment this once the legal department OKs it
(There is no anchor element here!)
<a href="perl.org">Perl Homepage</a>;
-->
ENDHTML
if($content =~ /.*?(<a .*?<\/a>).*/i){
print "matched '$1'\n";
}
--------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 17 Apr 2009 12:45:56 -0700
From: sln@netherlands.com
Subject: Re: Capture only first match in regular expression
Message-Id: <jbmhu4l0qvk4hp5j8e8n1i9r949v53b0of@4ax.com>
On Fri, 17 Apr 2009 09:35:32 -0500, Tad J McClellan <tadmc@seesig.invalid> wrote:
>or the canonical example of where pattern matching will fail while
>a Real Parser will not fail:
You would have to be more specific why pattern match will fail and is
not a real parser. Got any other examples? List them for me to see.
List any canonical example a regex can't parse.
The modified regex below is a Real Parser then until you prove otherwise.
>--------------------
>#!/usr/bin/perl
>use warnings;
>use strict;
>
>my $content =<<ENDHTML;
><!--
>uncomment this once the legal department OKs it
>(There is no anchor element here!)
><a href="perl.org">Perl Homepage</a>;
>-->
>ENDHTML
>
>if($content =~ /.*?(<a .*?<\/a>).*/i){
^
this space is a nice touch
> print "matched '$1'\n";
>}
>--------------------
use strict;
use warnings;
my $content =<<ENDHTML;
<!--
uncomment this once the legal department OKs it
(There is no anchor element here!)
<a href="perl.org">Perl Homepage</a>;
-->
ENDHTML
if($content =~ /(<a .*?<\/a>)|<--.*?-->/i && defined $1){
print "matched '$1'\n";
}
__END__
-sln
------------------------------
Date: Fri, 17 Apr 2009 13:58:38 -0400
From: "darkon" <darkon.tdo@gmail.com>
Subject: Re: effienct way to select random value from the hash
Message-Id: <VLadna69-MXTXnXUnZ2dnUVZ_hadnZ2d@supernews.com>
"John W. Krahn" <someone@example.com> wrote:
> If you exit early then it is not truly random. You have to iterate over
> the complete list to get a random element.
Are you sure? The Perl FAQ has a code sample for selecting a random line
from a file without reading the entire file, and references Knuth for a
proof:
perldoc -q "random line"
------------------------------
Date: Fri, 17 Apr 2009 11:17:00 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: effienct way to select random value from the hash
Message-Id: <yI3Gl.24694$Qh6.10430@newsfe14.iad>
darkon wrote:
> "John W. Krahn" <someone@example.com> wrote:
>=20
>> If you exit early then it is not truly random. You have to iterate=20
>> over the complete list to get a random element.
>=20
> Are you sure? The Perl FAQ has a code sample for selecting a random=20
> line from a file without reading the entire file, and references Knuth =
> for a proof:
>=20
> perldoc -q "random line"
perldoc -q "random line"
How do I select a random line from a file?
Here=92s an algorithm from the Camel Book:
srand;
rand($.) < 1 && ($line =3D $_) while <>;
This has a significant advantage in space over reading the whole
file in. You can find a proof of this method in The Art of Computer=
Programming, Volume 2, Section 3.4.2, by Donald E. Knuth.
Please read the code carefully. At no point does it exit the while loop.=
The text says "reading the whole file in" which the code does not do.=20
But it does read the whole file one line at a time.
John
--=20
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
------------------------------
Date: Fri, 17 Apr 2009 14:22:05 -0400
From: "darkon" <darkon.tdo@gmail.com>
Subject: Re: effienct way to select random value from the hash
Message-Id: <WJydncvMV9NQVXXUnZ2dnUVZ_oadnZ2d@supernews.com>
"John W. Krahn" <someone@example.com> wrote:
>Please read the code carefully. At no point does it exit the while loop.
>
>The text says "reading the whole file in" which the code does not do.
>But it does read the whole file one line at a time.
Yeah, you're right. Never mind.
------------------------------
Date: Fri, 17 Apr 2009 19:19:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: effienct way to select random value from the hash
Message-Id: <jqtmb6-tiu2.ln1@osiris.mauzo.dyndns.org>
Quoth "darkon" <darkon.tdo@gmail.com>:
> "John W. Krahn" <someone@example.com> wrote:
>
> > If you exit early then it is not truly random. You have to iterate over
> > the complete list to get a random element.
>
> Are you sure? The Perl FAQ has a code sample for selecting a random line
> from a file without reading the entire file, and references Knuth for a
> proof:
>
> perldoc -q "random line"
No, the faq has a code smaple for selecting a random line that reads the
whole file *exactly once*, and doesn't need to know where the newlines
are beforehand. A naive algorithm would read the file twice: once to
count the lines, then again to find the one we'd chosen.
Ben
------------------------------
Date: Fri, 17 Apr 2009 08:09:19 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: If not match and naked block question
Message-Id: <slrngugvrv.brf.tadmc@tadmc30.sbcglobal.net>
alfonsobaldaserra <alfonso.baldaserra@gmail.com> wrote:
>> > my $tmpDRET = qx( $DSPMQ -m $QUEUE );
> on a related note is there a way to tell qx not to spit error message
> while running the code?
A very effective aid to software development is to actually read
the documention for the constructs that you use.
The 2nd paragraph of the description of qx// answers your question...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 17 Apr 2009 06:50:04 -0700 (PDT)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: Re: If not match and naked block question
Message-Id: <dcec78bd-7253-4787-8c01-fd72b7bbffe1@x1g2000prh.googlegroups.com>
> What happens if you run dspmq on its own? Do you get the message twice
> (once to stdout, once to stderr) or is the message not sent to stdout
> at all? If you get it twice, then you need to get rid of the stderr
> copy using qx($DSMPQ ... 2>/dev/null); otherwise, you need to send
> stderr to stdout so qx// can pick it up: qx($DSMPQ ... 2>&1).
Ben: thanks again for your support. when i run dspmq -q qmgr_name on
shell it just gives the answer once. actually Tad is right, i just
read in qx// documentation:
"Because backticks do not affect standard error, use shell file
descriptor syntax (assuming the shell supports this) if you care to
address this."
indeed this is what i was missing. i used the syntax at the web page
and it's working now
my $DRET = qx/ $DSPMQ -m $QUEUE 2>&1 /; # without 2>&1 it was
not executing the if block at all
if ($DRET =~ /AMQ7048/) {
print "MQ: $QUEUE does not exist.\n";
exit $return_code{'CRIT'};
}
Tad: thank you, i will take care in future.
------------------------------
Date: Fri, 17 Apr 2009 13:22:16 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perls popularity
Message-Id: <Xns9BF05F500629asu1cornelledu@127.0.0.1>
"g3rc4n@gmail.com" <g3rc4n@gmail.com> wrote in
news:4b7b9910-8c3c-461a-a4d1-650b354bd0e9@w9g2000yqa.googlegroups.com:
> how well is perl doing as a language, how long is it going to be
> around for? not trolling but i've started asking myself questions on
> the benifits in the long run of using perl of unix administration,
> just is it as popular as i originally thought it was???? because my
> mate said it was dying
Yeah, well, opinons differ:
http://xkcd.com/519/
http://www.oreillynet.com/onlamp/blog/2007/08/perl_is_dead_long_live_perl.html
http://www.presicient.com/langjobs.html
http://www.google.com/search?q=perl+dead
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Fri, 17 Apr 2009 08:19:17 -0700 (PDT)
From: "g3rc4n@gmail.com" <g3rc4n@gmail.com>
Subject: Re: perls popularity
Message-Id: <01aea8e3-d6ba-42e5-8936-34283bf6c3fe@z5g2000vba.googlegroups.com>
lol, i think i see why people say it's "dead" now
------------------------------
Date: Fri, 17 Apr 2009 12:53:02 -0400
From: J Kenneth King <james@agentultra.com>
Subject: Re: perls popularity
Message-Id: <87eivr8bo1.fsf@agentultra.com>
"g3rc4n@gmail.com" <g3rc4n@gmail.com> writes:
> how well is perl doing as a language, how long is it going to be
> around for? not trolling but i've started asking myself questions on
> the benifits in the long run of using perl of unix administration,
> just is it as popular as i originally thought it was???? because my
> mate said it was dying
+1 flamebait
use it or don't.
------------------------------
Date: Fri, 17 Apr 2009 14:09:05 -0400
From: "darkon" <darkon.tdo@gmail.com>
Subject: Re: perls popularity
Message-Id: <Joudnb7_7IdcWHXUnZ2dnUVZ_rKdnZ2d@supernews.com>
<g3rc4n@gmail.com> wrote in message
news:4b7b9910-8c3c-461a-a4d1-650b354bd0e9@w9g2000yqa.googlegroups.com...
> how well is perl doing as a language, how long is it going to be
> around for? not trolling but i've started asking myself questions on
> the benifits in the long run of using perl of unix administration,
> just is it as popular as i originally thought it was???? because my
> mate said it was dying
(andecdote/not-data alert)
I use Perl almost every day, just not for web programming. At least not
directly. Most of my uses are for short utility programs that I write
quickly then then throw away, but without Perl some tasks would take me much
longer, sometime by several orders of magnitude. It's my pocketknife,
screwdriver, hammer, wrench set, and other assorted tools all in one. If I
were working in a Unix environment it might not be as necessary, but since
I'm confined to Windows, Perl is a lifesaver. (And I'm not looking for a
job to get away from Windows, because I have job security and a good salary.
With the economy the way it is, I'd be stupid to walk away from that just to
work with Unix.)
------------------------------
Date: Fri, 17 Apr 2009 11:33:01 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: perls popularity
Message-Id: <acf1fd59-3c01-4b73-bfa0-acbcc8089ba1@f19g2000yqo.googlegroups.com>
On Apr 17, 6:56=A0am, "g3r...@gmail.com" <g3r...@gmail.com> wrote:
> how well is perl doing as a language, how long is it going to be
> around for? not trolling but i've started asking myself questions on
> the benifits in the long run of using perl of unix administration,
> just is it as popular as i originally thought it was???? because my
> mate said it was dying
Is COBOL dead? Something like 80% of all financial software is written
on COBOL and California famously could not alter its payroll because
the software was written in COBOL and the state had no one to modify
it.
Is ADA dead? Go talk to the good folks in Huntsville, Ala.
Is C dead? or FORTRAN? or assembly? Go talk to the EEs.
I'm a database guy working for a large state university, and I write
Perl every day because my job requires a lot of database stuff, a lot
of data and file manipulation, and a fair amount of web programming.
Perl is optimized for all these things.
If you work in a GUI shop, Perl might well be dead. If you are a web
developer and use Adobe or .NET technology, Perl might well be dead.
Regardless, my suggestion is to acquire proficiency in several
languages and use whatever you need. From where I sit, I would
suggest:
Perl
Java
Javascript
PHP or ColdFusion
SQL
bash or PowerShell
You won't go wrong picking up other language skills, whether it be old
warhorses like Lisp or FORTRAN, or young upstarts like Erlang or
Clojure.
My $.02 worth, CC.
------------------------------
Date: Fri, 17 Apr 2009 17:50:31 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: Recognizing a regex reference
Message-Id: <1239983452.91930@proxy.dienste.wien.at>
"Ben Morrow":
> It is in fact performed inside sv.c:Perl_sv_2pv_flags, and the code
> apparently
> requires the SV to be an object as well as to carry 'r' magic: I don't
> know why.
There is an internal Regexp::DESTROY method. I don't know its purpose,
but I think it wouldn't be called for a qr// scalar if the scalar wouldn't
be
blessed.
Greetings, Ferry
--
Ing. Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: ferdinand.bolhar-nordenkampf@wien.gv.at
------------------------------
Date: Fri, 17 Apr 2009 17:31:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Recognizing a regex reference
Message-Id: <ugnmb6-tnt2.ln1@osiris.mauzo.dyndns.org>
Quoth "Ferry Bolhar" <bol@adv.magwien.gv.at>:
> "Ben Morrow":
> > It is in fact performed inside sv.c:Perl_sv_2pv_flags, and the code
> > apparently
> > requires the SV to be an object as well as to carry 'r' magic: I don't
> > know why.
>
> There is an internal Regexp::DESTROY method. I don't know its purpose,
> but I think it wouldn't be called for a qr// scalar if the scalar wouldn't
> be
> blessed.
It does precisely nothing. It was added to prevent
sub UNIVERSAL::DESTROY { qr/x/ }
from causing infinite recursion (why anyone would think defining
UNIVERSAL::DESTROY would be a good idea is quite beyond me). If the
scalar weren't blessed there wouldn't be a problem, since Perl wouldn't
be looking for a DESTROY method in any case: the actual destruction of
the compiled regex is accomplished by a destructor on the 'r' magic
itself, which prevents reblessing from causing a memory leak.
Ben
------------------------------
Date: Fri, 17 Apr 2009 17:08:02 GMT
From: markhobley@hotpop.donottypethisbit.com (Mark Hobley)
Subject: Replacing text containing parenthesis
Message-Id: <hlomb6-t0p.ln1@neptune.markhobley.yi.org>
Keywords: replace,replacing,text,brackets,regular,expression,perl,parenthesis,bananas
I am using perl as a find and replace tool. I want to replace the following
text with a null:
$(srcdir)/config/override.m4
I tried the following:
find ./ -name Makefile.in -exec perl -pi -e \
"s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;" {} \;
Unfortunately, this gives an error:
Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE top_srcdir\)/\.\./ \
config/override\.m4/ at -e line 1, <> line 1.
I guess that the brackets are being evaluated first, and being treated as part
of the expression.
How do I represent literal brackets within the expression?
Mark.
--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
------------------------------
Date: Fri, 17 Apr 2009 18:21:01 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Replacing text containing parenthesis
Message-Id: <Xns9BF091F72812Fasu1cornelledu@127.0.0.1>
markhobley@hotpop.donottypethisbit.com (Mark Hobley) wrote in
news:hlomb6-t0p.ln1@neptune.markhobley.yi.org:
> I am using perl as a find and replace tool. I want to replace the
> following text with a null:
>
> $(srcdir)/config/override.m4
>
> I tried the following:
>
> find ./ -name Makefile.in -exec perl -pi -e \
> "s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;" {} \;
>
> Unfortunately, this gives an error:
>
> Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE
> top_srcdir\)/\.\./ \ config/override\.m4/ at -e line 1, <> line 1.
>
> I guess that the brackets are being evaluated first, and being treated
> as part of the expression.
No. The shell gets to see the string first, replacing \$\( with $\(
where $\ is the output record separator.
So, replacing \$\( with \\$\( should work (untested).
Note also that the string you gave:
$(srcdir)/config/override.m4
will not match the pattern you use above.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Fri, 17 Apr 2009 19:17:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Replacing text containing parenthesis
Message-Id: <dmtmb6-tiu2.ln1@osiris.mauzo.dyndns.org>
Keywords: replace,replacing,text,brackets,regular,expression,perl,parenthesis,bananas
Quoth markhobley@hotpop.donottypethisbit.com (Mark Hobley):
> I am using perl as a find and replace tool. I want to replace the following
> text with a null:
ITYM 'an empty string'. 'A null' usually means "\0".
> $(srcdir)/config/override.m4
>
> I tried the following:
>
> find ./ -name Makefile.in -exec perl -pi -e \
> "s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;" {} \;
>
> Unfortunately, this gives an error:
>
> Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE top_srcdir\)/\.\./ \
> config/override\.m4/ at -e line 1, <> line 1.
>
> I guess that the brackets are being evaluated first, and being treated as part
> of the expression.
Nope. You're falling foul of double-interpolation. First the shell
expands the double-quoted string, treats the "\$" as an escaped $, and
leaves the other backwacks alone. So find gets
s/$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;
as its eighth argument, which it duly passes along to perl. Perl
interprets the initial "$\" in the expression as a request to
interpolate the $\ variable, which is currently empty, and then tries to
compile a regex with an unmatched paren.
Using single quotes for the shell will remove one level of
interpolation, and make things simpler. Using alternative delimiters for
the s/// will help get rid of some of those backwacks, and using \Q will
get rid of most of the rest:
... -e 's!\Q\$(top_srcdir)/../config/override.m4!!g;' \;
(Oddly, that \ on the \$ isn't actually necessary; it seems it's getting
caught by the code that does this:
$ in pattern could be $foo or could be tail anchor. Assumption:
it's a tail anchor if $ is the last thing in the string, or if it's
followed by one of "()| \r\n\t"
as it doesn't realise it's already inside a \Q. Sometimes I really hate
perl's habit of doing so much inside the lexer...)
Ben
------------------------------
Date: Fri, 17 Apr 2009 11:23:49 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Replacing text containing parenthesis
Message-Id: <YO3Gl.73601$9t6.27885@newsfe10.iad>
Mark Hobley wrote:
> I am using perl as a find and replace tool. I want to replace the following
> text with a null:
>
> $(srcdir)/config/override.m4
>
> I tried the following:
>
> find ./ -name Makefile.in -exec perl -pi -e \
> "s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;" {} \;
>
> Unfortunately, this gives an error:
>
> Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE top_srcdir\)/\.\./ \
> config/override\.m4/ at -e line 1, <> line 1.
Your string:
"s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;"
is in double quotes so it is interpolated by the shell first.
Run:
echo "s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;"
from the shell to see how the shell interpolates it.
You probably want to use single quotes instead of double quotes.
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
------------------------------
Date: Fri, 17 Apr 2009 20:08:03 GMT
From: markhobley@hotpop.donottypethisbit.com (Mark Hobley)
Subject: Re: Replacing text containing parenthesis
Message-Id: <713nb6-p2p.ln1@neptune.markhobley.yi.org>
John W. Krahn <someone@example.com> wrote:
> Run:
>
> echo "s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;"
> from the shell to see how the shell interpolates it.
Hmmm, it appeared to be ok ...
echo "s/\$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;"
s/$\(top_srcdir\)\/\.\.\/config\/override\.m4//g;
However, you are right about those double quotes. I will try that, and see
what happens.
Mark.
--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
------------------------------
Date: Fri, 17 Apr 2009 20:08:03 GMT
From: markhobley@hotpop.donottypethisbit.com (Mark Hobley)
Subject: Re: Replacing text containing parenthesis
Message-Id: <993nb6-p2p.ln1@neptune.markhobley.yi.org>
Ben Morrow <ben@morrow.me.uk> wrote:
> Using single quotes for the shell will remove one level of
> interpolation, and make things simpler. Using alternative delimiters for
> the s/// will help get rid of some of those backwacks, and using \Q will
> get rid of most of the rest:
>
> ... -e 's!\Q\$(top_srcdir)/../config/override.m4!!g;' \;
That is interesting. What is the capital Q?
Mark.
--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
------------------------------
Date: Fri, 17 Apr 2009 11:06:09 -0700 (PDT)
From: tandon.sourabh@gmail.com
Subject: Specifyig username and password in PERL
Message-Id: <d9cbc9e0-379b-4790-8818-f54d72e760cb@u39g2000pru.googlegroups.com>
Is there a way to navigate through a secure website (https) where I
have the username and password? I know the exact URL but do not know
how to specify the username and password in the PERL script so that
the website allows me in.
------------------------------
Date: Fri, 17 Apr 2009 19:20:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Specifyig username and password in PERL
Message-Id: <7stmb6-tiu2.ln1@osiris.mauzo.dyndns.org>
Quoth tandon.sourabh@gmail.com:
> Is there a way to navigate through a secure website (https) where I
> have the username and password? I know the exact URL but do not know
> how to specify the username and password in the PERL script so that
> the website allows me in.
LWP::Mechanize. Be sure the website's Terms of Service allow you to do
this before you begin.
Ben
------------------------------
Date: Fri, 17 Apr 2009 20:22:41 +0200
From: News123 <news123@free.fr>
Subject: Re: using SSH without modules
Message-Id: <49e8c8f2$0$24007$426a34cc@news.free.fr>
Tad J McClellan wrote:
>>> What is wrong with modules?> Nene <rodbass63@gmail.com> wrote:
>> I, personally, love modules.
>
>
>> But my manager doesn't.
>
>
I have some potential explications about why some people try to avoid
modules:
In big companies the assumption that perl is installed in the companies
network is installed can be made.
A certain minimal perl version can also be assumed.
Companies have often networks with mixed with solaris / linux / HP-UX /
(Windows)
Many companies manage to have such a 'smart' setup, that about 90 % of
all programs of the type "./configure ; make ; make install" do not compile.
In these setup compiling a perl module which contains C-code can be a
night mare.
Additionally every perl module with C code has to be compiled for all
existing platforms.
Firewalls, that don't allow to access CPAN directly and the fact, that
some modules have a quite impressive dependency tree are another factor.
part of the plain perl)
Many users are not smart enough to download and install perl modules in
sach a pretty setup.
The fact, that some companies don't give root privileges to users and
that perl modules can therefore not be installed in the default paths
doesn't help either.
If on the other hand somebody distributes a small perl script or a small
tar file with perl only code and it is written halfways clean, then he
code is reusable across many platforms and can be installed by almost
anybody.
Of course there might be suggestions like.
distributing root privileges, sticking to standard linux distributions,
etc. but don't believe seriously, that you manager and all the other
managers of the other teams and sites would accept such simple solutions.
Almost every time I wrote a perl script, which depends on modules, which
are not distributed with every perl releaseI had to do remote nanying to
make the scripts work for others.
perl only code on the other hand travels quite easily.
Just some thoughts.
Perhaps one solution would be to add more modules to the standard perl
distribution.
For all perl code, that I write for myself I try to use as many modules
as possible.
It's always more fun to concentrate on something new and not to
er-invent the wheel.
bye
N
------------------------------
Date: Fri, 17 Apr 2009 17:43:56 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: What does `my' do?!
Message-Id: <1239983056.707242@proxy.dienste.wien.at>
"Ilya Zakharevich":
>I managed to confuse myself in a teaspoon... Consider
>
> perl -wle "my $x; BEGIN{ $x=12 } print $x"
> 12
>
> I would expect it to warn that $x is uninitialized, and print
> nothing. The reasoning goes like that:
>
> AT COMPILE TIME:
> `my' is seen; after this $x is considered as lexical
> BEGIN is compiled and executed; $x becomes 12
> `print' is compiled
>
> AT RUN TIME
> `my' is executed. [*] Variable $x becomes undef
> `print' is executed
>
> Apparently, [*]-action is not executed in this context. The question
> is: why? Is it documented?
I think there is confusion about the term "executed" in conjunction with
"my". You have a misunderstanding of how the run-time part of "my" is
implemented.
The run-time effect of "my" is that it marks the variable to be cleared
at the end of the current scope. That's all.
In your example, the "current scope" is the file (here: -e) scope. The $x
is marked to be cleared when this scope is leaved. Next, you have an inner
scope (the BEGIN block). Because of the BEGIN, the assignment occurs
immediately after compilation, but this is meaningless here. You would
archive the same result without BEGIN. Last, the variable is printed.
And finally, the variable is cleared (set to 'undef'), but because your code
ends here, you'll never see this.
So your text must be changed:
AT RUN TIME:
'my' is executed. Variable $x is marked for deletion
'print' is executed
Scope end is reached, variable $x is set to undef.
Greetings, Ferry
--
Ing. Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: ferdinand.bolhar-nordenkampf@wien.gv.at
> Puzzled,
> Ilya
------------------------------
Date: Fri, 17 Apr 2009 18:04:37 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: What does `my' do?!
Message-Id: <1239984297.588051@proxy.dienste.wien.at>
"Ilya Zakharevich":
> perl -wle "eval shift; delayed()" "my $x; $x=12; sub delayed {print $x}"
> 12
>
> *After* `eval' is executed, the scope of $ARGV[0] is exited. But as
> you see (and this is *very expected*), $x is not cleared on scope
> exit.
Yor code example represents a closure wherein the value of a lexical
variable declared outside of its scope gets captured. As usual, $x is
cleared at the end of the scope of $ARGV[0], but the copy in the
closure still keeps its value. Therefore, you can access it whenever
you call the closure. That's the reason why your example works.
But $x is nevertheless deleted at the end of the scope!
Greetings, Ferry
--
Ing. Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: ferdinand.bolhar-nordenkampf@wien.gv.at
------------------------------
Date: Fri, 17 Apr 2009 17:35:03 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: What does `my' do?!
Message-Id: <nmnmb6-tnt2.ln1@osiris.mauzo.dyndns.org>
Quoth "Ferry Bolhar" <bol@adv.magwien.gv.at>:
> "Ilya Zakharevich":
>
> > perl -wle "eval shift; delayed()" "my $x; $x=12; sub delayed {print $x}"
> > 12
> >
> > *After* `eval' is executed, the scope of $ARGV[0] is exited. But as
> > you see (and this is *very expected*), $x is not cleared on scope
> > exit.
>
> Yor code example represents a closure wherein the value of a lexical
> variable declared outside of its scope gets captured. As usual, $x is
> cleared at the end of the scope of $ARGV[0], but the copy in the
> closure still keeps its value. Therefore, you can access it whenever
> you call the closure. That's the reason why your example works.
No. People seem to keep making this mistake. Named subs are *not*
closures in Perl 5, they simply keep a ref to all the variables they
reference.
> But $x is nevertheless deleted at the end of the scope!
$x is nevertheless SvREFCNT_dec'd at the end of the scope. Since it's
refcount hasn't yet reached zero, it isn't freed yet.
Ben
------------------------------
Date: Fri, 17 Apr 2009 16:53:44 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: What does `my' do?!
Message-Id: <gsac6o$2gv$1@reader1.panix.com>
In article <1239983056.707242@proxy.dienste.wien.at>,
Ferry Bolhar <bol@adv.magwien.gv.at> wrote:
>"Ilya Zakharevich":
>
>>I managed to confuse myself in a teaspoon... Consider
>>
>> perl -wle "my $x; BEGIN{ $x=12 } print $x"
>> 12
>>
>> I would expect it to warn that $x is uninitialized, and print
>> nothing. The reasoning goes like that:
>>
>> AT COMPILE TIME:
>> `my' is seen; after this $x is considered as lexical
>> BEGIN is compiled and executed; $x becomes 12
>> `print' is compiled
>>
>> AT RUN TIME
>> `my' is executed. [*] Variable $x becomes undef
>> `print' is executed
>>
>> Apparently, [*]-action is not executed in this context. The question
>> is: why? Is it documented?
>
>I think there is confusion about the term "executed" in conjunction with
>"my". You have a misunderstanding of how the run-time part of "my" is
>implemented.
>
>The run-time effect of "my" is that it marks the variable to be
>cleared at the end of the current scope. That's all.
To clarify, "that's all" in this example. The other run-time effect
of "my" is that, if there be an initial value supplied (for example,
on the right-hand side of "="), this assignment would be done at run
time. (Ilya was expecting that, if there be no right-hand side, it
would be set to undef, which is apparently not so.)
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Fri, 17 Apr 2009 18:48:45 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: What does `my' do?!
Message-Id: <t0smb6-h7u2.ln1@osiris.mauzo.dyndns.org>
Quoth tmcd@panix.com:
> In article <1239983056.707242@proxy.dienste.wien.at>,
> Ferry Bolhar <bol@adv.magwien.gv.at> wrote:
> >"Ilya Zakharevich":
> >
> >>I managed to confuse myself in a teaspoon... Consider
> >>
> >> perl -wle "my $x; BEGIN{ $x=12 } print $x"
> >> 12
> >>
> >> I would expect it to warn that $x is uninitialized, and print
> >> nothing. The reasoning goes like that:
> >>
> >> AT COMPILE TIME:
> >> `my' is seen; after this $x is considered as lexical
> >> BEGIN is compiled and executed; $x becomes 12
> >> `print' is compiled
> >>
> >> AT RUN TIME
> >> `my' is executed. [*] Variable $x becomes undef
> >> `print' is executed
> >>
> >> Apparently, [*]-action is not executed in this context. The question
> >> is: why? Is it documented?
> >
> >I think there is confusion about the term "executed" in conjunction with
> >"my". You have a misunderstanding of how the run-time part of "my" is
> >implemented.
> >
> >The run-time effect of "my" is that it marks the variable to be
> >cleared at the end of the current scope. That's all.
>
> To clarify, "that's all" in this example. The other run-time effect
> of "my" is that, if there be an initial value supplied (for example,
> on the right-hand side of "="), this assignment would be done at run
> time. (Ilya was expecting that, if there be no right-hand side, it
> would be set to undef, which is apparently not so.)
What? No. Perl is not C, and doesn't have a concept of 'initialization'
distinct from ordinary assignment. Any assignment to a newly created
lexical is executed when control flow reaches that point at runtime,
just as with any other expression.
Ben
------------------------------
Date: Fri, 17 Apr 2009 18:06:50 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: What does `my' do?!
Message-Id: <gsagfq$d27$1@reader1.panix.com>
In article <t0smb6-h7u2.ln1@osiris.mauzo.dyndns.org>,
Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth tmcd@panix.com:
>> In article <1239983056.707242@proxy.dienste.wien.at>,
>> Ferry Bolhar <bol@adv.magwien.gv.at> wrote:
>> >"Ilya Zakharevich":
>> >
>> >>I managed to confuse myself in a teaspoon... Consider
>> >>
>> >> perl -wle "my $x; BEGIN{ $x=12 } print $x"
>> >> 12
>> >>
>> >> I would expect it to warn that $x is uninitialized, and print
>> >> nothing. The reasoning goes like that:
>> >>
>> >> AT COMPILE TIME:
>> >> `my' is seen; after this $x is considered as lexical
>> >> BEGIN is compiled and executed; $x becomes 12
>> >> `print' is compiled
>> >>
>> >> AT RUN TIME
>> >> `my' is executed. [*] Variable $x becomes undef
>> >> `print' is executed
>> >>
>> >> Apparently, [*]-action is not executed in this context. The question
>> >> is: why? Is it documented?
>> >
>> >I think there is confusion about the term "executed" in conjunction with
>> >"my". You have a misunderstanding of how the run-time part of "my" is
>> >implemented.
>> >
>> >The run-time effect of "my" is that it marks the variable to be
>> >cleared at the end of the current scope. That's all.
>>
>> To clarify, "that's all" in this example. The other run-time effect
>> of "my" is that, if there be an initial value supplied (for example,
>> on the right-hand side of "="), this assignment would be done at run
>> time. (Ilya was expecting that, if there be no right-hand side, it
>> would be set to undef, which is apparently not so.)
>
>What? No. Perl is not C, and doesn't have a concept of
>'initialization' distinct from ordinary assignment. Any assignment to
>a newly created lexical is executed when control flow reaches that
>point at runtime, just as with any other expression.
We appear to be in vehement agreement: anything that looks like
"initialization" in a "my" is not special, but is merely a standard
run-time assignment like any other. (My use of "initial value" may
have been inapt, especially in this example, where it's assigned in
the BEGIN block.)
--
Tim McDaniel, tmcd@panix.com
------------------------------
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 2347
***************************************