[32478] in Perl-Users-Digest
Perl-Users Digest, Issue: 3743 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 25 09:09:21 2012
Date: Wed, 25 Jul 2012 06:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 25 Jul 2012 Volume: 11 Number: 3743
Today's topics:
Re: Pls help old perl-monger with new version syntax? <justin.1207@purestblue.com>
Re: Pls help old perl-monger with new version syntax? <ben@morrow.me.uk>
Re: Pls help old perl-monger with new version syntax? <hjp-usenet2@hjp.at>
Re: Pls help old perl-monger with new version syntax? <ben@morrow.me.uk>
Re: Pls help old perl-monger with new version syntax? <rweikusat@mssgmbh.com>
Re: Pls help old perl-monger with new version syntax? <*@eli.users.panix.com>
Re: Pls help old perl-monger with new version syntax? <ben@morrow.me.uk>
Re: Pls help old perl-monger with new version syntax? <ben@morrow.me.uk>
Re: Pls help old perl-monger with new version syntax? <*@eli.users.panix.com>
Re: Pls help old perl-monger with new version syntax? <hjp-usenet2@hjp.at>
Re: Pls help old perl-monger with new version syntax? <ben@morrow.me.uk>
Re: Pls help old perl-monger with new version syntax? r.mariotti@fdcx.net
Re: Pls help old perl-monger with new version syntax? <xhoster@gmail.com>
Re: Pls help old perl-monger with new version syntax? <*@eli.users.panix.com>
Re: Pls help old perl-monger with new version syntax? <hjp-usenet2@hjp.at>
Re: Pls help old perl-monger with new version syntax? <rweikusat@mssgmbh.com>
Re: Pls help old perl-monger with new version syntax? <rweikusat@mssgmbh.com>
Re: Pls help old perl-monger with new version syntax? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 24 Jul 2012 15:17:49 +0100
From: Justin C <justin.1207@purestblue.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <ddn2e9-at5.ln1@zem.masonsmusic.co.uk>
On 2012-07-24, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
> Been doing perl since mid-90's. Just upgraded to the latest version
> 5.14.2 and many of my perl scripts are thowing errors like no
> tomorrow.
>
> I've spent several days trying to resolve the errors without much
> success so I thought I would post here as many must have experienced
> the same.
>
> I DID research quite extensively with perldoc and google and tried
> literally all the suggestions but here it goes anyway.
>
> It appears that using the pragmas warning and strict the newest
> version is requiring predefinition of variables prior to their use.
>
> Here's a snippet of my code:
>
> # Define pragmas
> use warnings;
> use strict;
> # Define ALL needed variables & indecies
> my $fn = '' unless defined($fn);
> my $ln = '' unless defined($ln);
> my $opt = '' unless defined($opt);
> my $rr = 0 unless defined($rr);
> my $x1 = '' unless defined($x1);
> my $x2 = '' unless defined($x2);
> my $x3 = '' unless defined($x3);
> my $x4 = '' unless defined($x4);
In addition to what others have said, I think this is
standard practice these days:
my ($fh, $ln, $opt, $x1, $x2, $x3, $x4);
my $rr = 0;
(though it's definitely preferred to declare them
only within the scope of where they're used)
It may be possible to include the declration of $rr
in the first line, but it depends on how it's used.
If it's just a counter, AIUI initialising with: my
$rr; and then later doing: $rr++; would be enough to
make it '1'.
I'm guessing that $x1, $x2, $x3 and $x4 are in some
way related. It may be better to have them in an
array or hash:
my @x;
push @x, where_x1_comes_from();
push @x, where_x2_comes_from();
etc.
or
my %x;
$x{one} = where_x1_comes_from();
$x{two} = where_x2_comes_from()l
...then later:
my $where_i'd_use_x1 = $x[0];
where_i'd_use_x2( $x[1] );
or
my $where_i'd_use_x1 = $x{one};
where_i'd_ise_x2($x{two});
I'm far from good at this stuff, stick around and
watch the experts tear holes in in the above, we'll
both learn something!
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 24 Jul 2012 16:41:44 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <oas2e9-1pp2.ln1@anubis.morrow.me.uk>
Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> On 2012-07-24 12:10, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
>
> > Been doing perl since mid-90's. Just upgraded to the latest version
> > 5.14.2 and many of my perl scripts are thowing errors like no
> > tomorrow.
>
> What was the last version of perl you used? Your script doesn't work
> with perl 5.8.8 (2006), so it probably doesn't work since at least 5.8.0
> (2002).
It doesn't work in 5.6.0 either (2000). So, 5005? Older? Good God.
> > my $fn = '' unless defined($fn);
<snip>
>
> So this means:
>
> if the value of the variable $fn is undef
> then
> create a new variable $fn in this lexical scope
> and assign the empty string to it.
>
> Except that the variable is created at compile time, so it will
> always exist in this scope even if there happened to be a variable $fn
> with a defined value in an outer scope.
That isn't quite true. The RHS of the 'unless' is logically before the
start of the scope of the new $fn, so this will indeed test the
definedness of $fn in the outer scope.
I find it hard to believe this *ever* worked in any perl which supported
'strict'. If it did it was certainly a bug. That 'defined' is accessing
an unqualified global, which is exactly what strict should prevent.
Maybe there was an exception for 'defined' at some point?
Ben
------------------------------
Date: Tue, 24 Jul 2012 17:59:10 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <slrnk0thie.lbb.hjp-usenet2@hrunkner.hjp.at>
On 2012-07-24 14:17, Justin C <justin.1207@purestblue.com> wrote:
> On 2012-07-24, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
>> # Define pragmas
>> use warnings;
>> use strict;
>> # Define ALL needed variables & indecies
>> my $fn = '' unless defined($fn);
>> my $ln = '' unless defined($ln);
>> my $opt = '' unless defined($opt);
>> my $rr = 0 unless defined($rr);
>> my $x1 = '' unless defined($x1);
>> my $x2 = '' unless defined($x2);
>> my $x3 = '' unless defined($x3);
>> my $x4 = '' unless defined($x4);
>
> In addition to what others have said, I think this is
> standard practice these days:
>
> my ($fh, $ln, $opt, $x1, $x2, $x3, $x4);
> my $rr = 0;
Why do you initialize only $rr and not the other variables?
> It may be possible to include the declration of $rr
> in the first line, but it depends on how it's used.
It also depends on how $fn .. $x4 are used. An empty string is not the
same as undef. If it is important that $fn .. $x4 contain an empty
string, they must be initialized to the empty string. If they can (or
even should) contain undef, then they need not be initialized
explicitely (perl will automatically initialize them to undef). Same for
$rr: If it is important that it contains the number 0, it must be
initialized. If it can contain undef, this is not necessary.
hp
--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Bill Code on asrg@irtf.org
------------------------------
Date: Tue, 24 Jul 2012 16:49:28 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <8ps2e9-1pp2.ln1@anubis.morrow.me.uk>
Quoth Justin C <justin.1207@purestblue.com>:
> On 2012-07-24, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
>
> > my $fn = '' unless defined($fn);
> > my $ln = '' unless defined($ln);
> > my $opt = '' unless defined($opt);
> > my $rr = 0 unless defined($rr);
> > my $x1 = '' unless defined($x1);
> > my $x2 = '' unless defined($x2);
> > my $x3 = '' unless defined($x3);
> > my $x4 = '' unless defined($x4);
>
> In addition to what others have said, I think this is
> standard practice these days:
>
> my ($fh, $ln, $opt, $x1, $x2, $x3, $x4);
> my $rr = 0;
Neither '' nor 0 are the same as undef, so I'm not sure why you've
singled out $rr here...
> (though it's definitely preferred to declare them
> only within the scope of where they're used)
Yes. In general, don't create a variable until you have something useful
to put in it. (This isn't always possible.)
> It may be possible to include the declration of $rr
> in the first line, but it depends on how it's used.
> If it's just a counter, AIUI initialising with: my
> $rr; and then later doing: $rr++; would be enough to
> make it '1'.
More generally, any or all of those may need to be explicitly
initialised to something other than undef to avoid warnings, but that
depends on how they are first used. If (as is common) all that matters
is that they are false unless and until assigned to, it's probably
better to leave them undefined.
> ...then later:
>
> my $where_i'd_use_x1 = $x[0];
> where_i'd_use_x2( $x[1] );
[Presumably this is after
package where_i;
our $d_use_x1;
sub d_use_x2 { ... }
somewhere? :)]
Ben
------------------------------
Date: Tue, 24 Jul 2012 17:10:26 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <87ipdd2l8t.fsf@sapphire.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Justin C <justin.1207@purestblue.com>:
[...]
>> (though it's definitely preferred to declare them
>> only within the scope of where they're used)
>
> Yes. In general, don't create a variable until you have something useful
> to put in it. (This isn't always possible.)
In general, don't declare variables in a lexical scope unless it
happens to be the outmost lexical scope of a subroutine. As soon as
this starts to become unwieldly, structure the code into a set of
subroutines and a controlling superroutine.
------------------------------
Date: Tue, 24 Jul 2012 21:07:43 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <eli$1207241704@qz.little-neck.ny.us>
In comp.lang.perl.misc, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> > What was the last version of perl you used? Your script doesn't work
> > with perl 5.8.8 (2006), so it probably doesn't work since at least 5.8.0
> > (2002).
> It doesn't work in 5.6.0 either (2000). So, 5005? Older? Good God.
Panix has 5.00403 installed.
perl5.00403 -we 'use strict; my $fn = q,, unless defined($fn);'
Global symbol "fn" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
> I find it hard to believe this *ever* worked in any perl which supported
> 'strict'.
I don't know if it is a panix quirk or not, but "use warnings" fails
below 5.6.0 here (error line wrapped):
$ perl5.00503 -we 'use warnings;'
Can't locate warnings.pm in @INC (@INC contains:
/pkg/perl-5.005_03/lib/perl5.00503/i386-netbsd
/pkg/perl-5.005_03/lib/perl5.00503
/pkg/perl-5.005_03/lib/site_perl/5.005/i386-netbsd
/pkg/perl-5.005_03/lib/site_perl/5.005 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
$
Elijah
------
there are ten versions of perl installed on panix's shell servers
------------------------------
Date: Tue, 24 Jul 2012 22:34:52 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <s0h3e9-n3u2.ln1@anubis.morrow.me.uk>
Quoth Eli the Bearded <*@eli.users.panix.com>:
>
> Panix has 5.00403 installed.
If that's the only version of perl they provide then find somewhere
else. Versions of perl before 5.8.1 have a known security hole, apart
from anything else (the hash algorithmic complexity attack).
> I don't know if it is a panix quirk or not, but "use warnings" fails
> below 5.6.0 here (error line wrapped):
That's expected. warnings.pm (and the whole lexical warnings
infrastructure) didn't exist before 5.6.
Ben
------------------------------
Date: Tue, 24 Jul 2012 22:36:33 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <14h3e9-n3u2.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
> > Quoth Justin C <justin.1207@purestblue.com>:
>
> >> (though it's definitely preferred to declare them
> >> only within the scope of where they're used)
> >
> > Yes. In general, don't create a variable until you have something useful
> > to put in it. (This isn't always possible.)
>
> In general, don't declare variables in a lexical scope unless it
> happens to be the outmost lexical scope of a subroutine. As soon as
> this starts to become unwieldly, structure the code into a set of
> subroutines and a controlling superroutine.
Are you just contradicting me to be contrary, or do you have a point?
Ben
------------------------------
Date: Tue, 24 Jul 2012 22:17:35 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <eli$1207241817@qz.little-neck.ny.us>
In comp.lang.perl.misc, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth Eli the Bearded <*@eli.users.panix.com>:
> > Panix has 5.00403 installed.
> If that's the only version of perl they provide then find somewhere
> else. Versions of perl before 5.8.1 have a known security hole, apart
You didn't read far enough. Last line in my post mentions that panix
has ten versions installed. 5.00403 is oldest, 5.14.2 is newest. I
was only looking at the old ones for that post.
Elijah
------
who does not use a sig (no dash-dash-space) but instead types out this line
------------------------------
Date: Wed, 25 Jul 2012 00:52:14 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <slrnk0u9ou.dnj.hjp-usenet2@hrunkner.hjp.at>
On 2012-07-24 15:41, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> On 2012-07-24 12:10, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
>> > my $fn = '' unless defined($fn);
><snip>
>>
>> So this means:
>>
>> if the value of the variable $fn is undef
>> then
>> create a new variable $fn in this lexical scope
>> and assign the empty string to it.
>>
>> Except that the variable is created at compile time, so it will
>> always exist in this scope even if there happened to be a variable $fn
>> with a defined value in an outer scope.
>
> That isn't quite true. The RHS of the 'unless' is logically before the
> start of the scope of the new $fn, so this will indeed test the
> definedness of $fn in the outer scope.
Yes, that's what I wrote.
But test will not determine whether a new $fn at the inner scope will be
created, just whether it will be initialized.
Consider:
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
{
my $fn = 5; # 7
{
my $fn = 3 unless $fn; # 10
say "inner scope: ", $fn; # 12
} # 13
say "outer scope: ", $fn; # 14
} # 16
__END__
This prints:
Use of uninitialized value $fn in say at ./foo line 12.
inner scope:
outer scope: 5
At compile time the compiler sees a my $fn declaration at line 7 and one
at line 10 in nested scopes. So it creates two $fn variables: One with a
scope from line 7 to line 16 and one from line 10 to 13.
It also creates code that assigns 3 to the inner $fn only if the outer
$fn is not true.
So at run time, the interpreter notices that the outer $fn has a true
value (5) and skips the assignment of 3 to the inner $fn. However the
inner $fn still exists with an initial value of undef, und the say at
line 12 will attempt to print that value (which results in a warning).
This is the basis for the old "my $x if 0" hack (but you you know that).
hp
--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Bill Code on asrg@irtf.org
------------------------------
Date: Wed, 25 Jul 2012 01:24:33 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <1vq3e9-lcv2.ln1@anubis.morrow.me.uk>
Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> On 2012-07-24 15:41, Ben Morrow <ben@morrow.me.uk> wrote:
> > Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> >> On 2012-07-24 12:10, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
> >> > my $fn = '' unless defined($fn);
> ><snip>
> >>
> >> So this means:
> >>
> >> if the value of the variable $fn is undef
> >> then
> >> create a new variable $fn in this lexical scope
> >> and assign the empty string to it.
> >>
> >> Except that the variable is created at compile time, so it will
> >> always exist in this scope even if there happened to be a variable $fn
> >> with a defined value in an outer scope.
> >
> > That isn't quite true. The RHS of the 'unless' is logically before the
> > start of the scope of the new $fn, so this will indeed test the
> > definedness of $fn in the outer scope.
>
> Yes, that's what I wrote.
Oh, I see. I obviously misread what you wrote; I thought you were saying
the defined would test the new $fn and so the test would always succeed.
> But test will not determine whether a new $fn at the inner scope will be
> created, just whether it will be initialized.
For now. An explicit 'my $x if 0' where the 0 can be determined to be
false at compile time already gives a deprecation warning; my
understanding is that once 'state' is firmly established this behaviour
will be removed altogether.
> {
> my $fn = 5; # 7
>
> {
> my $fn = 3 unless $fn; # 10
>
> say "inner scope: ", $fn; # 12
> } # 13
> say "outer scope: ", $fn; # 14
>
> } # 16
> __END__
>
> This prints:
>
> Use of uninitialized value $fn in say at ./foo line 12.
> inner scope:
> outer scope: 5
>
> At compile time the compiler sees a my $fn declaration at line 7 and one
> at line 10 in nested scopes. So it creates two $fn variables: One with a
> scope from line 7 to line 16 and one from line 10 to 13.
Strictly, one from line 9 to line 16 and one from line 12 to line 13.
That was my point: a lexical's scope does not start until the start of
the next statement, which can be extremely irritating. (I can see why it
was done--to be consistent with local, where the behaviour is useful--
but it's still the wrong thing to do.)
Ben
------------------------------
Date: Tue, 24 Jul 2012 22:51:43 -0400
From: r.mariotti@fdcx.net
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <fmmu08t4a735s3j189rt3bjncq4jkea4k9@4ax.com>
Gents,
Thanks for all the good comments. Makes the brain churn even harder.
Here's the skinny on why I asked this:
Again, in most of the perl programs I've created over the years, I
normally have a section near the top of the program where I define the
necessary variables and/or arrays/hashes/etc. In most cases these
fields will be used in the logic that follows and set to the
appropriate value when used. It could be a pointer, a temp variable,
the target of a function, etc.
Not until I began working with this version (5.14.2) included with
Ubuntu 12.04 LTS did I start receiving the referenced error message.
My prior version is what came with Ubuntu 8.04 so I can't say exactly
which one that was. But my existing perl programs did NOT throw that
error back then. Only when I try running them on this new version did
I start seeing this error.
The snippet of code I included in my post was an attempt to come up
with a process that would initialize these fields if they were not
aleady defined. That's why I used the unless defined clause.
My understanding of this function was that it was the perl equivalent
of the php isset function. However, even when I remove the unless
portion of the statements I still receive the same use of
uninitialized variable blah blah.
All I'm trying to do is understand how I can satisfy the syntax so the
programs resume working. They were in production.
So please keep up the comments as I and I'm sure others find them
informative. And if you understand my issue more clearly perhaps more
suggestions will follow.
Thanks
------------------------------
Date: Tue, 24 Jul 2012 20:08:54 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <500f6346$0$31106$ed362ca5@nr5-q3a.newsreader.com>
On 07/24/2012 02:34 PM, Ben Morrow wrote:
>
> Quoth Eli the Bearded <*@eli.users.panix.com>:
>>
>> Panix has 5.00403 installed.
>
> If that's the only version of perl they provide then find somewhere
> else. Versions of perl before 5.8.1 have a known security hole, apart
> from anything else (the hash algorithmic complexity attack).
That seems like a vanishingly small use-case as a security hole. It is
mostly a "Want to deny service to your own bad self? Well, go right
ahead, dumb-ass" hole.
The people who are using the vanishingly small use-case, of course,
would be expected to care.
Xho
------------------------------
Date: Wed, 25 Jul 2012 04:31:01 +0000 (UTC)
From: Eli the Bearded <*@eli.users.panix.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <eli$1207250029@qz.little-neck.ny.us>
In comp.lang.perl.misc, Xho Jingleheimerschmidt <xhoster@gmail.com> wrote:
> On 07/24/2012 02:34 PM, Ben Morrow wrote:
>> Versions of perl before 5.8.1 have a known security hole, apart
>> from anything else (the hash algorithmic complexity attack).
> That seems like a vanishingly small use-case as a security hole. It is
> mostly a "Want to deny service to your own bad self? Well, go right
> ahead, dumb-ass" hole.
If it is the one I'm thinking of, it is a big DOS problem in, say, a
CGI script that will stick all URL parameters in a hash.
The PHP fix for that problem is a config file limit on number of URL
parameters to put in the hash, rather than fixing the hash itself.
Elijah
------
i.e. the PHP fix is a badly tattered bandage
------------------------------
Date: Wed, 25 Jul 2012 10:27:24 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <slrnk0vbfc.qhv.hjp-usenet2@hrunkner.hjp.at>
On 2012-07-25 02:51, r.mariotti@fdcx.net <r.mariotti@fdcx.net> wrote:
> Not until I began working with this version (5.14.2) included with
> Ubuntu 12.04 LTS did I start receiving the referenced error message.
> My prior version is what came with Ubuntu 8.04 so I can't say exactly
> which one that was.
Probably 5.8.8 or 5.10.0. The code you posted definitely wouldn't have
worked with those versions.
> But my existing perl programs did NOT throw that
> error back then. Only when I try running them on this new version did
> I start seeing this error.
>
> The snippet of code I included in my post was an attempt to come up
> with a process that would initialize these fields if they were not
> aleady defined. That's why I used the unless defined clause.
So this was already an attempt to work around the error message?
Please post a script which did work on Ubuntu 8.04 and which doesn't
work on Ubuntu 12.04.
> My understanding of this function was that it was the perl equivalent
> of the php isset function.
I don't understand PHP well enough to answer that question. The perl
defined() function is simple: It returns false if its argument is undef,
otherwise true.
> However, even when I remove the unless
> portion of the statements I still receive the same use of
> uninitialized variable blah blah.
So, this script:
# Define pragmas
use warnings;
use strict;
# Define ALL needed variables & indecies
my $fn = '' ;
my $ln = '' ;
my $opt = '' ;
my $rr = 0 ;
my $x1 = '' ;
my $x2 = '' ;
my $x3 = '' ;
my $x4 = '' ;
produces a "use of uninitialized variable" error? I find that hard to
believe.
hp
--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Bill Code on asrg@irtf.org
------------------------------
Date: Wed, 25 Jul 2012 10:17:56 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <87394gyzaz.fsf@sapphire.mobileactivedefense.com>
r.mariotti@fdcx.net writes:
[...]
> The snippet of code I included in my post was an attempt to come up
> with a process that would initialize these fields if they were not
> aleady defined. That's why I used the unless defined clause.
>
> My understanding of this function was that it was the perl equivalent
> of the php isset function. However, even when I remove the unless
> portion of the statements I still receive the same use of
> uninitialized variable blah blah.
Except that the error produced by your example code was something
different, namely,
Global symbol "$fn" requires explicit package name at a.pl line 5
and so on, for all variables used in it. And this error (not warning)
was caused by the fact that the unless defined(...) sub-statements
were outside of the scope of the my declarations and thus, accessed
undeclared package globals with full qualification.
The 'uninitialized value' (not variable) warning is very likely
produced when an automatic conversion of a so-called 'undefined value'
to either 0 or '' is done at runtime, except in some pretty random
looking subset of situations where this happens to be done. The best
way to deal with that, especially in known-to-be-working code, is
no warnings 'uinitialized';
which disables this warning. Alternatively, you can track down these
uses based on the warning output and include the necessary bogus
initializations to satisfy the coding pharisees ('Korinthenkacker'
would be more apropriate here but I don't know how to translate that
:-).
------------------------------
Date: Wed, 25 Jul 2012 13:42:46 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <877gts3tbt.fsf@sapphire.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
>> Ben Morrow <ben@morrow.me.uk> writes:
>> > Quoth Justin C <justin.1207@purestblue.com>:
>>
>> >> (though it's definitely preferred to declare them
>> >> only within the scope of where they're used)
>> >
>> > Yes. In general, don't create a variable until you have something useful
>> > to put in it. (This isn't always possible.)
>>
>> In general, don't declare variables in a lexical scope unless it
>> happens to be the outmost lexical scope of a subroutine. As soon as
>> this starts to become unwieldly, structure the code into a set of
>> subroutines and a controlling superroutine.
>
> Are you just contradicting me to be contrary, or do you have a point?
The point is that some odd 2x years of experience with it have taught
me that 'functional decomposition' is a good idea. This is also nicely
exposed by the fact that you didn't even try to argue against that but
went straight to the messenger (with a completely nonsensical
supposition -- maybe your wife/ girl friend/ current or perpetual sex
partner of choice argues with you for the sake of outacting
interelational stress, I certainly won't. I don't know you).
------------------------------
Date: Wed, 25 Jul 2012 13:53:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Pls help old perl-monger with new version syntax?
Message-Id: <qq65e9-9o6.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
> > Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> >> Ben Morrow <ben@morrow.me.uk> writes:
> >> > Quoth Justin C <justin.1207@purestblue.com>:
> >>
> >> >> (though it's definitely preferred to declare them
> >> >> only within the scope of where they're used)
> >> >
> >> > Yes. In general, don't create a variable until you have something useful
> >> > to put in it. (This isn't always possible.)
> >>
> >> In general, don't declare variables in a lexical scope unless it
> >> happens to be the outmost lexical scope of a subroutine. As soon as
> >> this starts to become unwieldly, structure the code into a set of
> >> subroutines and a controlling superroutine.
> >
> > Are you just contradicting me to be contrary, or do you have a point?
>
> The point is that some odd 2x years of experience with it have taught
> me that 'functional decomposition' is a good idea.
I agree entirely. This has nothing to do with whether you declare the
variables in a particular function in a group at the top, or as you need
them.
Ben
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3743
***************************************