[14073] in Perl-Users-Digest
Perl-Users Digest, Issue: 1483 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 24 18:15:45 1999
Date: Wed, 24 Nov 1999 15:15:31 -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: <943485331-v9-i1483@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 24 Nov 1999 Volume: 9 Number: 1483
Today's topics:
Re: Test for eval() without using eval() ?? <jeff@vpservices.com>
Re: Test for eval() without using eval() ?? (Scott McMahan)
Re: Test for eval() without using eval() ?? (Scott McMahan)
Re: Test for eval() without using eval() ?? <mkruse@rens.com>
Re: Test for eval() without using eval() ?? <mkruse@rens.com>
Re: Test for eval() without using eval() ?? (Craig Berry)
Re: Test for eval() without using eval() ?? <montuori@acs.neu.edu>
Re: Test for eval() without using eval() ?? (Simon Cozens)
testing if a filehandle is open already <ask_for_my_address_if_you_need_it@earthlink.net>
Re: variable scoping (Tad McClellan)
Re: variable scoping <helmut@cancon.com>
Re: variable scoping <nandu@cimedia.com>
Re: variable scoping (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Nov 1999 18:53:18 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <383C33C8.C3370F8B@vpservices.com>
Matt Kruse wrote:
>
> For example, some people were trying to run the script on Win95/98 and found
> that it does not have flock. So, I put that in an eval. Easy enough. So now
> it runs just fine, but without file locking.
But it is well documented that flock is missing from Win95 Perl and
therefore an eval of flock is totally appropriate. I don't recall
seeing anything documenting eval being missing in any ports of Perl.
And in another post:
> Simon Cozens <simon@brecon.co.uk> wrote in message
>> matt kruse's use of ancient
> I've never had a complaint.
That could mean 1) people have had problems but haven't bothered to
inform you or 2) you have had the good fortune to have your scripts run
in circumstances in which they work. Neither of those guarantees that
the script will continue to work in other circumstances. In fact,
preparing for strange circumstances is what got you into this thread in
the first place, so I'd think you would be doubly concerned when an
informed regular of this newsgroup points out problems in your scripts.
--
Jeff
------------------------------
Date: Wed, 24 Nov 1999 20:04:18 GMT
From: scott@aravis.softbase.com (Scott McMahan)
Subject: Re: Test for eval() without using eval() ??
Message-Id: <6xX_3.2209$Eh5.126115@monger.newsread.com>
Matt Kruse (mkruse@rens.com) wrote:
> Also, CGI.pm is huge and non-intuitive, IMO. I don't like it. And
> no, I'm certainly not alone in this feeling. Don't even try to tell me that
> everyone likes and uses CGI.pm.
I don't think I'd like it -- I was reading the official CGI.pm book to
see if it would be better than the old-fashioned way, and I am baffled
by it. I don't know how it even caught on. It has such a bizarre syntax
that I find just embedding HTML is much clearer and obvious. It seems
to be built to demonstrate a paradigm I don't care to subscribe to,
and offer minimal functionality if you don't buy into it all the way.
I've often thought about rolling my own template-based HTML outputting
solution that would combine the best of here documents and variable
interpolation, but have not yet had the need.
Scott
------------------------------
Date: Wed, 24 Nov 1999 20:09:31 GMT
From: scott@aravis.softbase.com (Scott McMahan)
Subject: Re: Test for eval() without using eval() ??
Message-Id: <%BX_3.2211$Eh5.126115@monger.newsread.com>
Matt Kruse (mkruse@rens.com) wrote:
> It sounds like some of you have never written scripts to be used by the
> general population.
One of the chief problems of modules is they're optional: you can count
on maybe a small core set, but if you're writing Perl programs to run on
machines where you only have FTP access to upload them and debugging is a
shot in the dark, you really have to be lean and mean and not use anything
other than what's built into the most basic Perl interpreter install.
Some of these modules are nice, but you get into complex installs to
get them working. Module cascading dependencies are the absolute worst
-- module X depends on Y, which depends on Z, and so on. You wind up
installing half of CPAN, and that's not always practical or possible
when you can do the same things these modules do in a few lines of code.
If you can only FTP programs to a host, you're debugging in the dark
and really have to improvise to get anything to run.
Scott
PS: I can sympathize with ISPs, too; this is a true story. I once had
a shell dial-up account and debugged CGI programs there using Perl
5, and FTPed it to their hosting web server only to get a 500 server
error. After WEEKS of desperate debugging, being totally out of ideas,
I FTPed the Perl interpreter off of the hosting server and discovered
their host had Perl 4! No wonder nothing worked! They had a different
version of Perl on each machine!
------------------------------
Date: Wed, 24 Nov 1999 14:16:31 -0600
From: "Matt Kruse" <mkruse@rens.com>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <81hgr3$n4i$1@ffx2nh3.news.uu.net>
Craig Berry <cberry@cinenet.net> wrote
> I'm curious how it can be that a script (algorithm) which requires locking
> in any context can be said to "run just fine" without file locking.
Well, the script can either be updated by everyone OR just used by a single
administrator. In cases where file locking isn't available, users should
only use a single administrator if they want to be that their data will not
be corrupted.
------------------------------
Date: Wed, 24 Nov 1999 14:23:16 -0600
From: "Matt Kruse" <mkruse@rens.com>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <81hh7n$nju$1@ffx2nh3.news.uu.net>
Scott McMahan <scott@aravis.softbase.com> wrote
> I've often thought about rolling my own template-based HTML outputting
> solution that would combine the best of here documents and variable
> interpolation, but have not yet had the need.
I have written one, and I'm considering making it available to everyone. It
just depends on whether I ever have enough time to document it and provide
limited support for it.
It is basically "ASP" in a CGI. You can use templates with the same syntax
as ASP and the script will parse and execute it correctly. It also has the
option of generating the "pure perl" to generate the page. That is, turn the
plain HTML into print statements and format the code nicely.
I use this for development, mainly. I can develop using templates in an
ASP-style that I find more comfortable. The script runs correctly by
interpretting the templates on-the-fly and running. Then I run my
pre-processor (which does much more than just interpret the "ASP" templates,
also) and it generates the code from the templates, turns them into
subroutines, modifies the original code to call them correctly, and outputs
a finished, packaged script. So the script runs in both development mode and
packaged mode without any modifications. Very nice.
When working with large scripts and multiple screens, I find this
development approach to be the one that works best for me and is has greatly
stream-lined the process of creating CGI scripts.
Matt Kruse
mkruse@netexpress.net
http://www.mattkruse.com/
------------------------------
Date: Wed, 24 Nov 1999 20:34:35 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Test for eval() without using eval() ??
Message-Id: <s3oiur9mrrp75@corp.supernews.com>
Matt Kruse (mkruse@rens.com) wrote:
: Craig Berry <cberry@cinenet.net> wrote
: > I'm curious how it can be that a script (algorithm) which requires locking
: > in any context can be said to "run just fine" without file locking.
:
: Well, the script can either be updated by everyone OR just used by a single
: administrator. In cases where file locking isn't available, users should
: only use a single administrator if they want to be that their data will not
: be corrupted.
If the script autodetects that flock is unavailable, does it tell the
user(s) about this important restriction?
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "They do not preach that their God will rouse them
a little before the nuts work loose." - Kipling
------------------------------
Date: 24 Nov 1999 16:32:57 -0500
From: kevin montuori <montuori@acs.neu.edu>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <ygezow3o9rq.fsf@spot.acs.neu.edu>
>>> Craig Berry writes:
cb> Matt Kruse (mkruse@rens.com) wrote:
mk> For example, some people were trying to run the script on
mk> Win95/98 and found that it does not have flock. So, I put that
mk> in an eval. Easy enough. So now it runs just fine, but without
mk> file locking.
cb> I'm curious how it can be that a script (algorithm) which
cb> requires locking in any context can be said to "run just fine"
cb> without file locking.
it won't, but that's just nitpicking. frankly, it won't work
everywhere flock() is supported: consider a web farm fronted
by a reverse proxy server (squid's httpd-accelerator mode);
just because a file is locked on one filesystem does not mean
it's locked on another.
i should think it nearly impossible to write code without
demanding certain requirements of the environment where it is
to be run. perl can lead you to believe this is the case, and
is more prone to this false assumption than, say, C.
cheers,
k.
--
kevin montuori
interactive web services
northeastern university
------------------------------
Date: 24 Nov 1999 22:33:36 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: Test for eval() without using eval() ??
Message-Id: <slrn83opu0.e4n.simon@othersideofthe.earth.li>
Matt Kruse (comp.lang.perl.misc):
>Don't assume that my goal is stupid and erroneous if you don't understand
>it.
It seems the CGI-coder-called-Matt syndrome *is* contageous, after all.
--
Your own mileage may vary.
------------------------------
Date: Wed, 24 Nov 1999 12:29:46 -0800
From: Phil <ask_for_my_address_if_you_need_it@earthlink.net>
Subject: testing if a filehandle is open already
Message-Id: <383C4ABA.86FA04C@earthlink.net>
Here's the story. I have a recursive sub which needs to print data from
each node of a tree. I know three ways to handle this:
1) open the file outside of the sub and, within the sub, write the
global filhendle created outside.
2) open the file outside of the sub and pass a filehandle into the sub,
then write to that filehandle.
3) cat everything onto a variable inside of the sub and return the
variable for printing outside of the sub.
I currently use technique 2. However, I'd PREFER TO DO this:
4) pass the filename into the sub.
open the file unless the file is already opened for writing
write to the filehandle, recurse, repeat, and leave.
The main reason for wanting to go this route is so that the sub has a
consistant interface and opens the file itself.
Consider the following to be my current implimentation:
open( F, "> $ARGV[0]" )
or die "Cannot write to $ARGV[0].\n";
tree_to_file( $tree, \*F ); ## write $tree to file
inorder
sub tree_to_file {
my ( $tree, $handle ) = @_;
return 1 if ( not $tree ); ## continue traversing
tree_to_file( $tree->{LEFT}, $handle ); ## recurse left
if ( $tree->{SSN} !~ /\*$/ ) { ## print data to $handle
print $handle "$tree->{FOO}\n"; ## unless SSN contains trailing *
}
tree_to_file( $tree->{RIGHT}, $handle ); ## recurse right
}
and this to be my intended:
tree_to_file( $tree, $file ); ## write $tree to file
inorder
sub tree_to_file {
my ( $tree, $file ) = @_;
return 1 if ( not $tree ); ## continue traversing
unless F { ## this won't work . . .
open( F, "> $file" ) or return;
}
tree_to_file( $tree->{LEFT}, $file ); ## recurse left
if ( $tree->{SSN} !~ /\*$/ ) { ## print data to $handle
print F "$tree->{FOO}\n"; ## unless SSN contains trailing *
}
tree_to_file( $tree->{RIGHT}, $file ); ## recurse right
}
Thank you,
phil
------------------------------
Date: Wed, 24 Nov 1999 09:55:36 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: variable scoping
Message-Id: <slrn83nv38.edv.tadmc@magna.metronet.com>
On Wed, 24 Nov 1999 10:31:02 -0800, Helmut Messerer <helmut@cancon.com> wrote:
>I'm using perl, version 5.005_02 built for sun4-solaris.
>And I have the following problem:
>
> local $whatever;
> {
> my $i1;
> $i="i1";
> $$i='TEST';
Using Symbolic References is a very very bad idea, you know.
They are all _global_ variables.
Global variables are bad.
> pint "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
^^^^
^^^^
> }
>
>prints:
>i1=//TEST/TEST
No it doesn't.
It gripes about the bareword you have there.
>if I remove the first 'local' declaration, it prints:
>i1=TEST/TEST/TEST/TEST
I can't get it to do that, but we don't know what code you
are _really_ using.
It ain't the code you showed us though...
>is this supposed to be?
I think not, since my perl (5.005_02) doesn't do that
(after turning your pseudo-Perl into Perl)...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 24 Nov 1999 12:38:25 -0800
From: Helmut Messerer <helmut@cancon.com>
Subject: Re: variable scoping
Message-Id: <383C4CC1.508C@cancon.com>
Tad McClellan wrote:
>
> On Wed, 24 Nov 1999 10:31:02 -0800, Helmut Messerer <helmut@cancon.com> wrote:
>
> >I'm using perl, version 5.005_02 built for sun4-solaris.
> >And I have the following problem:
> >
> > local $whatever;
> > {
> > my $i1;
> > $i="i1";
> > $$i='TEST';
>
> Using Symbolic References is a very very bad idea, you know.
> They are all _global_ variables.
>
> Global variables are bad.
> > pint "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
> ^^^^
> ^^^^
> > }
> >
> >prints:
> >i1=//TEST/TEST
>
> No it doesn't.
> It gripes about the bareword you have there.
sorry, it should be a 'print' the r got deleted while trying to
indent...
>
> >if I remove the first 'local' declaration, it prints:
> >i1=TEST/TEST/TEST/TEST
>
> I can't get it to do that, but we don't know what code you
> are _really_ using.
>
> It ain't the code you showed us though...
>
> >is this supposed to be?
>
> I think not, since my perl (5.005_02) doesn't do that
> (after turning your pseudo-Perl into Perl)...
>
> --
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
sorry about the confusion, let me try again...
I played around a little more with the following results:
[--1--]
#!/usr/bin/perl -w
{
$i1='';
my $i="i1";
$$i='TEST';
print "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
}
produces
i1=TEST/TEST/TEST/TEST
[--2--]
#!/usr/bin/perl -w
{
my $i1='';
my $i="i1";
$$i='TEST';
print "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
}
produces
i1=//TEST/TEST
that's how the whole thing got started, I had to remove the 'my' to get
the code to work...
I now tested it with 'local' instead of 'my' and this seems to work as
well. What I want to know though is why this is, so that I can avoid it
in the future.
------------------------------
Date: 24 Nov 1999 14:34:05 -0500
From: Nandu Shah <nandu@cimedia.com>
Subject: Re: variable scoping
Message-Id: <m3k8n73cr6.fsf@budgie.cimedia.com>
Helmut Messerer <helmut@cancon.com> writes:
> local $whatever;
> {
> my $i1;
> $i="i1";
> $$i='TEST';
> pint "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
> }
>
> prints:
> i1=//TEST/TEST
>
> if I remove the first 'local' declaration, it prints:
> i1=TEST/TEST/TEST/TEST
>
> is this supposed to be?
Yes, if you meant "'my' declaration", and not "'local' declaration".
The 'local' in this code sample doesn't affect the rest whatsoever.
You probably realize that '$i1' means the lexical variable, but you
probably think that '${i1}' is a symbolic dereference. Not so--see
the perlref man page for details.
Nandu
------------------------------
Date: 24 Nov 1999 15:37:51 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: variable scoping
Message-Id: <slrn83omrf.m2v.abigail@alexandra.delanet.com>
Helmut Messerer (helmut@cancon.com) wrote on MMCCLXXVI September MCMXCIII
in <URL:news:383C4CC1.508C@cancon.com>:
**
** [--2--]
** #!/usr/bin/perl -w
** {
** my $i1='';
** my $i="i1";
** $$i='TEST';
** print "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
** }
**
** produces
** i1=//TEST/TEST
**
**
** that's how the whole thing got started, I had to remove the 'my' to get
** the code to work...
** I now tested it with 'local' instead of 'my' and this seems to work as
** well. What I want to know though is why this is, so that I can avoid it
** in the future.
It all has to do with scoping, lexical variables and package variables.
Consult the manpages.
BTW, what do you want to avoid?
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
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 1483
**************************************