[17823] in Perl-Users-Digest
Perl-Users Digest, Issue: 5243 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 4 21:18:29 2001
Date: Thu, 4 Jan 2001 18:18:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978661086-v9-i5243@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 4 Jan 2001 Volume: 9 Number: 5243
Today's topics:
pushing an array in a for loop? <johngros@Spam.bigpond.net.au>
Re: pushing an array in a for loop? (Martien Verbruggen)
Re: pushing an array in a for loop? <johngros@Spam.bigpond.net.au>
Re: pushing an array in a for loop? <johngros@Spam.bigpond.net.au>
Re: pushing an array in a for loop? <uri@sysarch.com>
Re: pushing an array in a for loop? <johngros@Spam.bigpond.net.au>
Re: pushing an array in a for loop? (Martien Verbruggen)
Re: pushing an array in a for loop? <bart.lateur@skynet.be>
Re: pushing an array in a for loop? (Mark Jason Dominus)
Re: pushing an array in a for loop? (Garry Williams)
Re: pushing an array in a for loop? (Mark Jason Dominus)
Re: pushing an array in a for loop? (Martien Verbruggen)
Re: pushing an array in a for loop? <johngros@Spam.bigpond.net.au>
Question *not quite* answered by the FAQ posting... <feldspar@ix.netcom.com>
Re: Question *not quite* answered by the FAQ posting... <mischief@velma.motion.net>
Re: Question *not quite* answered by the FAQ posting... <mjcarman@home.com>
Re: Question *not quite* answered by the FAQ posting... <feldspar@ix.netcom.com>
Question regarding directory handles <cchiu@credit.erin.utoronto.ca>
Re: Question regarding directory handles <krahnj@acm.org>
Re: Question regarding directory handles (Mark Jason Dominus)
pop-up window problem manon_bertolini@mantacorp.com
Re: pop-up window problem <tony_curtis32@yahoo.com>
Re: pop-up window problem manonb@my-deja.com
Problem with DBI-sorry to send it again <edd@texscene.com>
Re: Problem with DBI-sorry to send it again (Garry Williams)
Re: Problem with DBI-sorry to send it again <joe+usenet@sunstarsys.com>
problem with DST conversion in Time::Local <econ@tamu.edu>
Problem with simple cookie program (Loans2001)
Re: Problem with simple cookie program egwong@netcom.com
Re: Problem with simple cookie program <a.v.a@home.nl>
Re: Problem with simple cookie program <bigrich318@yahoo.com>
Problem with values - simple problem msalerno@my-deja.com
Re: Problem with values - simple problem (Tad McClellan)
Re: Problem with values - simple problem <garryknight@bigfoot.com>
Problem writing temp files from a script called by .for dmarwick@my-deja.com
Problem writing temp files from a script called by .for dmarwick@my-deja.com
Problem writing temp files from a script called by .for david.marwick@barra.com
Re: Problem writing temp files from a script called by <revjack@revjack.net>
Re: Problem writing temp files from a script called by david.marwick@barra.com
Re: Problem writing temp files from a script called by david.marwick@barra.com
Re: Problem writing temp files from a script called by <revjack@revjack.net>
Re: Problem writing temp files from a script called by (Tad McClellan)
Re: Problem writing temp files from a script called by <revjack@revjack.net>
Re: Problems in writing in file ....? (Anno Siegel)
Re: Problems in writing in file ....? nobull@mail.com
Problems using Net:POP3 <don@lclcan.com>
Re: Problems using Net:POP3 <tony_curtis32@yahoo.com>
Proposed FAQ addition (was Re: how to send html mail) (Chris Fedde)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 30 Dec 2000 09:53:29 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: pushing an array in a for loop?
Message-Id: <tgi36.38206$xW4.304765@news-server.bigpond.net.au>
I was wondering if the behaviour of the for loop becomes erratic? Or does it
just push the loop on for more executions?
------------------------------
Date: Sat, 30 Dec 2000 22:52:24 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: pushing an array in a for loop?
Message-Id: <slrn94rj3o.6lr.mgjv@martien.heliotrope.home>
On Sat, 30 Dec 2000 09:53:29 GMT,
John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
> I was wondering if the behaviour of the for loop becomes erratic? Or does it
> just push the loop on for more executions?
What? I think, after reading your message about three times that I know
what you mean, but next time, please try to be a bit more clear. I think
oyu are asking about the following fragment from the documentation:
# man perlsyn
[snip]
Foreach Loops
The `foreach' loop iterates over a normal list value and
sets the variable VAR to be each element of the list in
[snip]
If any part of LIST is an array, `foreach' will get very
confused if you add or remove elements within the loop
body, for example with `splice'. So don't do that.
[snip]
So, do _not_ change the number of elements in the array you're looping
over. Not with push, pop, shift, unshift, or splice.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Sat, 30 Dec 2000 22:14:50 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: pushing an array in a for loop?
Message-Id: <u7t36.38717$xW4.309487@news-server.bigpond.net.au>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn94rj3o.6lr.mgjv@martien.heliotrope.home...
> On Sat, 30 Dec 2000 09:53:29 GMT,
> John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
> > I was wondering if the behaviour of the for loop becomes erratic? Or
does it
> > just push the loop on for more executions?
>
> What? I think, after reading your message about three times that I know
> what you mean, but next time, please try to be a bit more clear. I think
> oyu are asking about the following fragment from the documentation:
>
>
> # man perlsyn
> [snip]
> Foreach Loops
>
> The `foreach' loop iterates over a normal list value and
> sets the variable VAR to be each element of the list in
> [snip]
> If any part of LIST is an array, `foreach' will get very
> confused if you add or remove elements within the loop
> body, for example with `splice'. So don't do that.
> [snip]
>
>
> So, do _not_ change the number of elements in the array you're looping
> over. Not with push, pop, shift, unshift, or splice.
I meant : for ($i = 0; $i = @data - 1 $i += 2 ){
#the 2 is because I will be pushing two values based on previous values of
the array.
I guess I will have to experiment with it because I suspect that the
specific behaviour of the for loop would allow the addition of elements and
still run through them all if the exit condition is right i.e. $i = @data -
1. I was just hoping someone knew for sure it did not just go bananas. But I
think I got confused over the for and foreach, I had read that portion of
perlsyn before when other people had spliced and popped in a foreach.
------------------------------
Date: Sat, 30 Dec 2000 22:25:03 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: pushing an array in a for loop?
Message-Id: <3ht36.38719$xW4.309497@news-server.bigpond.net.au>
"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:u7t36.38717$xW4.309487@news-server.bigpond.net.au...
> I meant : for ($i = 0; $i = @data - 1 $i += 2 ){
How stoopid!
I really meant : for ($i = 0; $i <= @data - 1 $i += 2 ){
------------------------------
Date: Sat, 30 Dec 2000 22:48:35 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: pushing an array in a for loop?
Message-Id: <x7lmsxa5ks.fsf@home.sysarch.com>
>>>>> "JBW" == John Boy Walton <johngros@Spam.bigpond.net.au> writes:
JBW> I really meant : for ($i = 0; $i <= @data - 1 $i += 2 ){
why the -1? just use $i < @data; that is the standard for loop until the
end of an array idiom.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 30 Dec 2000 23:11:37 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: pushing an array in a for loop?
Message-Id: <JYt36.38751$xW4.309505@news-server.bigpond.net.au>
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x7lmsxa5ks.fsf@home.sysarch.com...
> >>>>> "JBW" == John Boy Walton <johngros@Spam.bigpond.net.au> writes:
>
> JBW> I really meant : for ($i = 0; $i <= @data - 1 $i += 2 ){
>
> why the -1? just use $i < @data; that is the standard for loop until the
> end of an array idiom.
I have composed and recomposed this over and over.
Finally I have to agree! Stepping through two or more elements at a time,
still $i < @data; works and therefore is preferable as it is common to all.
And not my complication.
Thanks Uri.
------------------------------
Date: Sun, 31 Dec 2000 11:00:29 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: pushing an array in a for loop?
Message-Id: <slrn94stot.6lr.mgjv@martien.heliotrope.home>
On Sat, 30 Dec 2000 22:14:50 GMT,
John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
>
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn94rj3o.6lr.mgjv@martien.heliotrope.home...
>> On Sat, 30 Dec 2000 09:53:29 GMT,
>> John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
>> > I was wondering if the behaviour of the for loop becomes erratic?
>> > Or does it just push the loop on for more executions?
>> # man perlsyn
>> [snip]
>> Foreach Loops
>> So, do _not_ change the number of elements in the array you're looping
>> over. Not with push, pop, shift, unshift, or splice.
> I meant : for ($i = 0; $i = @data - 1 $i += 2 ){
> #the 2 is because I will be pushing two values based on previous values of
> the array.
I am pretty sure that the @data will be evaluated anew on each
iteration, so there shouldn't be a problem here when you change the
length of the array. I would actually consider it severely broken if
@data didn't get evaluated each time.
> I guess I will have to experiment with it because I suspect that the
> specific behaviour of the for loop would allow the addition of elements and
> still run through them all if the exit condition is right i.e. $i = @data -
Yep. Let's see:
#!/usr/local/bin/perl -wl
use strict;
my @data = (1, 2, 3, 4);
for (my $i = 0; $i < @data; $i += 2)
{
push @data, $i + 5 if $i < 5;
print $data[$i];
}
print join ":", @data;
__END__
1
3
5
9
1:2:3:4:5:7:9
Seems to work OK.
> 1. I was just hoping someone knew for sure it did not just go bananas. But I
> think I got confused over the for and foreach, I had read that portion of
> perlsyn before when other people had spliced and popped in a foreach.
for and foreach are really just the same. It's the bit between the
brackets that makes it different. If you use a loop like you want to,
there is no aliasing of variables going on into the array. The for-loop
doesn't have to keep track of where it was itself. Instead, you are
simply incrementing a number that is unrelated to the array, and you use
that to access elements of the array. A big difference in internal state
maintenance for perl. With
for my $element (@array)
{
}
perl has to keep track of all the info about @array and where it is.
With
for (my $i = 0; $i < @data; $i++)
{
}
Perl doesn't have to keep track of anything. It evaluates 'my $i = 0'
just before the first iteration, '$i < @data' before each iteration, and
'$i++' just after each iteration. It's more or less equivalent to:
my $i = 0;
LABEL:
goto EXIT unless $i < @data;
# code here
$i++;
goto LABEL;
EXIT:
which shows the flow a bit better (but I trust you'll never use the
abhorrent code above), or if you want to express it as a while loop:
my $i = 0;
while ($i < @data)
{
# code here
$i++;
}
Now, you wouldn't expect the while loop to suffer from these problems,
would you? :)
Martien
--
Martien Verbruggen |
Interactive Media Division | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Sun, 31 Dec 2000 01:48:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: pushing an array in a for loop?
Message-Id: <tv3t4tc7mu6s4vf8qk3unvp21sr7rtg09s@4ax.com>
John Boy Walton wrote:
>I was wondering if the behaviour of the for loop becomes erratic? Or does it
>just push the loop on for more executions?
I'm guessing at what you're trying to accomplish... and here's how I
usually do it.
while(@data) {
$_ = shift @data;
... # do stuff with $_
push @data, these_too($_);
}
However, this does destroy the original array. So does pushing new data,
actually. Make a copy of it if you don't like that.
--
Bart.
------------------------------
Date: Sun, 31 Dec 2000 07:44:40 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: pushing an array in a for loop?
Message-Id: <3a4ee3e7.703f$7e@news.op.net>
In article <slrn94rj3o.6lr.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> If any part of LIST is an array, `foreach' will get very
> confused if you add or remove elements within the loop
> body, for example with `splice'. So don't do that.
It says that, but it's being overconservative. The behavior if you
change the array inside the loop is very simple: On the nth iteration,
you get the nth array element, whatever it happens to be at the moment
that the iteration commences. The loop terminates the first time that
n is off the end of the array.
It's also overconservative about changing a hash inside an 'each'
loop. It says not to delete elements from the hash, even though the
'delete' function is very careful to make sure that this will always
work, and the hash structure has a special data member whose only
purpose is to make this work.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sun, 31 Dec 2000 09:08:58 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: pushing an array in a for loop?
Message-Id: <KIC36.52$Dm5.3640@eagle.america.net>
On Sun, 31 Dec 2000 07:44:40 GMT, Mark Jason Dominus <mjd@plover.com>
wrote:
>In article <slrn94rj3o.6lr.mgjv@martien.heliotrope.home>,
>Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> If any part of LIST is an array, `foreach' will get very
>> confused if you add or remove elements within the loop
>> body, for example with `splice'. So don't do that.
...
>It's also overconservative about changing a hash inside an 'each'
>loop. It says not to delete elements from the hash, even though the
>'delete' function is very careful to make sure that this will always
>work, and the hash structure has a special data member whose only
>purpose is to make this work.
Yes and that got me into trouble once when I extended that observation
to a *tied* (NDBM) hash. Beware.
--
Garry Williams
------------------------------
Date: Sun, 31 Dec 2000 16:18:10 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: pushing an array in a for loop?
Message-Id: <3a4f5c41.ee7$6d@news.op.net>
In article <KIC36.52$Dm5.3640@eagle.america.net>,
Garry Williams <garry@zvolve.com> wrote:
>that got me into trouble once when I extended that observation
>to a *tied* (NDBM) hash. Beware.
Tied hashes *always* have a 'beware'. You can't depend on being able
to delete inside of an 'each' loop, but you can't depend on being able
to delete at all, or even on being able to fetch or store. With a tied
hash, all bets are off.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Mon, 1 Jan 2001 16:37:21 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: pushing an array in a for loop?
Message-Id: <slrn9505sh.6lr.mgjv@martien.heliotrope.home>
On Sun, 31 Dec 2000 07:44:40 GMT,
Mark Jason Dominus <mjd@plover.com> wrote:
> In article <slrn94rj3o.6lr.mgjv@martien.heliotrope.home>,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> If any part of LIST is an array, `foreach' will get very
>> confused if you add or remove elements within the loop
>> body, for example with `splice'. So don't do that.
>
>
> It says that, but it's being overconservative. The behavior if you
> change the array inside the loop is very simple: On the nth iteration,
> you get the nth array element, whatever it happens to be at the moment
> that the iteration commences. The loop terminates the first time that
> n is off the end of the array.
But a few CPU cycles could probably be saved by not testing for this (I
am now assuming that for each iteration perl tests whether the next
element it wants to serve still exists, instead of just blindlysetting
up counters before the first iteration, and keeping going until they are
all done. The test would be more expensive than just a simple loop).
I am not saying that that is wise, but if at some point someone decides
that it's necessary to make these loops slightly faster, then something
like:
@a = (1, 2, 3, 4);
for (@a)
{
@a = () if $_ == 2;
print;
}
Could suddenly stop working, or would work in a different manner, or
could potentially even dump core (although that should be considered a
bug, I guess).
> It's also overconservative about changing a hash inside an 'each'
> loop. It says not to delete elements from the hash, even though the
> 'delete' function is very careful to make sure that this will always
> work, and the hash structure has a special data member whose only
> purpose is to make this work.
*nod*
But what you are describing is the behaviour of Perl at this moment in
time. I don't know whether it has always behaved like this, but a
warning like that in the documentation tells me not to reply on the
behaviour staying the same in the future. This is sort of related to my
post of a few days ago (<slrn94t0o9.6lr.mgjv@martien.heliotrope.home>),
in which I state that Perl is still lacking a formal language
definition, which means that the doucmentation and the implementation
together define how Perl operates (this was related to the order in
which map() and grep() process their arguments). I should maybe add to
that post that I tend to believe that the documentation should be
followed when it is explicit, and the implementation should only be used
as a reference when the documentation is silent or ambiguous.
I know the documentation isn't always entirely up to date, and
sometimes contains errors, but at least a caveat like this one shows me
that the p5p (or someone) wants to reserve the right to change the
implementation in drastic ways that might change the way in which a for
loop can or can't deal with growing or shrinking arrays.
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: Tue, 02 Jan 2001 04:21:47 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: pushing an array in a for loop?
Message-Id: <vHc46.41262$xW4.331436@news-server.bigpond.net.au>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:tv3t4tc7mu6s4vf8qk3unvp21sr7rtg09s@4ax.com...
> while(@data) {
> $_ = shift @data;
> ... # do stuff with $_
> push @data, these_too($_);
> }
>
> However, this does destroy the original array. So does pushing new data,
> actually. Make a copy of it if you don't like that.
Martin gave a similar example, I thank you both. Actually I am building an
array based on elements from a previous array, So @data is being constructed
in the loop. I will spend the day going over perlstyle again. The while loop
_is_ much more suitable than a for loop.
------------------------------
Date: Wed, 03 Jan 2001 14:10:11 -0400
From: Antaeus Feldspar <feldspar@ix.netcom.com>
Subject: Question *not quite* answered by the FAQ posting...
Message-Id: <3A536B03.96A3A108@ix.netcom.com>
PerlFAQ Server wrote:
[snip]
> +
> Can I get a BNF/yacc/RE for the Perl language?
>
> There is no BNF, but you can paw your way through the yacc grammar in
> perly.y in the source distribution if you're particularly brave. The
> grammar relies on very smart tokenizing code, so be prepared to venture
> into toke.c as well.
>
> In the words of Chaim Frenkel: "Perl's grammar can not be reduced to
> BNF. The work of parsing perl is distributed between yacc, the lexer,
> smoke and mirrors."
[snip]
The above sheds light on a question I have, but doesn't *quite* answer
it. My question is, is it possible in some way to access the parse
tree(s) that Perl would construct from given source code?
My reason for asking? I have in mind a program called,
unimaginatively, Explicator, which would accept a file of Perl source
code as input and would allow you to go through the file and have it
explained/demonstrated how Perl is parsing each line. This would be a
valuable tool for both experienced programmers trying to detect bugs and
for novice programmers trying to understand existing Perl code.
At this point I fall far more into the latter category, so I'm mostly
asking whether such a program is feasible than "how can I get started?"
If it's feasible, however, then it'll go on my list of long-term
projects to attempt as I go up in skill level. (Needless to say, if
someone reads this and says, "Why, *I* know how to do that!" then I'll
be more than happy to let them take the project. ^^ But since I don't
expect that to happen, I'd just rather like to know whether this is
something for which the necessary infrastructure is already there, or
whether it'd require modifications almost as extreme as re-writing the
parsing code completely.
-jc
------------------------------
Date: Wed, 03 Jan 2001 21:33:17 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Question *not quite* answered by the FAQ posting...
Message-Id: <t576ktirrbsh4a@corp.supernews.com>
Antaeus Feldspar <feldspar@ix.netcom.com> wrote:
> PerlFAQ Server wrote:
> [snip]
>> +
>> Can I get a BNF/yacc/RE for the Perl language?
>>
>> There is no BNF, but you can paw your way through the yacc grammar in
[snip]
> The above sheds light on a question I have, but doesn't *quite* answer
> it. My question is, is it possible in some way to access the parse
> tree(s) that Perl would construct from given source code?
I'm not sure exactly how to play with them (for lack of time and
lack of antacid) but you could take a look at the modules O and B,
which deal with a Perl program interfacing to the back end and
dealing with data such as syntax tree and C structures. I'm not sure
this is the most effiecient way to do whatr you want, but it is an
interface into the compiler and is meant to make life easier for people
building ports and tools based around the Perl frontend with differing
backends.
perldoc O
perldoc B
excerpt from the documentation on B.pm:
walkoptree(OP, METHOD)
Does a tree-walk of the syntax tree based at OP and
calls METHOD on each op it visits. Each node is
visited before its children. If walkoptree_debug
(q.v.) has been called to turn debugging on then the
method walkoptree_debug is called on each op before
METHOD is called.
walkoptree_debug(DEBUG)
Returns the current debugging flag for walkoptree. If
the optional DEBUG argument is non-zero, it sets the
debugging flag to that. See the description of
walkoptree above for what the debugging flag does.
walksymtable(SYMREF, METHOD, RECURSE)
Walk the symbol table starting at SYMREF and call
METHOD on each symbol visited. When the walk reached
package symbols "Foo::" it invokes RECURSE and only
recurses into the package if that sub returns true.
> My reason for asking? I have in mind a program called,
> unimaginatively, Explicator, which would accept a file of Perl source
> code as input and would allow you to go through the file and have it
> explained/demonstrated how Perl is parsing each line. This would be a
> valuable tool for both experienced programmers trying to detect bugs and
> for novice programmers trying to understand existing Perl code.
Short of either duplicating or altering large portions of the core, I
think the B and O modules would be the most straightforward approach.
By altering the core, you risk branching if the standard distro ever
starts to include the same sort of tool. You'd want to make sure you
make recent patches available as the core is updated.
By duplicating the core, you are reinventing the wheel, possibly to
lower standards. You also risk incompatibilities with future versions
of the core if parsing changes at all.
By using B or O, you use an interface meant for tools to access this
sort of information in the arena of Perl's slightly drifting specs.
It is already part of the standard distro, so it could be reasonably
expected to remain available and up-to-date with the current version
of Perl. Even more conveniently, it is designed to work with whichever
version of Perl with which it is included. This means that there's less
chance of tools built on top of B or O becoming limited to usefulness
with certain versions of Perl and possibly giving incorrect output with
other versions.
> At this point I fall far more into the latter category, so I'm mostly
> asking whether such a program is feasible than "how can I get started?"
Everything that deals with manipulating text is feasible. It's a
Simple Matter of Programming ;) to implement it.
> If it's feasible, however, then it'll go on my list of long-term
> projects to attempt as I go up in skill level. (Needless to say, if
> someone reads this and says, "Why, *I* know how to do that!" then I'll
> be more than happy to let them take the project. ^^ But since I don't
> expect that to happen, I'd just rather like to know whether this is
> something for which the necessary infrastructure is already there, or
> whether it'd require modifications almost as extreme as re-writing the
> parsing code completely.
I don't know how to do it, so please don't leave the project for
me to do. It is an interesting idea. I could probably figure something
out with enough time spent combing the internals, the B and O modules,
and the docs. I'd rather, since this isn't something I'm immediately
interested in doing, point out that there are tools that could be useful
and hope that the OP or another party more interested decides to
pursue it.
Chris
--
Christopher E. Stith
For the pleasure of others, please adhere to the following rules when visiting your park:
No swimming. No fishing. No flying kites. No frisbees.
No audio equipment. Stay off grass. No pets. No running.
------------------------------
Date: Wed, 03 Jan 2001 15:09:19 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Question *not quite* answered by the FAQ posting...
Message-Id: <3A5394FF.45C008D0@home.com>
Antaeus Feldspar wrote:
>
> [I]s it possible in some way to access the parse
> tree(s) that Perl would construct from given source code?
Yes, using the B module (and perhaps its offshoots, such as B::Deparse).
> My reason for asking? I have in mind a program called,
> unimaginatively, Explicator, which would accept a file of Perl source
> code as input and would allow you to go through the file and have it
> explained/demonstrated how Perl is parsing each line.
Perhaps I'm misunderstanding your intent, but it sounds like you want to
explain in detail what (e.g.) map() is doing in a line of code. For
that, I think a person is better off consulting the docs and playing
with simple examples until they can understand big things made of little
pieces. It's generally more difficult to understand the big picture of
*why* a programmer is doing something a certain way -- a function of the
problem being solved and not something that any program is capable of
explaining.
> This would be a valuable tool for both experienced programmers
> trying to detect bugs and for novice programmers trying to
> understand existing Perl code.
Are you aware that Perl has a debugger? 'perl -d <file>' will launch
<file> in the interactive debugger. You can step through, set
breakpoints, even add code on the fly! For those who aren't comfortable
without a GUI, look into the Tk front-end: ptk-db.
> At this point I fall far more into the latter category, so I'm
> mostly asking whether such a program is feasible than "how can
> I get started?"
Yes, it's feasible. I'm not sure it's all that useful, but don't let me
put you off from doing it. If nothing else you're certain to learn a
good amount of Perl in the effort.
-mjc
------------------------------
Date: Wed, 03 Jan 2001 18:11:15 -0400
From: Antaeus Feldspar <feldspar@ix.netcom.com>
Subject: Re: Question *not quite* answered by the FAQ posting...
Message-Id: <3A53A383.19C0205A@ix.netcom.com>
Michael Carman wrote:
>
> Antaeus Feldspar wrote:
> >
> > [I]s it possible in some way to access the parse
> > tree(s) that Perl would construct from given source code?
>
> Yes, using the B module (and perhaps its offshoots, such as B::Deparse).
>
> > My reason for asking? I have in mind a program called,
> > unimaginatively, Explicator, which would accept a file of Perl source
> > code as input and would allow you to go through the file and have it
> > explained/demonstrated how Perl is parsing each line.
>
> Perhaps I'm misunderstanding your intent, but it sounds like you want to
> explain in detail what (e.g.) map() is doing in a line of code. For
> that, I think a person is better off consulting the docs and playing
> with simple examples until they can understand big things made of little
> pieces. It's generally more difficult to understand the big picture of
> *why* a programmer is doing something a certain way -- a function of the
> problem being solved and not something that any program is capable of
> explaining.
Mmmm, okay, I think we *do* have a lapse in communication here. I'm
aware that it'd take close to HAL-level AI to get a program that could
take in the code and explain the intent behind the code, but that's not
what I'm trying to do.
What I'm looking for, instead, is a program that would simply let you
know *how* the line is being broken down. Here, for example, is a line
from somebody's script:
$x =~ s/\s+?|[\000-\011\013-\037\177]|\178-\255//g;
Even with my trusty O'Reilly at my side, I had a difficult time even
knowing *what to look up.* Now, of course, having solved it, I know
that the right half of the statement is the substitution operator
"s/pattern/replace/options", where
"\s+?|[\000-\011\013-\037\177]|\178-\255" is the pattern, "" is the
replacement, and "g" is the set of options, and just knowing that that
was how it was being broken down would have put me a lot further towards
understanding why that line works as it does (fails to work, actually,
since it has a bug in it.)
> > This would be a valuable tool for both experienced programmers
> > trying to detect bugs and for novice programmers trying to
> > understand existing Perl code.
>
> Are you aware that Perl has a debugger? 'perl -d <file>' will launch
> <file> in the interactive debugger. You can step through, set
> breakpoints, even add code on the fly! For those who aren't comfortable
> without a GUI, look into the Tk front-end: ptk-db.
^_^ Well, I know about the debugger, but I think this tool might have
its own use.
> > At this point I fall far more into the latter category, so I'm
> > mostly asking whether such a program is feasible than "how can
> > I get started?"
>
> Yes, it's feasible. I'm not sure it's all that useful, but don't let me
> put you off from doing it. If nothing else you're certain to learn a
> good amount of Perl in the effort.
>
> -mjc
Thank you! ^_^
-jc
------------------------------
Date: Wed, 03 Jan 2001 17:55:29 GMT
From: "Cartland Chiu" <cchiu@credit.erin.utoronto.ca>
Subject: Question regarding directory handles
Message-Id: <01c075ad$ba2d8030$b7e4330a@cart>
Hi everybody,
I am a Perl beginner so please bear with me. :)
I have a problem where I want to recursively delete (purge) files based on
a date parameter. I want this to work on Windows NT if that matters.
Right now I see the program working this way:
# CODE BEGINS HERE
delete_dir
{
... open directory given as parameter ....
... delete files in current directory....
... recursively call function on sub-directories...
... delete current directory if empty ...
}
delete_dir $ARGV[0];
# CODE ENDS HERE
I took at look at the File::Find module but it doesn't do quite what I
want. I can't do any "post-recursion" stuff using this module (i.e. the
'delete current directory if empty' part in the code above). However, if I
don't use this, I have to worry about the directory handle, and from what I
understand, recursive call will overwrite the directory handle. I tried
localizing the directory handle but I can't seem to get that to work. I
also tried closing the current directory before the recursive call and
re-opening it after the recursive call but that also does not seem to work
either. Please help!
Thanks very much for your time.
Cartland
------------------------------
Date: Thu, 04 Jan 2001 00:27:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Question regarding directory handles
Message-Id: <3A53C424.660B6DEC@acm.org>
Cartland Chiu wrote:
>
> I have a problem where I want to recursively delete (purge) files based on
> a date parameter. I want this to work on Windows NT if that matters.
Have a look at the rmtree command in the File::Path module.
HTH
John
------------------------------
Date: Thu, 04 Jan 2001 01:52:38 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Question regarding directory handles
Message-Id: <3a53d765.20b8$16@news.op.net>
[mailed and posted]
In article <01c075ad$ba2d8030$b7e4330a@cart>,
Cartland Chiu <cchiu@credit.erin.utoronto.ca> wrote:
>I took at look at the File::Find module but it doesn't do quite what I
>want. I can't do any "post-recursion" stuff using this module (i.e. the
>'delete current directory if empty' part in the code above).
My recollection is that this is actually what the 'finddepth' function
does.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Tue, 02 Jan 2001 01:08:26 GMT
From: manon_bertolini@mantacorp.com
Subject: pop-up window problem
Message-Id: <92r9m8$rd1$1@nnrp1.deja.com>
I am having trouble running a perl script, and placing the contents in a
pop-up window. The problem is the script doesn't seem to complete to
the end.
Here's my call to the perl script:
<form name="oldpoll" action='http://localhost/cgi-bin/Instapoll.cgi'
method="post"
OnSubmit="window.open('http://localhost/cgi-bin/Instapoll.cgi/','mywindo
w','toolbar=0,location=0,directories=0,status=1,width=322,height=257');
return false;" TARGET="mywindow">
It is a web poll. The script is supposed to calculate the results. I
just get the top part of the results window.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 01 Jan 2001 19:31:57 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: pop-up window problem
Message-Id: <87y9wuu4c2.fsf@limey.hpcc.uh.edu>
>> On Tue, 02 Jan 2001 01:08:26 GMT,
>> manon_bertolini@mantacorp.com said:
> I am having trouble running a perl script, and placing the contents
> in a pop-up window. The problem is the script doesn't seem to
> complete to the end.
Perl does not have "pop-up windows". See below.
> Here's my call to the perl script: <form name="oldpoll"
> action='http://localhost/cgi-bin/Instapoll.cgi' method="post"
> OnSubmit="window.open('http://localhost/cgi-bin/Instapoll.cgi/','mywindo
> w','toolbar=0,location=0,directories=0,status=1,width=322,height=257');
> return false;" TARGET="mywindow">
> It is a web poll. The script is supposed to calculate the results.
> I just get the top part of the results window.
I guess there's a problem somewhere. But with no code and/or data to
reason with, who knows?
Write a small self-contained program that exhibits this behaviour.
Post it. Then someone may be able to offer advice. Otherwise it's
just GIGO isn't it?
Are you having a problem with understanding or using perl? Is it a
problem with CGI? Or with browser technology? Answering this may
help you narrow down your choice of most relevant newsgroup(s).
--
Eih bennek, eih blavek.
------------------------------
Date: Tue, 02 Jan 2001 04:10:59 GMT
From: manonb@my-deja.com
Subject: Re: pop-up window problem
Message-Id: <92rkcf$3h7$1@nnrp1.deja.com>
Actually, I have learned that it is a MSIE problem. Yes, I am new to
Perl - that makes it tougher. My problem has improved, but now I get
two windows with the results. A full one, and a smaller one.
Why the full one as well? I have tested for window.open, tried
using A HREF, and Netscape works perfectly. It is almost like there are
two "submits" going through.
arrgg! So I see now it was not a Perl problem.
In article <87y9wuu4c2.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >> On Tue, 02 Jan 2001 01:08:26 GMT,
> >> manon_bertolini@mantacorp.com said:
>
> > I am having trouble running a perl script, and placing the contents
> > in a pop-up window. The problem is the script doesn't seem to
> > complete to the end.
>
> Perl does not have "pop-up windows". See below.
>
> > Here's my call to the perl script: <form name="oldpoll"
> > action='http://localhost/cgi-bin/Instapoll.cgi' method="post"
> >
OnSubmit="window.open('','mywindow','toolbar=0,location=0,directories=0,
status=1,width=322,height=257');
> > return false;" TARGET="mywindow">
>
> > It is a web poll. The script is supposed to calculate the results.
> > I just get the top part of the results window.
>
> I guess there's a problem somewhere. But with no code and/or data to
> reason with, who knows?
>
> Write a small self-contained program that exhibits this behaviour.
> Post it. Then someone may be able to offer advice. Otherwise it's
> just GIGO isn't it?
>
> Are you having a problem with understanding or using perl? Is it a
> problem with CGI? Or with browser technology? Answering this may
> help you narrow down your choice of most relevant newsgroup(s).
>
> --
> Eih bennek, eih blavek.
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Mon, 1 Jan 2001 17:53:40 -0000
From: "Edd" <edd@texscene.com>
Subject: Problem with DBI-sorry to send it again
Message-Id: <3a50c1ed@news-uk.onetel.net.uk>
I am trying the PERL/DBI code below which I obtained from perlfaq.com but
doesn't work. Can anyone help?
----------------------------------
#!/usr/bin/perl -w
use DBI;
use strict;
print "Content-type: text/html\n";
my $database = 'database1';
my $user = 'user1';
my $password = 'pass1';
$dbh = DBI->connect("dbi:mysql:$database",$user,$password);
$sth = $dbh->do(qq{SELECT * FROM table1});
while (my $columns = $sth->fetchrow_hashref) {
print "Column 1: $columns->{col1}\n";
print "Column 2: $columns->{col2}\n";
}
$dbh->disconnect;
1;
I get the error messages below:
Global symbol '$dbh' requires explicit package name at line 10.
Global symbol '$sth' requires explicit package name at line 11.
Execution aborted due to compilation errors.
Can somebody please help where this code goes wrong?
Many thanks.
------------------------------
Date: Mon, 01 Jan 2001 18:17:07 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Problem with DBI-sorry to send it again
Message-Id: <DQ346.335$Dm5.15961@eagle.america.net>
On Mon, 1 Jan 2001 17:53:40 -0000, Edd <edd@texscene.com> wrote:
>I am trying the PERL/DBI code below which I obtained from perlfaq.com but
>doesn't work. Can anyone help?
>----------------------------------
> #!/usr/bin/perl -w
>
>use DBI;
>use strict;
>print "Content-type: text/html\n";
>
>my $database = 'database1';
>my $user = 'user1';
>my $password = 'pass1';
>
>$dbh = DBI->connect("dbi:mysql:$database",$user,$password);
...
>I get the error messages below:
>
> Global symbol '$dbh' requires explicit package name at line 10.
> Global symbol '$sth' requires explicit package name at line 11.
>
>Can somebody please help where this code goes wrong?
It looks like you didn't copy/paste that code from that Web site.
The perldiag manual page explains what the problem is:
Global symbol "%s" requires explicit package name
(F) You've said "use strict vars", which indicates that
all variables must either be lexically scoped (using
"my"), declared beforehand using "our", or explicitly
qualified to say which package the global variable is in
(using "::").
So declare $dbh and $sth with my(), just as you did for $database and
the others. (See the original.)
Use the manual.
Incidentally, you can get perl to look up its error messages in the
perldiag manual page automatically by saying:
use diagnostics;
--
Garry Williams
------------------------------
Date: 01 Jan 2001 13:18:42 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Problem with DBI-sorry to send it again
Message-Id: <m33df35e65.fsf@mumonkan.sunstarsys.com>
"Edd" <edd@texscene.com> writes:
> I am trying the PERL/DBI code below which I obtained from perlfaq.com but
> doesn't work. Can anyone help?
> ----------------------------------
> #!/usr/bin/perl -w
^^^^^^
You didn't cut and paste this- a space before the # spoils the shebang
effect (also your errors would be on line 11 & 12 in the code posted,
not 10 & 11).
> use strict;
[...]
my or die $DBI::errstr;
vv vv
> $dbh = DBI->connect("dbi:mysql:$database",$user,$password);
> $sth = $dbh->do(qq{SELECT * FROM table1});
^^ ^^
my or die $DBI::errstr;
prefix these lines with "my", add some error-checking, and you should be OK.
[...]
> while (my $columns = $sth->fetchrow_hashref) {
> print "Column 1: $columns->{col1}\n";
> print "Column 2: $columns->{col2}\n";
> }
Although not strictly necessary, it might be nice to include
$sth->finish,
vv
> $dbh->disconnect;
here.
> Global symbol '$dbh' requires explicit package name at line 10.
> Global symbol '$sth' requires explicit package name at line 11.
> Execution aborted due to compilation errors.
This is the error message you get whenever you use undeclared
variables under "use strict;". Error messages often contain
useful diagnostic messages in them, and this one is no exception.
If they're not verbose enough, perl even lets you add a
use diagnostics;
pragma as well. Try adding it to the top of your broken code
and see what it tells you.
> Can somebody please help where this code goes wrong?
You are almost doing the Right Thing here, but in the
future try to figure out what the error messages mean
before giving up on fixing the code yourself.
HTH
--
Joe Schaefer
------------------------------
Date: Thu, 04 Jan 2001 10:43:18 -0600
From: Greg Economides <econ@tamu.edu>
Subject: problem with DST conversion in Time::Local
Message-Id: <3A54A826.B4938F0C@tamu.edu>
Hi all,
I've been using Time::Local (timegm and localtime) to do conversions
from GMT to local time. The code has been working fine for a year, but
now seems to have a problem. It looks like the module is missing the
fact that DST starts on 1 April 2001 this year. All of the conversions
that I do show that it incorrectly subtracts 6 hours
from DST during April 1 - April 7 (GMT-6 is for CST and GMT-5 for CDT).
Then, from 8 April on, it correctly subtracts 5 hours.
Here's the significant line of code:
@tarray=localtime(timegm(0,$min,$hour,$day,$mon,$yr));
Are any of you finding this problem?
peace,
greg
------------------------------
Date: 02 Jan 2001 07:36:35 GMT
From: loans2001@aol.com (Loans2001)
Subject: Problem with simple cookie program
Message-Id: <20010102023635.12084.00001262@ng-cd1.aol.com>
This code worked, I think. After clicking on the link I had set up from the
website sending the ended url, (storecookie.cgi?id=scot)
It read the Query String, and caughed up a little box saying form contains no
data. I'm supposed to be able to look in the netscape cookies.txt file to see
the cookie, or id=scot, since that's what I'm trying to put there. But I
opened this up, and it was not there. Am I missing something?
Thanks for your help.
#!/usr/bin/perl
($key, $value) = split(/=/, $ENV{'QUERY_STRING'});
print "Content-type: text/html", "\n";
print "Set-Cookie: $key=$value; expires=Sat, 26-Aug-01 15:45:30 GMT; path=/;
domain=mortgage-pros.com", "\n\n";
exit (0);
Scot King
mortgage-pros.com
------------------------------
Date: Tue, 02 Jan 2001 08:03:36 GMT
From: egwong@netcom.com
Subject: Re: Problem with simple cookie program
Message-Id: <sXf46.33158$bw.2090602@news.flash.net>
You're missing CGI.pm :)
http://search.cpan.org/search?dist=CGI.pm
But, if I had to guess, since the header looks okay to me, I'm guessing
that you checked your cookies.txt file while netscape was still running.
I don't think the cookies file is updated while netscape is running.
Loans2001 <loans2001@aol.com> wrote:
> This code worked, I think. After clicking on the link I had set up from the
> website sending the ended url, (storecookie.cgi?id=scot)
> It read the Query String, and caughed up a little box saying form contains no
> data. I'm supposed to be able to look in the netscape cookies.txt file to see
> the cookie, or id=scot, since that's what I'm trying to put there. But I
> opened this up, and it was not there. Am I missing something?
> Thanks for your help.
> #!/usr/bin/perl
> ($key, $value) = split(/=/, $ENV{'QUERY_STRING'});
> print "Content-type: text/html", "\n";
> print "Set-Cookie: $key=$value; expires=Sat, 26-Aug-01 15:45:30 GMT; path=/;
> domain=mortgage-pros.com", "\n\n";
> exit (0);
> Scot King
> mortgage-pros.com
------------------------------
Date: Tue, 02 Jan 2001 11:26:33 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: Problem with simple cookie program
Message-Id: <3A51BC5E.CCA59B26@home.nl>
egwong@netcom.com wrote:
> You're missing CGI.pm :)
> http://search.cpan.org/search?dist=CGI.pm
>
> But, if I had to guess, since the header looks okay to me, I'm guessing
> that you checked your cookies.txt file while netscape was still running.
> I don't think the cookies file is updated while netscape is running.
>
> Loans2001 <loans2001@aol.com> wrote:
> > This code worked, I think. After clicking on the link I had set up from the
> > website sending the ended url, (storecookie.cgi?id=scot)
> > It read the Query String, and caughed up a little box saying form contains no
> > data. I'm supposed to be able to look in the netscape cookies.txt file to see
> > the cookie, or id=scot, since that's what I'm trying to put there. But I
> > opened this up, and it was not there. Am I missing something?
>
>
> yes thats true..you need to close your browser first before netscape stores ur
> cookie in the cookiefile.
Also u could check if the browser accepts the year 01.
------------------------------
Date: Tue, 2 Jan 2001 07:01:53 -0600
From: "Rich H" <bigrich318@yahoo.com>
Subject: Re: Problem with simple cookie program
Message-Id: <t53k5787ic0494@corp.supernews.com>
"Loans2001" <loans2001@aol.com> wrote in message
news:20010102023635.12084.00001262@ng-cd1.aol.com...
> This code worked, I think. After clicking on the link I had set up from
the
> website sending the ended url, (storecookie.cgi?id=scot)
> It read the Query String, and caughed up a little box saying form contains
no
> data. I'm supposed to be able to look in the netscape cookies.txt file to
see
> the cookie, or id=scot, since that's what I'm trying to put there. But I
> opened this up, and it was not there. Am I missing something?
>
> Thanks for your help.
>
>
> #!/usr/bin/perl
> ($key, $value) = split(/=/, $ENV{'QUERY_STRING'});
> print "Content-type: text/html", "\n";
> print "Set-Cookie: $key=$value; expires=Sat, 26-Aug-01 15:45:30 GMT;
path=/;
> domain=mortgage-pros.com", "\n\n";
> exit (0);
I'm not certain but I believe you should print "Set-Cookie before
Content-type and the expiration date should be 2001.
#!/usr/bin/perl
($key, $value) = split(/=/, $ENV{'QUERY_STRING'});
print "Set-Cookie: $key=$value; expires=Sat, 26-Aug-2001 15:45:30 GMT;
path=/; domain=mortgage-pros.com ";
print "Content-type: text/html\n\n";
exit (0);
You could also use CGI.pm
#!/usr/bin/perl -wT
use strict;
use CGI ':standard';
my($q, $key, $value, $new_cookie)
$q = new CGI;
($key, $value) = split(/=/, $ENV{'QUERY_STRING'});
$new_cookie =
$q->cookie(-name=>$key, -value=>$value, -path=>'/', -domain=>'mortgage-pros.
com');
print $q->header(-cookie=>$new_cookie);
To test it, just print out the HTTP_COOKIE environment variable.
Rich H
------------------------------
Date: Fri, 29 Dec 2000 16:41:48 GMT
From: msalerno@my-deja.com
Subject: Problem with values - simple problem
Message-Id: <92iesb$ih1$1@nnrp1.deja.com>
I am trying to get the script to exit if the user enters q
what is happening is, if the user enters a word that begins with a q
(ex. que quick quest) the script terminates !
I want the script to terminate only if the user enters a single q
die "Bye !\n" if $search == /q/;
die "Bye !\n" if $search =~ /b[q]/i;
" " eq
Please let me know where I have made my mistake.
Thanks,
Matt
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 29 Dec 2000 11:56:07 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Problem with values - simple problem
Message-Id: <slrn94pgh7.u3.tadmc@magna.metronet.com>
msalerno@my-deja.com <msalerno@my-deja.com> wrote:
>I am trying to get the script to exit if the user enters q
>what is happening is, if the user enters a word that begins with a q
>I want the script to terminate only if the user enters a single q
>
>die "Bye !\n" if $search == /q/;
^^^
That is matching against the string in $_, not against $search.
I'll bet you retyped your code instead of copy/pasting it. Don't do that.
die "Bye !\n" if $search eq "q\n";
or
die "Bye !\n" if $search =~ /^q$/;
>die "Bye !\n" if $search =~ /b[q]/i;
I'm not at all sure what you expected that to do. It requires
a "b" to match. You haven't said anything about the letter "b"...
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 30 Dec 2000 00:22:43 +0000
From: "Garry Knight" <garryknight@bigfoot.com>
Subject: Re: Problem with values - simple problem
Message-Id: <92j9sj$n4k$1@taliesin.netcom.net.uk>
In article <92iesb$ih1$1@nnrp1.deja.com> msalerno@my-deja.com wrote:
> I am trying to get the script to exit if the user enters q what is
> happening is, if the user enters a word that begins with a q
> (ex. que quick quest) the script terminates !
>
> I want the script to terminate only if the user enters a single q
>
> die "Bye !\n" if $search == /q/; die "Bye !\n" if $search =~
> /b[q]/i;
> " " eq
How about:
die "Bye !\n" if $search =~ /^q$/;
--
Garry Knight
garryknight@bigfoot.com
------------------------------
Date: Fri, 29 Dec 2000 20:41:26 GMT
From: dmarwick@my-deja.com
Subject: Problem writing temp files from a script called by .forward
Message-Id: <92istl$ud9$1@nnrp1.deja.com>
Hi,
I am running a script from my .forward, by piping email to it--my .forward
looks something like "| myscript.pl".
From this script I seem to be unable to write temp files to /tmp. I have
also tried to write within my home directory, also with no success. I don't
think this is a permissions problem since /tmp is world-writeable.
Any advice on how to write files in this context would be greatly appreciated.
Thanks
Dave
Programmer, BARRA
david.marwick@barra.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 29 Dec 2000 20:41:27 GMT
From: dmarwick@my-deja.com
Subject: Problem writing temp files from a script called by .forward
Message-Id: <92istn$uda$1@nnrp1.deja.com>
Hi,
I am running a script from my .forward, by piping email to it--my .forward
looks something like "| myscript.pl".
From this script I seem to be unable to write temp files to /tmp. I have
also tried to write within my home directory, also with no success. I don't
think this is a permissions problem since /tmp is world-writeable.
Any advice on how to write files in this context would be greatly appreciated.
Thanks
Dave
Programmer, BARRA
david.marwick@barra.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 29 Dec 2000 20:43:36 GMT
From: david.marwick@barra.com
Subject: Problem writing temp files from a script called by .forward
Message-Id: <92it1n$uer$1@nnrp1.deja.com>
Hi all,
I am running a script from my .forward, by piping email to it--my
.forward looks something like:
"| myscript.pl".
From this script I seem to be unable to write files to /tmp. I have
also tried to write within my home directory, also with no success. I
don't think this is a permissions problem since /tmp is
world-writeable.
Any advice on how to write files in this context would be greatly
appreciated.
Thanks
Dave
Programmer, BARRA
david.marwick@barra.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 29 Dec 2000 20:56:24 GMT
From: revjack <revjack@revjack.net>
Subject: Re: Problem writing temp files from a script called by .forward
Message-Id: <92itpo$8dj$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
dmarwick@my-deja.com wrote:
: I am running a script from my .forward, by piping email to it--my .forward
: looks something like "| myscript.pl".
: From this script I seem to be unable to write temp files to /tmp.
What does the error message say?
--
___________________
revjack@revjack.net
------------------------------
Date: Fri, 29 Dec 2000 21:12:04 GMT
From: david.marwick@barra.com
Subject: Re: Problem writing temp files from a script called by .forward
Message-Id: <92iumu$vu9$1@nnrp1.deja.com>
Sorry for the multiple postings btw, browser problems.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 29 Dec 2000 21:23:27 GMT
From: david.marwick@barra.com
Subject: Re: Problem writing temp files from a script called by .forward
Message-Id: <92ivc8$fb$1@nnrp1.deja.com>
I'm not sure how to read the error output b/c I'm not running
the script directly. I'm pretty new to Perl--is there a way from within
the script to redirect STDERR to a file?
In article <92itpo$8dj$1@news1.Radix.Net>,
revjack <revjack@revjack.net> wrote:
> dmarwick@my-deja.com wrote:
>
> : I am running a script from my .forward, by piping email to it--my
.forward
> : looks something like "| myscript.pl".
>
> : From this script I seem to be unable to write temp files to /tmp.
>
> What does the error message say?
>
> --
> ___________________
> revjack@revjack.net
>
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 29 Dec 2000 22:36:37 GMT
From: revjack <revjack@revjack.net>
Subject: Re: Problem writing temp files from a script called by .forward
Message-Id: <92j3ll$bba$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
[please reply below quoted material]
david.marwick@barra.com wrote:
: In article <92itpo$8dj$1@news1.Radix.Net>,
: revjack <revjack@revjack.net> wrote:
:> dmarwick@my-deja.com wrote:
:>
:> : I am running a script from my .forward, by piping email to it--my
: .forward
:> : looks something like "| myscript.pl".
:>
:> : From this script I seem to be unable to write temp files to /tmp.
:>
:> What does the error message say?
: I'm not sure how to read the error output b/c I'm not running
: the script directly. I'm pretty new to Perl--is there a way from within
: the script to redirect STDERR to a file?
In perlfaq9:
"How can I get better error messages from a CGI program?"
--
___________________
revjack@revjack.net
------------------------------
Date: Fri, 29 Dec 2000 17:00:53 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Problem writing temp files from a script called by .forward
Message-Id: <slrn94q2cl.23c.tadmc@magna.metronet.com>
revjack <revjack@revjack.net> wrote:
>david.marwick@barra.com wrote:
>: In article <92itpo$8dj$1@news1.Radix.Net>,
>: revjack <revjack@revjack.net> wrote:
>:> dmarwick@my-deja.com wrote:
>:>
>:> : I am running a script from my .forward
>:> : From this script I seem to be unable to write temp files to /tmp.
>:>
>:> What does the error message say?
>
>: I'm not sure how to read the error output b/c I'm not running
>: the script directly. I'm pretty new to Perl--is there a way from within
>: the script to redirect STDERR to a file?
perldoc -f open
... Here is a script that saves, redirects, and restores STDOUT and
STDERR: ...
>In perlfaq9:
>"How can I get better error messages from a CGI program?"
That ain't going to help.
He is running his Perl program from a .forward file, not as
a CGI program.
What made you think that CGI was involved?
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 30 Dec 2000 05:03:02 GMT
From: revjack <revjack@revjack.net>
Subject: Re: Problem writing temp files from a script called by .forward
Message-Id: <92jqa6$mo6$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
Tad McClellan <tadmc@metronet.com> wrote:
: That ain't going to help.
: He is running his Perl program from a .forward file, not as
: a CGI program.
: What made you think that CGI was involved?
Thinking wasn't involved, apparently. I should never post
before that third beer.
Thanks for the correction.
--
___________________
revjack@revjack.net
------------------------------
Date: 29 Dec 2000 16:05:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problems in writing in file ....?
Message-Id: <92ico5$q8f$2@mamenchi.zrz.TU-Berlin.DE>
jaya <jaya_j_k@hotmail.com> wrote in comp.lang.perl.misc:
>Hello,
>
>I have one file and want to modify that file at 50 different places I know
>the line numbers where I want to modify that.
>
>Let's say my line number 20 is :
>$c = 50;
>
>And I want that line as
>$c = 30;
>
>If I open the file with ">>" then perl is not allowing the chomp in that
>as I want to read the file upto 20 lines.
>
>Presently I'm reading that file (opened in Read mode) and creating a new
>file (opened in write mode) with new contents and then renaming the new
>file.
>
>Is there any way, by which I can change the contents of same file, without
>using another file.
This is discussed extensively in the faq. "perldoc -q 'change one line'"
takes you there. Please check the faq before you post.
Anno
------------------------------
Date: 29 Dec 2000 17:33:04 +0000
From: nobull@mail.com
Subject: Re: Problems in writing in file ....?
Message-Id: <u93df75e03.fsf@wcl-l.bham.ac.uk>
jaya <jaya_j_k@hotmail.com> writes:
> Subject: Problems in writing in file ....?
Subject line does not attempt to describe your problem. Please
attempt to describe your problem in the subject line.
> I have one file and want to modify that file at 50 different places I know
> the line numbers where I want to modify that.
>
> Let's say my line number 20 is :
> $c = 50;
>
> And I want that line as
> $c = 30;
>
> If I open the file with ">>" then perl is not allowing the chomp in that
> as I want to read the file upto 20 lines.
Huh?
> Presently I'm reading that file (opened in Read mode) and creating a new
> file (opened in write mode) with new contents and then renaming the new
> file.
>
> Is there any way, by which I can change the contents of same file, without
> using another file.
There is a way, but probably not a _better_ way.
If you are making changes that only replace characters and never
insert/delete then you can open in '+<' mode use seek() to jump back
and overwrite the last line. This is messy.
Alternatively you can slurp the whole file into an array, edit the
array, truncate() the file to zero length and write the array back
out.
> Thanks in advance,
If you are going to do anything "in advance" it should be "read the
FAQ". Your question is very close to one of the questions in the FAQ.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 04 Jan 2001 12:18:13 -0500
From: Don <don@lclcan.com>
Subject: Problems using Net:POP3
Message-Id: <3A54B055.645CDDAD@lclcan.com>
Combine two facts
1) I am still a partial neophyte at programming with Perl
2) The documentation for Net:POP3 is woefully lean
I've created an object by the following method:
$webmail = Net::POP3->new("localhost", Timeout => 60);
Now, I wish to log in and retrieve email so I issued the following
command:
$messages = $webmail->login("mu_user", "my_password");
I get this error after issuing the second command:
"Can't call method "login" on an undefined value at update_db.pl line
31."
I suspect that my syntax is wrong but there are NO examples in the
docs. If anyone has used this module before, I'd really appreciate a
sample script with examples of connecting and retrieving email from a
POP3 server user account.
Thanks,
Don
------------------------------
Date: 04 Jan 2001 11:26:26 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Problems using Net:POP3
Message-Id: <87wvcb6xfh.fsf@limey.hpcc.uh.edu>
>> On Thu, 04 Jan 2001 12:18:13 -0500,
>> Don <don@lclcan.com> said:
> Combine two facts 1) I am still a partial neophyte at
> programming with Perl 2) The documentation for Net:POP3
> is woefully lean
> I've created an object by the following method:
> $webmail = Net::POP3->new("localhost", Timeout => 60);
> Now, I wish to log in and retrieve email so I issued the
> following command:
> $messages = $webmail->login("mu_user", "my_password");
> I get this error after issuing the second command:
> "Can't call method "login" on an undefined value at
> update_db.pl line 31."
Did you check that the constructor was successful?
$webmail appears to be undefined, indicating that you did
not make the desired connection to localhost.
You can do something like this:
use strict;
use Net::POP3;
my $webmail = Net::POP3->new("localhost", Timeout => 60);
die "some useful error messsage about connection" if ! defined $webmail;
my $messages = $webmail->login("mu_user", "my_password");
die "some useful error message about login" if ! defined $messages;
print "There are $messages messages for you\n";
$webmail->quit();
When interacting with anything external to your program,
you really need to check everything that happens.
Remember: the impossible will happen often.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Thu, 04 Jan 2001 06:18:27 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Proposed FAQ addition (was Re: how to send html mail)
Message-Id: <TAU46.646$B9.191605760@news.frii.net>
In article <3A5405F4.856B75B0@looksmart.net>,
Jim Ramberg <jramberg@looksmart.net> wrote:
>I have perl program that outputs html. I want to be able to mail this
>out to people and to have the content type register correctly as
>HTML so that the HTML will be rendered.
>
>I have tried using the Mail:Send module and I have yet to get the syntax
>correct such that the resulting mail has the correct content-type
>header.
>
Here is a proposed addition to the FAQ.
=head2 How do I use MIME to make an attachment to a mail message?
This answer is extracted directly from the MIME::Lite documentation.
Create a multipart message (i.e., one with attachments):
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'A message with 2 parts...',
Type =>'multipart/mixed'
);
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type =>'TEXT',
Data =>"Here's the GIF file you wanted"
);
$msg->attach(Type =>'image/gif',
Path =>'aaa000123.gif',
Filename =>'logo.gif'
);
$text = $msg->as_string;
MIME::Lite also includes a method for sending these things:
$msg->send;
This defaults to using L<sendmail(1)> but can be customized to use
SMTP via L<Net::SMTP>.
--
This space intentionally left blank
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5243
**************************************