[20007] in Perl-Users-Digest
Perl-Users Digest, Issue: 2202 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 25 18:05:59 2001
Date: Sun, 25 Nov 2001 15:05:07 -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: <1006729507-v10-i2202@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 25 Nov 2001 Volume: 10 Number: 2202
Today's topics:
Re: 10 by 10 (error results?) <5l259r001@sneakemail.com>
Re: [Newbie] Iterating through dirs recursively <assafl@flashnetworks.com>
Re: [Newbie] Iterating through dirs recursively <echang@netstorm.net>
Re: A Perl Bug? (Mark Jason Dominus)
Re: A Perl Bug? <uri@stemsystems.com>
Re: A Perl Bug? <uri@stemsystems.com>
Re: A Perl Bug? <gisle@ActiveState.com>
Re: A Perl Bug? <jake@chaogic.com>
Re: A Perl Bug? <uri@stemsystems.com>
Re: A Perl Bug? <echang@netstorm.net>
Declaring a filehandle <p.tomkins@virgin.net>
Re: Declaring a filehandle <spam@thecouch.homeip.net>
Re: Declaring a filehandle <5l259r001@sneakemail.com>
file or directory exists question... <no_mto@hotmail.com>
Re: file or directory exists question... (Peter J. Acklam)
Re: file or directory exists question... (Wojtek Walczak)
Re: file or directory exists question... (Logan Shaw)
Placing sitemgr within its own directory...? (no-sig) (TC)
spurious warning with special var LOG in 5.6.1 (John)
Re: spurious warning with special var LOG in 5.6.1 <godzilla@stomp.stomp.tokyo>
Re: spurious warning with special var LOG in 5.6.1 (Honza Pazdziora)
Re: spurious warning with special var LOG in 5.6.1 <godzilla@stomp.stomp.tokyo>
Re: spurious warning with special var LOG in 5.6.1 <5l259r001@sneakemail.com>
Re: TESTING CGI SCRIPTS WITH ACTIVE PERL <5l259r001@sneakemail.com>
Re: variable scope <bart.lateur@pandora.be>
Re: variable scope <bart.lateur@pandora.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Nov 2001 20:28:02 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: 10 by 10 (error results?)
Message-Id: <9trglr$29o$06$1@news.t-online.com>
"Jason Gray" <perl@cableone.net> schrieb im Newsbeitrag
news:u01ka7l90m2cf6@corp.supernews.com...
| Hi, I am having trouble once again with my 10 by 10 results, for some
reason
| when i click the "See more" link in my code it gives it an awkward
position
| everytime, its reading from the files position though, is there anyway i
can
| fix this? To view an example, go here:
| http://www.jayb.net/cgi-bin/cgiwrap/jayb/pp/test.pl,
Seems to work for me. The position is in bytes, not entries.
| My following code:
|
| &parse($seperator);
|
| my $DB = "data.txt";
| my ($pos, @matches, $last_loc, $more);
|
| print "Content-type: text/html\n\n";
|
| open FILE, $DB or die "can't read $DB: $!";
| seek FILE, $pos, 0 if $pos = $in{'pos'};
| while (<FILE>) {
| chomp(my @fields = split /\\n/);
| if ($fields[0]) {
| $last_loc = tell(FILE) - length; # get position
| push @matches, $fields[0];
| last if @matches == 11; # yes, 11
| }
| }
| close FILE;
|
| $more = @matches == 11 and pop @matches;
|
| print map{ $_, "<br>" } @matches;
Seems an awkward way of doing
print "$_<br>" foreach @matches;
| $last_loc -= 1;
$last_loc--;
| more_button($last_loc) if $more;
|
| sub more_button {
| my ($pos) = @_;
| print "<br>See <a href=\"test.pl?pos=$pos\">more</a>.\n";
| }
| "Just Another Perl Programmer"
^^^^^^^^^^
Sure you got that right?
HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Sun, 25 Nov 2001 18:24:16 +0200
From: "Assaf Lavie" <assafl@flashnetworks.com>
Subject: Re: [Newbie] Iterating through dirs recursively
Message-Id: <9tr602$it6$1@news.att.net.il>
"Wolfram Pfeiffer" <wolfram.pfeiffer@bigfoot.com> wrote in message
news:9tqgqu$q3v$1@news.rz.uni-karlsruhe.de...
> Assaf Lavie <assafl@flashnetworks.com> wrote:
> > I have a recursive function that works on every file in a certain
directory
> > and then calls itself for any sub-directory.
> > Question is: How do I begin to iterate over the sub-dir's files? Do I
need
> > to change the working directory (how?), or can I simply do this:
> > (<$subdir/*>)?
>
> You can change your working directory with 'chdir' (perldoc perlfunc).
Thanks.
Will I need to change it back when I return?
> You should have a look at File::Find, though, it probably already does
> what you want to do.
No I don't think so. I'm not searching these files; I'm doing some
source-control manipluation on them.
Assaf.
------------------------------
Date: Sun, 25 Nov 2001 17:09:27 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: [Newbie] Iterating through dirs recursively
Message-Id: <Xns91647CBEED16Cechangnetstormnet@207.106.92.86>
"Assaf Lavie" <assafl@flashnetworks.com> wrote in
news:9tr602$it6$1@news.att.net.il:
> "Wolfram Pfeiffer" <wolfram.pfeiffer@bigfoot.com> wrote in message
> news:9tqgqu$q3v$1@news.rz.uni-karlsruhe.de...
>> Assaf Lavie <assafl@flashnetworks.com> wrote:
>> > I have a recursive function that works on every file in a
>> > certain directory and then calls itself for any sub-directory.
>> > Question is: How do I begin to iterate over the sub-dir's files?
>> > Do I need to change the working directory (how?), or can I
>> > simply do this: (<$subdir/*>)?
>>
>> You can change your working directory with 'chdir' (perldoc
>> perlfunc).
> Thanks.
> Will I need to change it back when I return?
>
>> You should have a look at File::Find, though, it probably already
>> does what you want to do.
> No I don't think so. I'm not searching these files; I'm doing some
> source-control manipluation on them.
Hmm. First you say you are a newbie, then you assume you know what
File::Find does without even looking at the documentation on it.
To repeat the original advice, "You should have a look at File::Find,
it probably already does what you want to do."
find - traverse a file tree
finddepth - traverse a directory structure depth-first
The "find" refers to finding files in a directure structure, not to
searching the the contents of the files. Unsurprisingly, you are not
the first programmer who has needed to do this. :)
Many common programming tasks have already been addressed - thoroughly
and safely - in the modules that are part of the standard Perl
distribution.
--
EBC
------------------------------
Date: Sun, 25 Nov 2001 14:17:12 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: A Perl Bug?
Message-Id: <3c00fd68.60b0$186@news.op.net>
In article <iqm10ukp5apf33h3k7n09bramb0srk8843@4ax.com>,
Bart Lateur <bart.lateur@pandora.be> wrote:
>undef() is not defined. There's no way your program is supposed to know
>the difference between an autovivifies element, or one which got
>undeffed.
>
>But somehow, Data::Dumper knows, and reports it. See:
I always considered that a bug in Data::Dumper.
Internally, the difference is that the empty autovivified entries have
NULL pointers in the array elements, but when you assign an explicit
'undef', the array contains &PL_sv_undef.
--
@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, 25 Nov 2001 17:24:37 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A Perl Bug?
Message-Id: <x7d726ahkd.fsf@home.sysarch.com>
>>>>> "JF" == Jake Fan <jake@chaogic.com> writes:
JF> Thanks for the tutorial link. I was only partially and vaguely
JF> aware of the autovivification issue, now things are much clearer.
JF> But still, why "$x[0] ||= ..." autovivifies, while "$x[0] = $x[0]
JF> || ..." doesn't? Does not seem consistent.
because of the way it is implemented. ||= is set up to be faster than
the expanded version as well as more succinct. the compiler knows more
about the actual code with ||= and can do optimizations like
autovivifying first. with the full expression it has to do much more
analysis to get the same effect.
JF> (ps/btw/lol/imho/ymmv/..., let's not start another flame war over the
JF> "top-post" issue. I have my own reasons for "top-posting" but let's just
JF> call it different personal preference. You don't have to agree with
JF> people's different styles, but at least respect their choices. After all,
JF> one of the greatest spirits of the 'net, OSS, or even Perl is freedom and
JF> choices. TMTOWTDI.)
this group does not tolerate top posting. you will get killfiled for
doing it. your personal preferences have nothing to do with it. it is
inconsiderate of all the other readers so it is very personal to them as
well. this is not perl but usenet nettiquette and TMTOWTDI does not
apply.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 25 Nov 2001 17:28:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A Perl Bug?
Message-Id: <x78zcuahdp.fsf@home.sysarch.com>
>>>>> "M" == Mark <admin@asarian-host.net> writes:
>>
>> $x[0] ||= undef;
>>
>> Not that such operation makes much sense; but just out of
>> curiosity, would it autovivify and then be undef-ed again?
>> Or would perl see through this?
M> Or would this still autovivify a "defined" for $x[0], but just undef its
M> content?
as bart pointed out, there is a subtle difference between an empty array
slot and one that has an undef value. both look like undef from the
point of view of perl expressions. but the former has no SV in the slot
and the other has one with undef in it. it is analagous to a hash entry
with a value of undef vs. a missing entry. exists was created to detect
this difference. there isn't as pressing a need to tell the difference
in array elements that are missing or filled with undef.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 25 Nov 2001 17:58:49 GMT
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: A Perl Bug?
Message-Id: <m3bshqzq6f.fsf@ActiveState.com>
mjd@plover.com (Mark Jason Dominus) writes:
> Internally, the difference is that the empty autovivified entries have
> NULL pointers in the array elements, but when you assign an explicit
> 'undef', the array contains &PL_sv_undef.
This is wrong. The empty autovivified entries have &PL_sv_undef.
Those you assign have separate SVs that happen to be undef.
--
Gisle Aas
------------------------------
Date: Sun, 25 Nov 2001 12:08:29 -0600
From: "Jake Fan" <jake@chaogic.com>
Subject: Re: A Perl Bug?
Message-Id: <9trc3k$8gv$1@Masala.CC.UH.EDU>
Uri Guttman has an in-depth article on autovivification
(http://tlc.perlarchive.com/articles/perl/ug0002.shtml, in an earlier post)
which is a good read, but it doesn't cover this assignment issue. IMHO,
sometimes autovivification makes perfect sense, but in this assignment case,
it'd be more consistent and intuitive not to autovivify LHS. Your code
example could be re-written so that it's a bit more illustrative:
$x{aha} = $x{aha} || scalar keys %x;
$y{aha} ||= scalar keys %y;
# They do different things. But why make ||= (and .=, +=, etc.) special?
Anyhow, I think it definitely deserves to be documented.
On a side note, sometimes exits() does autovivify things, if not its
argument itself. The following code was taken from the article mentioned
above:
use Data::Dumper ;
$HoH = {
'foo' => {
'x' => 23,
},
'bar' => {
'y' => 18,
},
} ;
print Dumper $HoH ;
print "baz->z doesn't exist\n" unless exists $HoH->{'baz'}{'z'} ;
print Dumper $HoH ;
# $HoH->{'baz'} is autovivified by exists(), which does make sense.
Bart Lateur <bart.lateur@pandora.be> wrote in message
news:94m10uoqlvr3r6n5k2gkhs0d25g5r0i1o5@4ax.com...
> Witness the difference:
>
> my(%x, %y);
> $x{aha} = scalar keys %x unless exists $x{aha};
> $y{aha} ||= scalar keys %y;
> print "\$x{aha} = $x{aha}\n\$y{aha} = $y{aha}\n";
>
> (Note: the "scalar" is only there for clarity. keys() in scalar context
> returns the number of keys.)
>
> You seem to expect the same in %x and %y afterwards. Yet $x{aha} is 0,
> $y{aha} is 1. Why?
>
> Because
>
> $y{aha} ||= ...
>
> makes $y{aha} spring to life (value = undef) if it didn't exist already
> before the RHS is evaluated. Thus, at that time, keys %y contains one
> entry, for "aha".
>
> But
>
> $x{aha} = scalar keys %x unless exists $x{aha};
>
> does not have the same effect. exists() doesn't make it exist, if it
> didn't. Thus, at the time the RHS is evaluated, $x{aha} doesn't exist
> yet, %x is still empty, keys %x returns 0. Only AFTER THAT, does $x{aha}
> spring to life, and it gets the value of the expression: 0.
>
> Is it documented somewhere? I don't know. I know this from experience.
> When you think of it, it makes sense. It deserves to be documented.
>
------------------------------
Date: Sun, 25 Nov 2001 19:04:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A Perl Bug?
Message-Id: <x73d32acy2.fsf@home.sysarch.com>
>>>>> "JF" == Jake Fan <jake@chaogic.com> writes:
JF> On a side note, sometimes exits() does autovivify things, if not its
^s
JF> argument itself. The following code was taken from the article mentioned
JF> above:
exists doesn't do the autovivification, perl does. anytime you access
referenced entries through an undef value, perl will replace the undef
with an appropriate ref. exists is not special here at all. in fact many
(and i in the past) complained that exists should be special in the
other way and NOT autovivify its argument.
and i didn't cover the ||= case since i didn't know about it then and it
is not a ref/deref issue where it crops up much more often. but it is
related to the assigning of $x[10] = 1 and 0-9 are autovivified to
undef.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 25 Nov 2001 19:12:42 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: A Perl Bug?
Message-Id: <Xns916491A462EBAechangnetstormnet@207.106.93.86>
"Jake Fan" <jake@chaogic.com> wrote in
news:9trc3k$8gv$1@Masala.CC.UH.EDU:
> Uri Guttman has an in-depth article on autovivification
> (http://tlc.perlarchive.com/articles/perl/ug0002.shtml, in an
> earlier post) which is a good read, but it doesn't cover this
> assignment issue. IMHO, sometimes autovivification makes perfect
> sense, but in this assignment case, it'd be more consistent and
> intuitive not to autovivify LHS. Your code example could be
> re-written so that it's a bit more illustrative:
Whose code example? Uri's? Mine? (Of course not mine; I didn't post
one - but it sounds that way since I'm the one reading this article.)
It is impossible to tell who/what you are referring to.
[rest of confusingly top-posted srticle snipped.]
--
EBC
------------------------------
Date: Sun, 25 Nov 2001 21:55:19 -0000
From: "news.bmthonline.net" <p.tomkins@virgin.net>
Subject: Declaring a filehandle
Message-Id: <3c016b77$1_1@news2.vip.uk.com>
Hi,
I know that we can declare a scoped scalar, array or hash as
my ($scalar, @array, %hash)
but how do we declare a filehandle?
Thanks
Paul
------------------------------
Date: Sun, 25 Nov 2001 17:40:24 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: Declaring a filehandle
Message-Id: <UqeM7.3821$Mm.439332@wagner.videotron.net>
"news.bmthonline.net" <p.tomkins@virgin.net> wrote in message
news:3c016b77$1_1@news2.vip.uk.com...
> Hi,
>
> I know that we can declare a scoped scalar, array or hash as
> my ($scalar, @array, %hash)
I beleive it's:
local (*FH);
>
> but how do we declare a filehandle?
>
> Thanks
>
> Paul
>
>
------------------------------
Date: Sun, 25 Nov 2001 23:37:12 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: Declaring a filehandle
Message-Id: <9trroj$hqj$02$1@news.t-online.com>
"news.bmthonline.net" <p.tomkins@virgin.net> schrieb im Newsbeitrag
news:3c016b77$1_1@news2.vip.uk.com...
| Hi,
|
| I know that we can declare a scoped scalar, array or hash as
| my ($scalar, @array, %hash)
|
| but how do we declare a filehandle?
{
open( my $fh, "my_pants") or die "Could not open my pants! $!";
my $var = <$fh>; # reads the next line. (je nach $/)
}
my $var = <$fh>; # error, out of scope!
HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Sun, 25 Nov 2001 19:05:47 +0100
From: "MAGiC MANiAC^mTo" <no_mto@hotmail.com>
Subject: file or directory exists question...
Message-Id: <9trc80$1hrg$1@news.kabelfoon.nl>
how do I know if a file exists or not,
and how do I know if a directory exists or not...
for the file, I need to know if a file exists and gives me a return value.
for example 0=file doesn't exist and 1=file already exists.
for the directory, I want to create a directory when it is not exist.
Can someone helps me how I can do this?...
------------------------------
Date: 25 Nov 2001 19:19:35 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: file or directory exists question...
Message-Id: <r8qmsog8.fsf@online.no>
"MAGiC MANiAC^mTo" <no_mto@hotmail.com> wrote:
> how do I know if a file exists or not, and how do I know if a
> directory exists or not...
>
> for the file, I need to know if a file exists and gives me a
> return value. for example 0=file doesn't exist and 1=file
> already exists.
>
> for the directory, I want to create a directory when it is not
> exist.
Look in the "perlfunc" manual page under "-X" for "-e", "-f"
and "-d".
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: 25 Nov 2001 19:02:59 GMT
From: gminick@hacker.pl (Wojtek Walczak)
Subject: Re: file or directory exists question...
Message-Id: <slrna02cd5.1aq.gminick@hannibal.localdomain>
Dnia Sun, 25 Nov 2001 19:05:47 +0100, MAGiC MANiAC^mTo napisa³(a):
>how do I know if a file exists or not,
if(-e '/etc/passwd') {
print "exist\n";
}
else {
... # not exists
}
--
[ Wojtek gminick Walczak ][ http://hacker.pl/gminick/ ]
[ gminick (at) hacker.pl ][ gminick (at) klub.chip.pl ]
------------------------------
Date: 25 Nov 2001 15:57:41 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: file or directory exists question...
Message-Id: <9trpgl$fa8$1@starbuck.cs.utexas.edu>
In article <9trc80$1hrg$1@news.kabelfoon.nl>,
MAGiC MANiAC^mTo <no_mto@hotmail.com> wrote:
>for the file, I need to know if a file exists and gives me a return value.
>for example 0=file doesn't exist and 1=file already exists.
Others have already mentioned "-e".
>for the directory, I want to create a directory when it is not exist.
The easiest thing to do in that case is to call mkdir() without first
checking if the directory exists. If it doesn't exist, then mkdir()
will create it. If it does exist, then mkdir() will just return an
error.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: Sun, 25 Nov 2001 15:11:39 -0600 (CST)
From: TcTech@webtv.net (TC)
Subject: Placing sitemgr within its own directory...? (no-sig)
Message-Id: <27852-3C015E8B-446@storefull-292.iap.bryant.webtv.net>
Below is a snippet of codes, within a site-manager I am presently
working on.
Presently, the site-manager will only work when placed in the parent
directory, but I would like to place it in its own sub-directory, so I
can passwd protect it.
(This is what I presently have)
=====
### find form and query data
$ch_dir = $q->param('cd') if $q->param('cd');
$action = $q->param('action') if $q->param('action');
$operation = $q->param('operation') if $q->param('operation');
if (($ch_dir) && (!$action) && (!$operation)) {
$done = "<b><strong>$ch_dir</strong></b> sub-directory files listed:";
}
### location of file and location of top directory
$this_url = $ENV{'SCRIPT_NAME'};
$mgr = $this_url;
@urls = split(/\//,$this_url);
pop(@urls);
$top_dir = $urls[$#urls];
if ($top_dir) {
$top_dir = '/'.$top_dir;
}
$top_dir .= '/';
$c_l_c = '<font color=0000ff face="System"><b>';
### find out if we are in another directory
if ($ch_dir) {
$new_dir = "$ch_dir";
} else {
$new_dir = '.';
}
if ($ch_dir) {
@ch_dirs = split(/\//,$ch_dir);
pop(@ch_dirs);
$up_dir = join("\/",@ch_dirs);
}
if ($up_dir) {
$last_dir = "cd=$up_dir";
}
### directory we are in
$this_dir = $top_dir.$ch_dir;
$cur_loc = "<font size=4 face=\"Tahoma\">
<br>
<b>
<strong>
This Directory is:
<br>
$this_dir
</strong>
</b>
</font>
<br><br>";
=====
Is this possible and, if so, would the changes necessary be minimal or
excessive??
(BTW, I am new to perl, but learning as I go, so bear with me:)
..TC
------------------------------
Date: 25 Nov 2001 08:54:52 -0800
From: nospam@ne9.com (John)
Subject: spurious warning with special var LOG in 5.6.1
Message-Id: <24badd3f.0111250854.17d5e8a6@posting.google.com>
Hi, folks,
Just installed 5.6.1 on linux 2.4.2 (RH7.1), and now
open(LOG,...) produces a "main::LOG used only once" warning
that 5.0005_3 (and, I think, 5.6.0) never did.
'man perldelta' indicates that this is a bug that has been fixed... ?
The code that produces the warning is as follows:
BEGIN {
use CGI::Carp qw(carp carpout fatalsToBrowser confess cluck);
open(LOG, ">>./error_log") or die("Unable to open error_log: $!\n");
carpout(LOG);
}
The error message is:
[Sun Nov 25 10:34:48 2001] ascript.cgi:
Name "main::LOG" used only once: possible typo at
[..]myscript.cgi line 3.
The fix/workaround appears to be to add this:
our $LOG;
before the open() -- note: 'my' still produces the warning.
Am I missing something?
thanks,
John bro+usenet (at) ne9 (dot) com
------------------------------
Date: Sun, 25 Nov 2001 11:23:15 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: spurious warning with special var LOG in 5.6.1
Message-Id: <3C014523.FDAE4DE0@stomp.stomp.tokyo>
John wrote:
> Just installed 5.6.1 on linux 2.4.2 (RH7.1), and now
> open(LOG,...) produces a "main::LOG used only once" warning
> that 5.0005_3 (and, I think, 5.6.0) never did.
> 'man perldelta' indicates that this is a bug that has been fixed... ?
This is untrue. Perl 5.6.0 and some older versions will
generate this warning as well, using your example code.
This is not a bug. It is an error in your code.
> The code that produces the warning is as follows:
> BEGIN {
> use CGI::Carp qw(carp carpout fatalsToBrowser confess cluck);
> open(LOG, ">>./error_log") or die("Unable to open error_log: $!\n");
> carpout(LOG);
> }
> The error message is:
> [Sun Nov 25 10:34:48 2001] ascript.cgi:
> Name "main::LOG" used only once: possible typo at
> [..]myscript.cgi line 3.
You have neglected to close your filehandle.
> The fix/workaround appears to be to add this:
> our $LOG;
> before the open() -- note: 'my' still produces the warning.
Your fix is to close your filehandle as it should be.
> Am I missing something?
Yes. You are missing a close (FILEHANDLE); in your code.
Godzilla!
------------------------------
Date: Sun, 25 Nov 2001 20:05:53 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: spurious warning with special var LOG in 5.6.1
Message-Id: <slrna02jp0.96lc.adelton@nemesis.fi.muni.cz>
On Sun, 25 Nov 2001 11:23:15 -0800, Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> > The code that produces the warning is as follows:
>
> > BEGIN {
> > use CGI::Carp qw(carp carpout fatalsToBrowser confess cluck);
> > open(LOG, ">>./error_log") or die("Unable to open error_log: $!\n");
> > carpout(LOG);
> > }
>
> > The error message is:
> > [Sun Nov 25 10:34:48 2001] ascript.cgi:
> > Name "main::LOG" used only once: possible typo at
> > [..]myscript.cgi line 3.
>
> Yes. You are missing a close (FILEHANDLE); in your code.
I might be missing something, but the presence of the name LOG has
nothing to do with the operations you do with the filehandle. You
might be right that adding close(LOG) would silence the "used only
once" message, but in general your advice and the reasons you state
are not correct.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, mod_perl, DBI, Oracle, auth. WWW servers, XML/XSL, ...
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Sun, 25 Nov 2001 12:42:31 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: spurious warning with special var LOG in 5.6.1
Message-Id: <3C0157B7.EAE404FB@stomp.stomp.tokyo>
Honza Pazdziora aka John aka Frank Gostak aka The CLPM Troll wrote:
> Godzilla! wrote:
(snipped)
> > Yes. You are missing a close (FILEHANDLE); in your code.
> I might be missing something,
Yes. You are missing locking and loading your brain
before firing off your mouth.
> but the presence of the name LOG has
> nothing to do with the operations you do with the filehandle. You
> might be right that adding close(LOG) would silence the "used only
> once" message, but in general your advice and the reasons you state
> are not correct.
Direct testing indicates differently.
You are wrestling, unsuccessfully, with two different
packages, Perl's and me, neither of which you have the
intellectual capacity with which to deal without suffering
a serious mental militia style rout, at my hand.
* coughs *
Annoys me, this habit of yours of blowing smoke out of your arse, Frank.
Godzilla!
------------------------------
Date: Sun, 25 Nov 2001 23:40:56 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: spurious warning with special var LOG in 5.6.1
Message-Id: <9trrvj$3a2$04$1@news.t-online.com>
| Honza Pazdziora aka John aka Frank Gostak aka The CLPM Troll wrote:
|
| > Godzilla! wrote:
[Do not pay any attention to what Godzilla says. It is a troll, and
has no decent working knowledge of Perl or programming in general.
Search groups.google.com to see a history of its posts and replies
to these posts.]
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Sun, 25 Nov 2001 20:31:28 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: TESTING CGI SCRIPTS WITH ACTIVE PERL
Message-Id: <9trgs9$cav$05$1@news.t-online.com>
"Re: TESTING CGI SCRIPTS WITH ACTIVE PERL"
Don't shout, people will ignore you.
"cb" <spamcop@spamcop.net> schrieb im Newsbeitrag
news:nI0M7.1$407.174@typhoon.nyu.edu...
| I haven't used Active Perl in a while and completely forgot on how to use
| it. If I want to write CGI script and test it with a server in what
| directory do I put my html and pl files and what else do I have to do to
| test it?
You completely forgot where you should ask this. This is not a Perl
question.
This is about your webserver configuration. Even if this was on-topic,
nobody could help you without knowledge of your configuration.
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Sun, 25 Nov 2001 14:44:42 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: variable scope
Message-Id: <ci020ucal82iampsdhfl72hmp834kgs4is@4ax.com>
Joe Schaefer wrote:
>Bart Lateur <bart.lateur@pandora.be> writes:
>
>> Perhaps that could be an addition to B::Xref, if it's not already in
>> there. (n.b. invoke with "-MO=Xref" on the command line)
>
>What I had in mind was something like C's lint, possibly with
>programmable "clauses" to indicate one's idea of "bad practice",
>but I'm not aware of anything that specifically addresses masked
>lexicals. B::Lint would be a natural candidate; something like
>
> % perl -MO=Lint,no-masked-lex script.pl
>
>might be nice here.
You're absolutely right. I haven't used B::Lint yet, so I had overlooked
the fact that it even exists. Oops. But of course, that is where such a
test belongs.
>Somehow I'm skeptical that optree walking/
>parsing is well-suited for this sort of thing, but I'll certainly
>look into B::Lint more closely.
It should well be? The op tree certainly ought to contain more info than
what B::XRef emits. If two different variables with the name $x exist,
you should be able to spot it, in the op tree.
>OTOH, I find it strange that (AFAIK) there's no development suite
>in Perl that's even remotely comparable to something as sophisticated
>as lclint.
Then complain to perl-qa ;-) See the list of mailing lists at
<http://lists.perl.org> = <http://lists.cpan.org>. Surely some people
there will share your concern. (According to the description of the
mailing lists, perl-qa-metrics is more where it belongs, but that
mailing list is virtually dead...) BTW "qa" stands for quality
assurance", and what you're complaining about here, certainly falls
under that umbrella.
>Unfortunately I don't think B::Xref can be easily modified to keep
>track of the scope. Here's a patch that lets you see how it walks
>the op tree
That's a very nice initiative. Even though I haven't tried it yet, it
most certainly feels like an incentive for me to go and track down that
bug in B::XRef that I stumbled over a few months ago. I even forgot
exactly what it was about :-/, but I think that B::XRef sometimes fails
to properly report where a variable is declared, IIRC. I had been
postponing doing this indefinitely, until now. Maybe.
--
Bart.
------------------------------
Date: Sun, 25 Nov 2001 15:00:19 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: variable scope
Message-Id: <9g120ucu1dqie3pj2ok0vfotgjenl7ndok@4ax.com>
Bart Lateur wrote:
> it
>most certainly feels like an incentive for me to go and track down that
>bug in B::XRef that I stumbled over a few months ago. I even forgot
>exactly what it was about :-/, but I think that B::XRef sometimes fails
>to properly report where a variable is declared, IIRC.
I misremembered. It was not a variable, but a sub. For example, for this
script:
#! perl -w
foo();
exit;
sub foo {
print "Okido\n"
}
perl -MO=Xref test.pl returns (irrelevant stuff snipped):
File test.pl
Subroutine (definitions)
...
Package main
&foo s2
Subroutine (main)
Package main
&foo &2
So the sub definition (s2) and call (&2) are both on line 2!?!
Reverse the order of the call and the definition, and you'll get
different results for both:
#! perl -w
sub foo {
print "Okido\n"
}
foo();
-->
File test.pl
Subroutine (definitions)
Package main
&foo s4
...
Subroutine (main)
Package main
&foo &5
n.b. The sub definition is reported to be on the line with the closing
brace.
--
Bart.
------------------------------
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.
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 2202
***************************************