[25286] in Perl-Users-Digest
Perl-Users Digest, Issue: 7531 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 17 18:05:54 2004
Date: Fri, 17 Dec 2004 15:05:11 -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, 17 Dec 2004 Volume: 10 Number: 7531
Today's topics:
Re: (quickie) (Aliasing) Possible to get this to work i <tassilo.von.parseval@rwth-aachen.de>
Re: (quickie) (Aliasing) Possible to get this to work i <tassilo.von.parseval@rwth-aachen.de>
[PATTERN MATCHING] <nicolas.vautier@gmail.com>
Re: [PATTERN MATCHING] <xx087@freenet.carleton.ca>
Re: [PATTERN MATCHING] <1usa@llenroc.ude.invalid>
Re: [PATTERN MATCHING] <nicolas.vautier@gmail.com>
Re: [PATTERN MATCHING] <Juha.Laiho@iki.fi>
Re: [PATTERN MATCHING] <nicolas.vautier@gmail.com>
Re: [PATTERN MATCHING] <1usa@llenroc.ude.invalid>
Re: [PATTERN MATCHING] <noreply@gunnar.cc>
Re: [PATTERN MATCHING] <noreply@gunnar.cc>
Re: [PATTERN MATCHING] <1usa@llenroc.ude.invalid>
Re: [PATTERN MATCHING] <1usa@llenroc.ude.invalid>
Re: [PATTERN MATCHING] <1usa@llenroc.ude.invalid>
Re: [PATTERN MATCHING] <noreply@gunnar.cc>
Re: [PATTERN MATCHING] <noreply@gunnar.cc>
Re: [PATTERN MATCHING] <1usa@llenroc.ude.invalid>
Re: [Q] $ARGV, <>, and command-line Perl <nobull@mail.com>
Re: [Q] $ARGV, <>, and command-line Perl <nobull@mail.com>
Re: [Q] $ARGV, <>, and command-line Perl <please_post@nomail.edu>
Re: FAQ 4.36: How can I expand variables in text string nobull@mail.com
Re: How to tell what is using memory <nobull@mail.com>
Re: How to tell what is using memory mjcarman@mchsi.com
Re: HTML Parser <kkeller-usenet@wombat.san-francisco.ca.us>
Re: HTML Parser <mgjv@tradingpost.com.au>
Re: HTML Parser <1usa@llenroc.ude.invalid>
Re: HTML Parser <noreply@gunnar.cc>
Re: replace multiple lines in a file with Perl <tzhai2002@yahoo.com>
Re: replace multiple lines in a file with Perl <1usa@llenroc.ude.invalid>
Re: replace multiple lines in a file with Perl <abigail@abigail.nl>
Re: Requiring perl scripts nobull@mail.com
Re: Static Code Analysis Tools? <nobull@mail.com>
Re: Static Code Analysis Tools? <emschwar@pobox.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 17 Dec 2004 17:46:18 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: (quickie) (Aliasing) Possible to get this to work in strict?
Message-Id: <slrncs63aq.t1.tassilo.von.parseval@localhost.localdomain>
Also sprach Michele Dondi:
> On Thu, 16 Dec 2004 10:03:13 +0100, "Tassilo v. Parseval"
><tassilo.von.parseval@rwth-aachen.de> wrote:
>
>>> aliasing can even be done. Oh, and of course on lexical scope exit it
>>> will "downgrade" to a simple copy, won't it? (Just tried, and AFAICT
>>> it is indeed so).
>>
>>No, an alias remains an alias. Perl increments the reference-count of
>>the variable to be aliased:
>
> Well, but from the UI-point of view, I mean: it acts in a way that is
> perfectly undistinguishable from a copy, doesn't it?
Yes, quite. There's no way to tell the original from the alias.
>> ethan@ethan:~$ perl -MDevel::Peek
>> { my $c = 42;
>> Dump($c);
>> *alias = \$c;
>> Dump($alias);
>> }
>> Dump($alias);
>> __END__
>> SV = IV(0x8163094) at 0x814cc6c
>> REFCNT = 1
>> FLAGS = (PADBUSY,PADMY,IOK,pIOK)
>> IV = 42
>> SV = IV(0x8163094) at 0x814cc6c
>> REFCNT = 2
>> FLAGS = (PADBUSY,PADMY,IOK,pIOK)
>> IV = 42
>
> I see... but now that I think of it better, examining your example in
> detail, isn't it somewhat contradictory that the *package* variable
> $alias has the PADMY flag set, what that as you explain below should
> mark a lexical variable?
In a way it seems like a contradiction. But on closer inspection it is
not, because you created an alias to a lexical variable. And as there is
no way to distinguish between original and alias (as said above), the
alias must behave just as the original variable. And that includes
refcounting, therefore PADMY.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 17 Dec 2004 18:18:43 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: (quickie) (Aliasing) Possible to get this to work in strict?
Message-Id: <slrncs657j.t1.tassilo.von.parseval@localhost.localdomain>
Also sprach Tassilo v. Parseval:
> Also sprach Michele Dondi:
>
>> On Thu, 16 Dec 2004 10:03:13 +0100, "Tassilo v. Parseval"
>>> ethan@ethan:~$ perl -MDevel::Peek
>>> { my $c = 42;
>>> Dump($c);
>>> *alias = \$c;
>>> Dump($alias);
>>> }
>>> Dump($alias);
>>> __END__
>>> SV = IV(0x8163094) at 0x814cc6c
>>> REFCNT = 1
>>> FLAGS = (PADBUSY,PADMY,IOK,pIOK)
>>> IV = 42
>>> SV = IV(0x8163094) at 0x814cc6c
>>> REFCNT = 2
>>> FLAGS = (PADBUSY,PADMY,IOK,pIOK)
>>> IV = 42
>>
>> I see... but now that I think of it better, examining your example in
>> detail, isn't it somewhat contradictory that the *package* variable
>> $alias has the PADMY flag set, what that as you explain below should
>> mark a lexical variable?
>
> In a way it seems like a contradiction. But on closer inspection it is
> not, because you created an alias to a lexical variable. And as there is
> no way to distinguish between original and alias (as said above), the
> alias must behave just as the original variable. And that includes
> refcounting, therefore PADMY.
When thinking about that a little further, this explanation is
misleading. It implies that perl would internally do additional work to
ensure that both the original and the alias have the same flags. This is
not the case. Perl merely copies the pointer to the original variable
into the alias, and that is the explanation why even a package variable
can have the flags of a lexical. This is easier to understand when
looking at what happens on the C level (simplified):
SV *lexical; /* gets initialized somewhere below */
...
SV *alias = lexical;
SvREFCNT_inc(lexical);
'lexical' and 'alias' point to the same memory address in which all the
flags, slots (such as IV, NV, PV, ...), refcount field etc. are stored.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 17 Dec 2004 11:14:23 -0800
From: "Nicolas Vautier" <nicolas.vautier@gmail.com>
Subject: [PATTERN MATCHING]
Message-Id: <1103310863.092409.215790@f14g2000cwb.googlegroups.com>
Hey guys,
Let's say that I have this:
$line =~ s/$pattern/$replacement/;
It should find every $pattern in $line and replace it by $replacement
right?
But since I have characters such as "|", """, "'", "!", "?" in my
strings, it has a very strange behavior.
Is there any way to specify perl NOT TO USE regular expressions in my
example?
Thanks for your help,
Nico
------------------------------
Date: 17 Dec 2004 19:25:23 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: [PATTERN MATCHING]
Message-Id: <slrncs6cl3.gja.xx087@smeagol.ncf.ca>
At 2004-12-17 02:14PM, Nicolas Vautier <nicolas.vautier@gmail.com> wrote:
> Let's say that I have this:
>
> $line =~ s/$pattern/$replacement/;
>
> It should find every $pattern in $line and replace it by $replacement
> right?
>
> But since I have characters such as "|", """, "'", "!", "?" in my
> strings, it has a very strange behavior.
>
> Is there any way to specify perl NOT TO USE regular expressions in my
> example?
perldoc -f quotemeta
$line =~ s/\Q$pattern/$replacement';
--
Glenn Jackman
glennj@ncf.ca
------------------------------
Date: 17 Dec 2004 19:26:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [PATTERN MATCHING]
Message-Id: <Xns95C292D9C11E6asu1cornelledu@132.236.56.8>
"Nicolas Vautier" <nicolas.vautier@gmail.com> wrote in
news:1103310863.092409.215790@f14g2000cwb.googlegroups.com:
Subject: [PATTERN MATCHING]
Please don't shout.
> Let's say that I have this:
>
> $line =~ s/$pattern/$replacement/;
>
> It should find every $pattern in $line and replace it by $replacement
> right?
>
> But since I have characters such as "|", """, "'", "!", "?" in my
> strings, it has a very strange behavior.
See
perldoc perlop
> Is there any way to specify perl NOT TO USE regular expressions in my
> example?
Sure you could do search and replace without regular expressions but it
would be very tedious and bug prone. Why do you want to do that?
Sinan
------------------------------
Date: 17 Dec 2004 11:36:00 -0800
From: "niko" <nicolas.vautier@gmail.com>
Subject: Re: [PATTERN MATCHING]
Message-Id: <1103312160.501287.309130@f14g2000cwb.googlegroups.com>
That's exactly what I want to do.
Not using regular expressions.
Because in the example, when $pattern="super.test?\nothin" and
$replacement="another?greatte\st", it obviously doesn't work properly.
Thanks for your reply,
Nico
------------------------------
Date: Fri, 17 Dec 2004 19:35:58 +0000 (UTC)
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: [PATTERN MATCHING]
Message-Id: <cpvceu$k0h$2@ichaos.ichaos-int>
"Nicolas Vautier" <nicolas.vautier@gmail.com> said:
>Let's say that I have this:
>
>$line =~ s/$pattern/$replacement/;
>
>It should find every $pattern in $line and replace it by $replacement
>right?
>
>But since I have characters such as "|", """, "'", "!", "?" in my
>strings, it has a very strange behavior.
>
>Is there any way to specify perl NOT TO USE regular expressions in my
>example?
I think you're after \Q and \E - as in
$line =~ s/\Q$pattern\E/$replacement/;
See 'perldoc perlre' for explanation.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: 17 Dec 2004 11:41:37 -0800
From: "niko" <nicolas.vautier@gmail.com>
Subject: Re: [PATTERN MATCHING]
Message-Id: <1103312497.621813.9470@f14g2000cwb.googlegroups.com>
> > Is there any way to specify perl NOT TO USE regular expressions in
my
> > example?
>
> Sure you could do search and replace without regular expressions but
it
> would be very tedious and bug prone. Why do you want to do that?
>
Because my two strings contain characters used in regular expressions
such as ?.|\ ...
What could make perl considering those characters as characters like
others?
Thx,
Nico
------------------------------
Date: 17 Dec 2004 19:48:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [PATTERN MATCHING]
Message-Id: <Xns95C296A3C10D0asu1cornelledu@132.236.56.8>
"niko" <nicolas.vautier@gmail.com> wrote in news:1103312160.501287.309130
@f14g2000cwb.googlegroups.com:
> That's exactly what I want to do.
> Not using regular expressions.
> Because in the example, when $pattern="super.test?\nothin" and
> $replacement="another?greatte\st", it obviously doesn't work properly.
No, it looks like what you want to do is keep using regular expressions but
have some special characters not be special.
Based on your problem description, I am not sure you want those double-
quotes in
my $pattern="super.test?\nothin";
either.
Please do read
perldoc perlop
Sinan
------------------------------
Date: Fri, 17 Dec 2004 21:45:20 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [PATTERN MATCHING]
Message-Id: <32gvblF3np8n6U1@individual.net>
Nicolas Vautier wrote:
> Let's say that I have this:
>
> $line =~ s/$pattern/$replacement/;
>
> It should find every $pattern in $line and replace it by $replacement
> right?
No, it should find *the first occurrence of* $pattern in $line and
replace it. You need the /g modifier to replace *every* of something.
> But since I have characters such as "|", """, "'", "!", "?" in my
> strings, it has a very strange behavior.
>
> Is there any way to specify perl NOT TO USE regular expressions in my
> example?
Others have pointed you to this solution:
$line =~ s/\Q$pattern/$replacement/;
which makes the left side of the s/// operator treat $pattern as a
string. OTOH, using the regex engine for searching and replacing strings
is not very efficient, and a combination of the substr() and index()
functions can be used instead:
substr $line, index($line, $pattern), length $pattern, $replacement;
If you actually need multiple substitutions, this would work:
{
local $[ = 1;
while ( my $pos = index $line, $pattern ) {
substr $line, $pos, length $pattern, $replacement;
}
}
See "perldoc -f substr" and "perldoc -f index".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 17 Dec 2004 21:48:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [PATTERN MATCHING]
Message-Id: <32gvh6F3np8n6U2@individual.net>
A. Sinan Unur wrote:
> Nicolas Vautier wrote:
>>Is there any way to specify perl NOT TO USE regular expressions in my
>>example?
>
> Sure you could do search and replace without regular expressions but it
> would be very tedious and bug prone.
In what way would searching and replacing *strings* without the regex
engine be "tedious and bug prone"?
See my other post in this thread.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 17 Dec 2004 21:08:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [PATTERN MATCHING]
Message-Id: <Xns95C2A4490E319asu1cornelledu@132.236.56.8>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:32gvh6F3np8n6U2@individual.net:
> A. Sinan Unur wrote:
>> Nicolas Vautier wrote:
>>>Is there any way to specify perl NOT TO USE regular expressions in my
>>>example?
>>
>> Sure you could do search and replace without regular expressions but it
>> would be very tedious and bug prone.
>
> In what way would searching and replacing *strings* without the regex
> engine be "tedious and bug prone"?
Well, I thought of posting a similar routine for the purposes of this
question but then decided against it. While that method works for the
specific case we are talking about, it becomes unwieldy very fast the
moment you introduce even the simplest pattern matching features we take
for granted.
I did not mean to imply, although it does come across that way, that
searching and replacing plain strings is that hard.
However, if you do want an example of a bug with the code you posted:
#! perl
use strict;
use warnings;
my $text = q{I would like to replace Gunnar's name with my name.};
my $search = 'Tad';
my $replace = 'Sinan';
substr $text, index($text, $search), length $search, $replace;
print $text;
__END__
D:\Home>perl s.pl
I would like to replace Gunnar's name with my nameSinan
I know, I know, it is a cheap shot :) But it is a bug nevertheless. You do
need to remember to check if the match actually succeeded.
Sinan.
------------------------------
Date: 17 Dec 2004 21:10:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [PATTERN MATCHING]
Message-Id: <Xns95C2A48112B89asu1cornelledu@132.236.56.8>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:32gvblF3np8n6U1@individual.net:
> If you actually need multiple substitutions, this would work:
>
> {
> local $[ = 1;
> while ( my $pos = index $line, $pattern ) {
> substr $line, $pos, length $pattern, $replacement;
> }
> }
Opps. I did not read this far down in my reply to your other message.
Apologies.
Sinan.
------------------------------
Date: 17 Dec 2004 21:19:45 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [PATTERN MATCHING]
Message-Id: <Xns95C2A61BC8E58asu1cornelledu@132.236.56.8>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns95C2A48112B89asu1cornelledu@132.236.56.8:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
> news:32gvblF3np8n6U1@individual.net:
>
>> If you actually need multiple substitutions, this would work:
>>
>> {
>> local $[ = 1;
>> while ( my $pos = index $line, $pattern ) {
>> substr $line, $pos, length $pattern, $replacement;
>> }
>> }
>
> Opps. I did not read this far down in my reply to your other message.
> Apologies.
On second thought, another cheap shot:
#! perl
use strict;
use warnings;
my $line = 'Sinan';
my $pattern = 'Sinan';
my $replacement = 'A. Sinan Unur';
{
local $[ = 1;
while ( my $pos = index $line, $pattern ) {
substr $line, $pos, length $pattern, $replacement;
}
}
print $line;
__END__
Sinan
------------------------------
Date: Fri, 17 Dec 2004 22:23:13 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [PATTERN MATCHING]
Message-Id: <32h1jkF3k93bmU1@individual.net>
A. Sinan Unur wrote:
> However, if you do want an example of a bug with the code you posted:
>
> #! perl
>
> use strict;
> use warnings;
>
> my $text = q{I would like to replace Gunnar's name with my name.};
>
> my $search = 'Tad';
> my $replace = 'Sinan';
>
> substr $text, index($text, $search), length $search, $replace;
>
> print $text;
>
> __END__
>
> D:\Home>perl s.pl
> I would like to replace Gunnar's name with my nameSinan
>
> I know, I know, it is a cheap shot :)
Not cheap at all. The single substitution variant should better be
something like:
if ( ( my $pos = index $line, $pattern ) >= 0 ) {
substr $line, $pos, length $pattern, $replacement;
}
Thanks for pointing it out!
Btw, the multiple substitution should be:
while ( ( my $pos = index $line, $pattern ) >= 0 ) {
substr $line, $pos, length $pattern, $replacement;
}
to prevent the need to fiddle with the $[ variable.
> But it is a bug nevertheless. You do
> need to remember to check if the match actually succeeded.
Yep.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 17 Dec 2004 22:32:13 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [PATTERN MATCHING]
Message-Id: <32h24kF3n7ercU1@individual.net>
A. Sinan Unur wrote:
> On second thought, another cheap shot:
>
> #! perl
>
> use strict;
> use warnings;
>
> my $line = 'Sinan';
> my $pattern = 'Sinan';
> my $replacement = 'A. Sinan Unur';
>
> {
> local $[ = 1;
> while ( my $pos = index $line, $pattern ) {
> substr $line, $pos, length $pattern, $replacement;
>
> }
> }
>
> print $line;
>
> __END__
Yeah, *that* was cheap. :) Well, I never said you don't need to be
attentive to what you are doing when playing with substr() and index().
Just that it may be more efficient...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 17 Dec 2004 21:51:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [PATTERN MATCHING]
Message-Id: <Xns95C2AB69F1DF9asu1cornelledu@132.236.56.8>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:32h24kF3n7ercU1@individual.net:
> A. Sinan Unur wrote:
>> On second thought, another cheap shot:
...
> Yeah, *that* was cheap. :)
...
I know, I know.
> Well, I never said you don't need to be attentive to what you are doing
> when playing with substr() and index(). Just that it may be more
> efficient...
Mine was just an indirect way of trying to fix the OP's terminology and
also guide him toward a document which he should benefit from by reading in
its entirety.
I suspect that the OP's problem may involve inappropriate (or
inconsistent) use of double quotes as well as failing to quote the regex-
special characters, but this is just a suspicion since the OP did not show
real code and real data.
I did originally think about posting an index/substr based solution but too
many special cases kept pop up in my mind. Then I remembered Sedgewick's
treatment of search and replace in C, and I gave up.
Hope you had fun. I did :)
Sinan.
------------------------------
Date: Fri, 17 Dec 2004 17:23:56 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: [Q] $ARGV, <>, and command-line Perl
Message-Id: <cpv4ei$rhf$1@sun3.bham.ac.uk>
bill wrote:
> In <Xns95C294318E40Felhber1lidotechnet@62.89.127.66> "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net> writes:
>
>
>>bill <please_post@nomail.edu> wrote:
>
>
>>[...]
>
>
>>>Of course the catch could be in that last "non-magical" bit, which
>>>as far as I know is totally undefined crap (i.e. useless
>>>non-documentation). [...]
>
>
>
>>Documentation patches are a great way to contribute to the Perl
>>project. Thanks in advance for yours.
>
>
> I can't possibly produce this patch, since I have no idea what this
> magical/non-magical stuff means. Do you?
Yes, the magicical nature of the *ARGV special variable is explained in
the documentation decribing the *ARGV special varaible. Oddly enough,
when I started to try to help you in this thread which asks questions
about *ARGV the _first_ thing I did was go re-read the relevant
documentation. This was before I actually looked at the code in any
detail and noticed that the print $ARGV was outside the loop.
------------------------------
Date: Fri, 17 Dec 2004 17:25:26 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: [Q] $ARGV, <>, and command-line Perl
Message-Id: <cpv4hb$rhf$2@sun3.bham.ac.uk>
bill wrote:
> BTW, I figured out why I got more than one line to print out in my
> version: I had preceded the perl statement with "find . -type f |
> xargs ".
Yes, I'd already wroked that out.
------------------------------
Date: Fri, 17 Dec 2004 20:06:38 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: [Q] $ARGV, <>, and command-line Perl
Message-Id: <cpve8e$16a$1@reader2.panix.com>
In <cpv4ei$rhf$1@sun3.bham.ac.uk> Brian McCauley <nobull@mail.com> writes:
>bill wrote:
>> In <Xns95C294318E40Felhber1lidotechnet@62.89.127.66> "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net> writes:
>>
>>
>>>bill <please_post@nomail.edu> wrote:
>>
>>
>>>[...]
>>
>>
>>>>Of course the catch could be in that last "non-magical" bit, which
>>>>as far as I know is totally undefined crap (i.e. useless
>>>>non-documentation). [...]
>>
>>
>>
>>>Documentation patches are a great way to contribute to the Perl
>>>project. Thanks in advance for yours.
>>
>>
>> I can't possibly produce this patch, since I have no idea what this
>> magical/non-magical stuff means. Do you?
>Yes, the magicical nature of the *ARGV special variable is explained in
>the documentation decribing the *ARGV special varaible.
Where exactly is that documentation? If I search for ARGV in
perlvar, this is what comes up:
input_line_number HANDLE EXPR
$INPUT_LINE_NUMBER
$NR
$. The current input record number for the last file
handle from which you just read() (or called a
"seek" or "tell" on). The value may be different
from the actual physical line number in the file,
depending on what notion of "line" is in
effect--see $/ on how to change that. An explicit
close on a filehandle resets the line number.
Because "<>" never does an explicit close, line
numbers increase across ARGV files (but see exam
ples in "eof" in perlfunc). Consider this vari
able read-only: setting it does not reposition the
seek pointer; you'll have to do that on your own.
Localizing $. has the effect of also localizing
Perl's notion of "the last read filehandle".
(Mnemonic: many programs use "." to mean the cur
rent line number.)
...
$ARGV contains the name of the current file when reading
from <>.
@ARGV The array @ARGV contains the command-line argu
ments intended for the script. $#ARGV is gener
ally the number of arguments minus one, because
$ARGV[0] is the first argument, not the program's
command name itself. See $0 for the command name.
...
Perl identifiers that begin with digits, control charac
ters, or punctuation characters are exempt from the
effects of the "package" declaration and are always forced
to be in package "main". A few other names are also
exempt:
ENV STDIN
INC STDOUT
ARGV STDERR
ARGVOUT
SIG
That's it. Nothing on magic. Programming Perl 3d ed. says
ARGV
[ALL] The special filehandle that iterates over command-line
filenames in @ARGV. Usually written as the null filehandle
in the angle operator: <>.
No mention of magic here either. Also there's no mention of anything
(whether magic or not) that explains the inconsistency I cited
earlier, namely that a "last" statement in an -ne script doesn't
exit just the inner loop.
bill
------------------------------
Date: 17 Dec 2004 11:06:06 -0800
From: nobull@mail.com
Subject: Re: FAQ 4.36: How can I expand variables in text strings?
Message-Id: <1103310366.506802.24370@z14g2000cwz.googlegroups.com>
brian d foy wrote:
> In article <cpnaof$6c0$1@sun3.bham.ac.uk>, Brian McCauley
> <nobull@mail.com> wrote:
>
> > > That's what I thought too: the input string is beyond our
> > > control and we just get to deal with it.
> >
> > I've made quite a study of this question over the years and in
pratice
> > it is rare that the input is beyond the asker's control.
>
> I must get all the rare cases then, because I run into a lot
> of situations where people don't have control over the whole
> problem.
In general yes. But in the specific case of this question? Are you
sure? Care to back up that assertion?
Can you point to a single case where this question was asked in a
public forum such that:
1) The input format was beyond the control of the asker.
2) The prescribed input format was such that the assuptions made
about the input format in the current FAQ answer are near enough to
being correct to make the answer applicable.
Actually if you can't find one that satisfies both of the above it
would be interesting to know if you can find many that safisfy _either_.
------------------------------
Date: Fri, 17 Dec 2004 17:14:39 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to tell what is using memory
Message-Id: <cpv3t6$r8n$1@sun3.bham.ac.uk>
Nikki R wrote:
> # Suck in the entire Data::Dumper'd file.
> my $filestr = join('', <SOMEFILE>);
> # The Data::Dumper file consists of a statement like:
> # $var1 = {....} ; # Large hash reference.
> eval $filestr;
I've not tested it but I'd expect do() to be possibly more memory
efficient efficient than slurp and eval().
If you do want to slurp the whole file into a string there are more
efficient ways (see FAQ) than sturping it into a list of lines then
joining those lines together.
------------------------------
Date: 17 Dec 2004 13:16:07 -0800
From: mjcarman@mchsi.com
Subject: Re: How to tell what is using memory
Message-Id: <1103318167.611672.102340@f14g2000cwb.googlegroups.com>
Nikki R wrote:
>
> even though all of the 'my' variables go out of scope, Perl doesn't
> normally release any memory back to the operating system until the
> script finishes running.
Correct. Perl will hold on to the memory in case it needs it again
later. Note that data allocated for my() variables will *not* be reused
elsewhere. It is reserved for the original user (in case it comes back
into scope).
> Is there anything I can do about this
A little, maybe. With the restrictions you've imposed you haven't left
much room for us to help you.
> e.g. change the way that the data file is read in? I definitely need
> to use a hash and I don't have the choice of using anything else but
> Data::Dumper (this is part of a large project that I cannot change).
Brian McCauley gave you a suggestion that stays within these
boundaries, but you should consider trying to change this anyway.
Data::Dumper's output is meant to be human readable and eval-able. It
really isn't all that suitable for storing and restoring large data
structures. That's what Storable is for:
* It has very little overhead.
* It creates much smaller data files.
* It's much faster.
If your data file is 10 MB then using Data::Dumper+eval would have *at
least* 10 MB of overhead. (The data structure itself + the string it's
created from.) Storable's overhead is (comparitively) negligable.
If your project is well-architected, the change could be as simple as
changing a few lines of code inside the routines for reading/writing a
data file.
Of course, changing between Data::Dumper and Storable won't make a bit
of difference in how large your data structure is after it's been read
into memory. If that's the real problem you need to try something else
-- maybe tieing the data structure to disk. (This has the side effect
of making it slower to access.)
> Is there also a good way of finding out [...] which variables are
> using how much memory in a Perl script?
Take a look at Devel::Size. If you can't change the data structure,
though, then that information won't be very helpful either.
-mjc
------------------------------
Date: Fri, 17 Dec 2004 08:02:10 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: HTML Parser
Message-Id: <6icb92x9l8.ln2@goaway.wombat.san-francisco.ca.us>
On 2004-12-17, A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> "Asoup" <groups@gevorgian.com> wrote in
> news:1103266133.715414.277400@f14g2000cwb.googlegroups.com:
>> $html get("http://www.yerkir.am/eng/index.php?sub=news_arm&id=11918");
>
> What is this line supposed to do?
The message I read (pre-plonk) went like so:
> $html =
> get("http://www.yerkir.am/eng/index.php?sub=news_arm&id=11918");
Perhaps the = got stripped by your newsreader somehow? *shrug*
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
------------------------------
Date: Sat, 18 Dec 2004 08:55:47 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: HTML Parser
Message-Id: <slrncs6lf3.16a.mgjv@martien.heliotrope.home>
On 17 Dec 2004 13:52:32 GMT,
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> "Asoup" <groups@gevorgian.com> wrote in
> news:1103266133.715414.277400@f14g2000cwb.googlegroups.com:
>>
>> $html get("http://www.yerkir.am/eng/index.php?sub=news_arm&id=11918");
>
> What is this line supposed to do?
That is not what the line looked like in Asoup's original. In fact, it
was two lines, the first pne ending in '='. I think that your newsreader
is incorrectly removing something it thinks is quoted-printable encoding
or so. If I were you, I would fix the newsreader or get another one.
Martien
--
|
Martien Verbruggen | Blessed are the Fundamentalists, for they
| shall inhibit the earth.
|
------------------------------
Date: 17 Dec 2004 22:34:37 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: HTML Parser
Message-Id: <Xns95C2B2CDE723Aasu1cornelledu@132.236.56.8>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote in
news:slrncs6lf3.16a.mgjv@martien.heliotrope.home:
> On 17 Dec 2004 13:52:32 GMT,
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>> "Asoup" <groups@gevorgian.com> wrote in
>> news:1103266133.715414.277400@f14g2000cwb.googlegroups.com:
>>>
>>> $html get("http://www.yerkir.am/eng/index.php?sub=news_arm&id=11918");
>>
>> What is this line supposed to do?
>
> That is not what the line looked like in Asoup's original. In fact, it
> was two lines, the first pne ending in '='. I think that your newsreader
> is incorrectly removing something it thinks is quoted-printable encoding
> or so. If I were you, I would fix the newsreader or get another one.
I am quite happy with XNews, thank you. Looking at the original on Google
shows some funkiness however:
http://tinyurl.com/5zttd
Copied and pasted from the page above:
$output_file =3D "/public_html/rss.txt";
$html =3D
get("http://www.yerkir.am/eng/index.php?sub=3Dnews_arm&id=3D11918");
$formatter =3D HTML::FormatText->new;
$tree_builder =3D HTML::TreeBuilder->new;
I am retracting my comment. I am glad the OP's post showed up properly on
your software.
Sinan.
------------------------------
Date: Fri, 17 Dec 2004 23:49:59 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: HTML Parser
Message-Id: <32h6nvF3o8101U1@individual.net>
Martien Verbruggen wrote:
> I think that your newsreader is incorrectly removing something it
> thinks is quoted-printable encoding or so.
The original message *was* sent quoted-printable encoded, so Sinan's
newsreader rather failed to decode it properly.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 17 Dec 2004 08:57:45 -0800
From: "learner" <tzhai2002@yahoo.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <1103302665.844892.234810@f14g2000cwb.googlegroups.com>
Well, everyone,
I thought the little program I posted is such an simple endeavor
that it would be really obvious for gurus to disect... and then the
"instruction" i gave, which invoke so many ANGRY people. Appologize to
you all!
Peace.
------------------------------
Date: 17 Dec 2004 19:29:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <Xns95C2935ED17B5asu1cornelledu@132.236.56.8>
"learner" <tzhai2002@yahoo.com> wrote in news:1103302665.844892.234810
@f14g2000cwb.googlegroups.com:
> Well, everyone,
> I thought the little program I posted is such an simple endeavor
> that it would be really obvious for gurus to disect... and then the
> "instruction" i gave, which invoke so many ANGRY people.
Because your instructions presumed that the two minutes it would have taken
you to do it right was more valuable than the 30 or so minutes 15 different
people would have spent following your instructions. That is very rude.
> Appologize to you all!
If the apology is sincere, then there might still be hope for you. You can
show that you are sincere by following the posting guidelines in your
future posts.
Sinan.
------------------------------
Date: 17 Dec 2004 22:09:33 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <slrncs6m8t.fj.abigail@alexandra.abigail.nl>
learner (tzhai2002@yahoo.com) wrote on MMMMCXXVI September MCMXCIII in
<URL:news:1103302665.844892.234810@f14g2000cwb.googlegroups.com>:
`` Well, everyone,
`` I thought the little program I posted is such an simple endeavor
`` that it would be really obvious for gurus to disect... and then the
`` "instruction" i gave, which invoke so many ANGRY people. Appologize to
`` you all!
*PLONK*
Abigail
--
What's this? Wabbit season?
------------------------------
Date: 17 Dec 2004 10:48:07 -0800
From: nobull@mail.com
Subject: Re: Requiring perl scripts
Message-Id: <1103309287.153738.266820@z14g2000cwz.googlegroups.com>
Bigus wrote:
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:cporaq$pqp$1@sun3.bham.ac.uk...
> > > If I do a "require login.cgi" in
application.cgi will
> > > it just make the subroutines available or will it attempt to run
all the
> > > code in login.cgi before the subroutines?
> >
> > It will run the code unless you prevent it. It is possible to have
a
> > Perl script that also functions as a Perl4-style library by
checking
> > caller() but I would consider that a poor programming pratice.
> >
> > Migrate the common subroutines to a Perl5-style module and use it
in
> > both scripts.
>
> ok, not got to grips with writing modules yet, but I suppose I could
create
> a script with just subs in it, then pull them into the app or login
script
> via a require and call them as normal.
While Perl5 still supports the Perl4 approach that you describe above I
would think you'd be better off spending a few minutes picking up the
basics of modules. There are pitfalls (pratfalls?) for the non-expert
trying to use the both the Perl4-library and Perl5-module approaches at
the same time. If you do things the Perl5 way from the outset you
largely avoid these pitfalls.
Note: For this purpose running your CGI under mod_perl counts as
creating modules. GCI scripts that are run under mod_perl using
Apache::Registry (or similar) must not require Perl4-style libraries.
This is in fact a slight simplification - a Perl guru could safely do
this with sufficient thought and care.
------------------------------
Date: Fri, 17 Dec 2004 17:44:39 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Static Code Analysis Tools?
Message-Id: <cpv5le$s5p$1@sun3.bham.ac.uk>
Eric Schwartz wrote:
> I was searching through CPAN today for a module that would generate a
> static call tree, but couldn't seem to find one (lots of dynamic call
> tree generators, though!). I'm less concerned with code coverage at
> this point; I'm looking for a module (or tool) that will help me
> refactor code by easily showing me who calls, say, MyMod::Foo.
>
> Does anyone know of such a thing?
Beacuse Perl is not strongly typed it is impossible for static analysis
to resolve method calls.
It's also not possible for static analysis to resolve subroutine calls
through symrefs, run-time aliases or eval().
But subject to those limitations Perl does, as others have pointed out,
come with a static cross-reference tool.
------------------------------
Date: Fri, 17 Dec 2004 11:42:33 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Static Code Analysis Tools?
Message-Id: <etomzwcydeu.fsf@wilson.emschwar>
Brian McCauley <nobull@mail.com> writes:
> Beacuse Perl is not strongly typed it is impossible for static
> analysis to resolve method calls.
That's okay; I'll consider myself successful if I can get everybody to
stick to our coding standards, never mind teaching them OOP. :-)
> It's also not possible for static analysis to resolve subroutine calls
> through symrefs, run-time aliases or eval().
Also true. Thankfully, with the exception of dispatch tables, we have
officially deemed most of those Evil(tm)(c)(r).
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
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 V10 Issue 7531
***************************************