[32188] in Perl-Users-Digest
Perl-Users Digest, Issue: 3453 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 25 06:09:24 2011
Date: Mon, 25 Jul 2011 03:09:07 -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 Mon, 25 Jul 2011 Volume: 11 Number: 3453
Today's topics:
Script to align columns in a text table. <RedGrittyBrick@SpamWeary.invalid>
Re: Script to align columns in a text table. <rweikusat@mssgmbh.com>
Re: stuck in regex <tadmc@seesig.invalid>
Re: stuck in regex sln@netherlands.com
Re: stuck in regex <elliot@example.net>
Re: stuck in regex <elliot@example.net>
Re: syntax query: ($var++ && next) if /match/ <rvtol+usenet@xs4all.nl>
Re: syntax query: ($var++ && next) if /match/ <rweikusat@mssgmbh.com>
Re: syntax query: ($var++ && next) if /match/ <rweikusat@mssgmbh.com>
Re: syntax query: ($var++ && next) if /match/ <derykus@gmail.com>
Re: syntax query: ($var++ && next) if /match/ <rweikusat@mssgmbh.com>
why won't perl say which value was uninitialized? jidanni@jidanni.org
Re: why won't perl say which value was uninitialized? <derykus@gmail.com>
Re: why won't perl say which value was uninitialized? <rweikusat@mssgmbh.com>
Re: why won't perl say which value was uninitialized? <uri@StemSystems.com>
Re: why won't perl say which value was uninitialized? <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 24 Jul 2011 13:23:52 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.invalid>
Subject: Script to align columns in a text table.
Message-Id: <LpKdnZJVmux6k7HTnZ2dnUVZ7sqdnZ2d@bt.com>
I use a plain-text mark-up system to produce HTML and PDF documents from
plain text files which I edit using a text editor.
(see http://superuser.com/questions/209897/text-formatter-tools/)
When you edit a table in the midst of a file, it is tedious to insert or
delete numerous spaces to get the columns to line up. I needed to filter
chunks of text through a tool a little better suited to this than Unix's
`column` utility - so I wrote the following Perl script.
I have the feeling that a more elegant and concise (but still readable)
solution should be possible. Maybe someone can suggest improvements, a
better algorithm, etc.?
-----------------------------8<--------------------------------------
#!/usr/bin/perl
#
# Align columns in a text table. RGB 2011
#
use strict;
use warnings;
my @table;
while (my $line=<DATA>) {
if ($line =~ /^[+|]/) {
push @table, $line;
} else {
if (@table) { pretty_print(@table); @table = (); }
print $line;
}
}
sub pretty_print {
my @widths;
my @rows_of_columns;
#
# Calculate max widths of content in each column
#
for (@_) {
if (/^\|/) {
s/^\|(.*)\|\s*$/$1/; # Remove outer "|" characters
my @columns = split( /\s*\|\s*/, $_, -1);
for my $i (0..$#columns) {
if (($i > $#widths) or (length($columns[$i]) > $widths[$i])) {
$widths[$i] = length($columns[$i]);
}
}
push @rows_of_columns, [ @columns ];
} else {
push @rows_of_columns, [ $_ ];
}
}
#
# Construct table row divider
#
my $divider;
for my $w (@widths) { $divider .= '+' . '-'x$w; }
$divider .= "+\n";
#
# Pad table column data to required widths
#
for my $line (@rows_of_columns) {
my @columns = @$line;
if ($columns[0] =~ /^\+/) {
print $divider;
} else {
for my $i (0..$#columns) {
print "|", $columns[$i], ' 'x($widths[$i]-length($columns[$i]));
}
print "|\n";
}
}
} # sub pretty_print
__DATA__
Title
+---+---+---+
|Fruit|Price|No.|
+---+---+---+
|Apples|3.63|100|
+---+---+---+
|Sweet|17|5.000|
|Potatoes| | |
+---+---+---+
Caption
-----------------------------8<--------------------------------------
Output:
Title
+--------+-----+-----+
|Fruit |Price|No. |
+--------+-----+-----+
|Apples |3.63 |100 |
+--------+-----+-----+
|Sweet |17 |5.000|
|Potatoes| | |
+--------+-----+-----+
Caption
--
RGB
------------------------------
Date: Sun, 24 Jul 2011 18:55:15 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Script to align columns in a text table.
Message-Id: <874o2b36nw.fsf@sapphire.mobileactivedefense.com>
RedGrittyBrick <RedGrittyBrick@SpamWeary.invalid> writes:
> I use a plain-text mark-up system to produce HTML and PDF documents
> from plain text files which I edit using a text editor.
> (see http://superuser.com/questions/209897/text-formatter-tools/)
>
> When you edit a table in the midst of a file, it is tedious to insert
> or delete numerous spaces to get the columns to line up. I needed to
> filter chunks of text through a tool a little better suited to this
> than Unix's `column` utility - so I wrote the following Perl script.
>
> I have the feeling that a more elegant and concise (but still
> readable) solution should be possible. Maybe someone can suggest
> improvements, a better algorithm, etc.?
Below is your script with a couple of modifications I consider to be
sensible:
-----------------------------
#!/usr/bin/perl
#
# Align columns in a text table. RGB 2011
#
use strict;
use warnings;
# repeat 100 times: "'Perl' ne 'C'", dammit ...
no warnings 'uninitialized';
use constant DIV => [];
my @table;
while (my $line=<DATA>) {
if ($line =~ /^[+|]/) {
push @table, $line;
} else {
if (@table) { pretty_print(@table); @table = (); }
print $line;
}
}
sub pretty_print {
my @widths;
my @rows_of_columns;
#
# Calculate max widths of content in each column
#
for (@_) {
if (/^\|/) {
s/^\|(.*)\|\s*$/$1/; # Remove outer "|" characters
my @columns = split( /\s*\|\s*/, $_, -1);
length($columns[$_]) > $widths[$_] and $widths[$_] = length($columns[$_])
for (0..$#columns);
push @rows_of_columns, [ @columns ];
} else {
push @rows_of_columns, DIV;
}
}
#
# Construct table row divider and format string
#
my ($divider, $fmt);
for my $w (@widths) {
$divider .= '+' . '-'x$w;
$fmt .= "|%-${w}s"; # don't reinvent the square wheel
}
$divider .= "+\n";
$fmt .= "|\n";
#
# print the table
#
for my $line (@rows_of_columns) {
printf($fmt, @$line), next if @$line;
print($divider);
}
} # sub pretty_print
__DATA__
Title
+---+---+---+
|Fruit|Price|No.|
+---+---+---+
|Apples|3.63|100|
+---+---+---+
|Sweet|17|5.000|
|Potatoes| | |
+---+---+---+
Caption
------------------------------
Date: Sun, 24 Jul 2011 08:27:00 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: stuck in regex
Message-Id: <slrnj2o6v7.i32.tadmc@tadbox.sbcglobal.net>
elliot <elliot@example.net> wrote:
> The script that I would think were more elegant and useful would be one
> that would remove an integer if it is the first word in a line, as well
> as whitespace thereafter.
perl -pe 's/^\s*\d+\s+//' cfile.c
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Sun, 24 Jul 2011 11:13:42 -0700
From: sln@netherlands.com
Subject: Re: stuck in regex
Message-Id: <n8mo27p9c174tb683qiu3fapn9klrje93k@4ax.com>
On Sun, 24 Jul 2011 00:11:39 -0600, elliot <elliot@example.net> wrote:
>On 07/23/2011 08:36 PM, Jürgen Exner wrote:
>
>> How so? In e.g.
>> 3.1415E01
>> _I_ see just three natural numbers, separated by a '.' and an 'E'. ;-)
>>
>> However, I did forget about the optional signum in integers, so the OP
>> may want to add that to the RE.
>>
>> jue
>
>Even facetious replies helped me figure this out. It took me a while to
>figure out why the 2 was disappearing in the ultimate line, but I think
>I got it. It compiles:
>
>elliot@dan:/media/KINGSTON$ perl input2.pl
>elliot@dan:/media/KINGSTON$ cat cfile2.c
>#include <stdio.h>
>#include <malloc.h>
>void testc(double **pa)
>{
>double b;
>double *a;
>int m;
>a = (double*) malloc(sizeof(double)*5);
>a[0]=1.23;
>a[1]=2.46;
>a[2]=3.69;
>a[3]=4.11;
>a[4]=7.21;
>*pa=a;
>for (m=0;m<5;m++)
>{
>b=a[m];
>b=b+1.0;
>a[m]=b;
>}
>}
>//gcc -c -Wall -Wextra cfile2.c -o testc.o tja
>elliot@dan:/media/KINGSTON$ gcc -c -Wall -Wextra cfile2.c -o testc.o
>elliot@dan:/media/KINGSTON$ ls -l testc.o
>-rw-r--r-- 1 elliot elliot 1048 2011-07-23 23:55 testc.o
>elliot@dan:/media/KINGSTON$ cat input2.pl
>#!/usr/bin/perl -w
>use strict;
>my $filename = "cfile.c";
>open FILE, $filename or die $!;
>open FILE2, ">cfile2.c" or die $!;
>while (<FILE>) {
> #s/(?<![.\d])\d+(?![.\d])//g;
> s/\d+// unless m%/%;
> s/\s+//;
> print FILE2;
>}
>elliot@dan:/media/KINGSTON$
>
>The script that I would think were more elegant and useful would be one
>that would remove an integer if it is the first word in a line, as well
>as whitespace thereafter.
That script produces this output:
#include<stdio.h>
#include<malloc.h>
voidtestc(double **pa)
{doubleb;
double*a;
intm;
a= (double*) malloc(sizeof(double)*);
a[]=1.23;a[]=2.46;a[]=3.69;a[]=4.11;a[]=7.21;*pa=a;for(m=;m<5;m++)
{b=a[m];b=b+.0;a[m]=b;}}
Doesen't make a lot of sence.
-sln
------------------------------
Date: Sun, 24 Jul 2011 20:56:27 -0600
From: elliot <elliot@example.net>
Subject: Re: stuck in regex
Message-Id: <9944asFeqmU1@mid.individual.net>
On 07/24/2011 07:27 AM, Tad McClellan wrote:
> elliot<elliot@example.net> wrote:
>
>> The script that I would think were more elegant and useful would be one
>> that would remove an integer if it is the first word in a line, as well
>> as whitespace thereafter.
>
>
> perl -pe 's/^\s*\d+\s+//' cfile.c
>
>
Nice:
$ perl -pe 's/^\s*\d+\s+//' cfile3.c
#include <stdio.h>
#include <malloc.h>
void testc(double **pa)
{
double b;
double *a;
int m;
a = (double*) malloc(sizeof(double)*5);
a[0]=1.23;
a[1]=2.46;
a[2]=3.69;
a[3]=4.11;
a[4]=7.21;
*pa=a;
for (m=0;m<5;m++)
{
b=a[m];
b=b+1.0;
a[m]=b;
}
}
# perl -pe 's/^\s*\d+\s+//' cfile3.c
// gcc -c -Wall -Wextra cfile2.c -o testc.o
$
Sometimes simple and elegant are the same things.
--
elliot
------------------------------
Date: Sun, 24 Jul 2011 21:00:45 -0600
From: elliot <elliot@example.net>
Subject: Re: stuck in regex
Message-Id: <9944itFeqmU2@mid.individual.net>
On 07/24/2011 12:13 PM, sln@netherlands.com wrote:
> That script produces this output:
>
> #include<stdio.h>
> #include<malloc.h>
> voidtestc(double **pa)
> {doubleb;
> double*a;
> intm;
> a= (double*) malloc(sizeof(double)*);
> a[]=1.23;a[]=2.46;a[]=3.69;a[]=4.11;a[]=7.21;*pa=a;for(m=;m<5;m++)
> {b=a[m];b=b+.0;a[m]=b;}}
>
>
> Doesen't make a lot of sence.
What input files were you using?
$ cat cfile3.c
1 #include <stdio.h>
2 #include <malloc.h>
3
4 void testc(double **pa)
5 {
6 double b;
7 double *a;
8 int m;
9
10 a = (double*) malloc(sizeof(double)*5);
11 a[0]=1.23;
12 a[1]=2.46;
13 a[2]=3.69;
14 a[3]=4.11;
15 a[4]=7.21;
16 *pa=a;
17 for (m=0;m<5;m++)
18 {
19 b=a[m];
20 b=b+1.0;
21 a[m]=b;
22 }
23 }
// gcc -c -Wall -Wextra cfile2.c -o testc.o
Something like this?
--
elliot
------------------------------
Date: Sun, 24 Jul 2011 12:31:41 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <4e2bf48d$0$23945$e4fe514c@news2.news.xs4all.nl>
On 2011-07-23 01:15, C.DeRykus wrote:
> I've used 'and' chains
> to sneak in a side effect :
>
> /^paul/ and $seen=1 and next;
Who's still afraid of the comma operator?
$seen = 1, next if /^paul/;
(non-summary: I am just repeating what someone else already wrote, it
was already suggested before, if you go back in the thread you'll find
it, and if not then look again)
--
Ruud
Nice block clash:
perl -MO=Deparse -e'do { $seen = 1, next } if /^paul/;'
if (/^paul/) {
$seen = 1, next;
}
------------------------------
Date: Sun, 24 Jul 2011 13:39:54 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <87ipqrrgx1.fsf@sapphire.mobileactivedefense.com>
blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> writes:
> In article <87sjpy9wte.fsf@sapphire.mobileactivedefense.com>,
> Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
[...]
>> A text doesn't become easier to understand by adding more
>> non-alphanumeric characters to it.
>
> Presumably you mean "program text" here (since if you could also mean
> natural language text I would respectfully disagree and I suspect you
> would too since as this sentence is meant to demonstrate punctuation
> can be very helpful in making sense of long sentences and indeed in
> separating sentences not to mention that without nonalphanumerics
> you couldnt spell contractions right).
,,!`!I%%^^^actu;;;;!ly```````mea::@:@n#~~tt\||||||ext$$
[...]
> The case is perhaps less clear for program text, but I would argue
> that judicious use of parentheses, even when not needed, is an
> aid to understanding. Then again, I'm probably biased by the fact
> that I'd rather put in some unnecessary parentheses from time to
> time than try to keep in my head a table of operator precedences.
> For example, I would rather just write
>
> (a && b) || (c && d)
That's not a suitable example because the parentheses in the original
code were not used to clarify the precedence within a complex
expression but to separate a statement/expression [$seen = 1 and next]
from a statement modifier.
[...]
>> Why this, since it does exactly what its literal meaning appears to
>> be:
>>
>> $seen = 1 and next if /^paul/
>
> I would say that this line of code has an unambiguous literal
> meaning only to someone who knows the relative precedence of all
> the operators.
To someone who is aware of the concept of 'operators with different
precedence' but who doesn't really now what the precedence happens to
be *and* who isn't willing to look it up in the manual, no code
sequence has an unambigious meaning. But - imagine that - people
actually use language for everyday communication and manage to make
this work.
> And (as someone else pointed out) what if the
> assignment was "$seen = 0"?
The assignment isn't $seen = 0. Making uninformed changes to working
code (such as turning $seen = 1 and next into $seen = 0 and next) may
(and likely will) result in code which doesn't work anymore.
[...]
>> (set $seen to 1 and execute next if $_ matches /^paul/)
>
> But isn't that sentence also potentially ambiguous?
'Potentially ambiguous' is a combination of terms which makes no
sense (everything is 'potentially ambiguous'). Generally, sentences
don't have an unambiguous meaning outside of the (con)text they were
meant to be part of and this is still the statement + statement
modifier situation.
------------------------------
Date: Sun, 24 Jul 2011 18:06:29 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <87fwlv38x6.fsf@sapphire.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mssgmbh.com> writes:
> blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> writes:
[...]
>> And (as someone else pointed out) what if the
>> assignment was "$seen = 0"?
>
> The assignment isn't $seen = 0.
Additional clarfication: My opinion on this is that using the and
logical operator as sequence binder in a context where this happens to
be possible because the first of the to-be-sequenced expressions
happens to evaluate to a true value is a rather unfortunate idea and
that the proper operator for this purpose should be used instead which
would be , in one of the two posted variants, namely
$seen = 1, next if /^paul/;
or
/^paul/ and $seen = 1, next;
But that's an entirely a matter of what I consider to be a sensible
coding style and does not imply that something is technically wrong
with the originally posted code (except the operator precedence
problem, of course).
------------------------------
Date: Sun, 24 Jul 2011 14:53:40 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <c8077023-00ac-456d-8e89-683f23e0c840@t38g2000prj.googlegroups.com>
On Jul 24, 3:31=A0am, "Dr.Ruud" <rvtol+use...@xs4all.nl> wrote:
> On 2011-07-23 01:15, C.DeRykus wrote:
>
> > I've used 'and' chains
> > to sneak in a side effect :
>
> > =A0 =A0 =A0/^paul/ and $seen=3D1 and next;
>
> Who's still afraid of the comma operator?
>
> =A0 =A0 =A0$seen =3D 1, next if /^paul/;
The rarity of the comma operator makes it just
a bit harder to spot IMO. And, in this case,
I think a {} or do{} is "easier on the eyes and
arguably the brain" which trumps the brevity of
the comma operator.
--
Charles DeRykus
------------------------------
Date: Mon, 25 Jul 2011 10:24:11 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: syntax query: ($var++ && next) if /match/
Message-Id: <87r55eyapw.fsf@sapphire.mobileactivedefense.com>
Jürgen Exner <jurgenex@hotmail.com> writes:
> Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>>Jürgen Exner <jurgenex@hotmail.com> writes:
>>> Justin C <justin.1104@purestblue.com> wrote:
>>>>My intention is to set a variable $seen to 1 (true) (for use later), to
>>>>stop processing the current item and move on to the next if $_ matches
>>>>certain criteria.
>>>
>>> What's wrong with an old-fashioned
>>> if ($_ matches certain criteria) {
>>> $seen = 1;
>>> next;
>>> }
>>
>>The signal-to-noise ratio of this encoding of this particular operation
>>is worse than that of the equivalent statement-modifier or logical
>>operating using variants. Additionally, it is less efficient although
>>this could be regarded as a deficiency of the perl compiler. The only
>>'positive' thing about it is that it looks more familiar to people who
>>are versed in 'other curly-bracket languages'.
>
> I disagree. This isn't one operation, it is two and they are quite
> different. One assignment and one loop control jump.
Nobody ever claimed that they weren't.
> And therefore it should look and feel like two operations, i.e. be
> separated into two statements.
Perl has four operators which can be used to bind two different but
(in a certain context) related things together, '&& || and or
,'. Interpreted as general as it stand there, the sentence could as
easily apply to
if ($a == 1 && $b ne 'Huehnerdieb') { }
two different comparisons which are executed in sequence and thus,
should be two statements instead of this confusing conglomerate:
if ($a == 1) {
if ($b ne 'Huehnerdieb') { }
}
Consequently, this statement should be less general so that it is
applicable to assignment and loop-control operators but not to chained
comparisons.
> You can easily see how confusing it is to munge them together: in just
> this very thread there are already at least three different
> interpretions of what the OP intended the code to do.
I'm not aware of any, but the OP stated quite plainly what he wanted
to do (as paraphrase: Why does it work with , but not with &&?) and
if at least three people existed who didn't understand a particular
text, presumably, because they jumped to conclusions about its
probable meaning before they finished reading it, that's not an argument
for or against anything: Whatever is said, someone will not listen and
misunderstand it.
> It is just not worth this confusion. Consice code that is easy to
> understand is way more important than shorting the code to the max.
> Unless you are playing Perl golf, of course.
Nobody argued in favor of 'shorting code to the max' (a remarkably
nonsensical phrase .... shouldn't that be 'shorten it to the min'?).
> Also, I am not convinced about your efficieny argument.
First and foremost, this was a statement of facts: The if-block makes
perl perform more operations than the 'block-free' variants. A
contrived example which demonstrates this (both at the 'op tree' level
and in terms of actual execution time, at least here):
-----------
use Benchmark;
my $x;
sub s1
{
if (rand(100) < 50) {
++$x;
return $x;
}
}
sub s2
{
++$x, return $x if rand(100) < 50;
}
timethese(-5, {
a => \&s1,
b => \&s2
});
-----------
> For one nobody asked for the code to be as efficient as possible.
That's a different question.
> And even if so I would still find it hard to believe that an if
> statement is slower, because in both cases the same operations are
> performed. Or actually in case of the statement modifier there is
> even an additional and.
Well, you are wrong about that and I actually posted output of the
'Perl disassembler' that showed the difference. You can also get it
from the code above by using it as argument to
perl -MO=Concise,-exec,s1
perl -MO=Concise,-exec,s2
(first shows the first sub, 2nd the 2nd).
> Not to mention that such micro-optimizations are rarely the right
> approach. If a program is too slow then almost always a different
> algorithm or a different overall approach is the answer.
Provided that a program is too slow, 'removing avoidable blocks' might
not be the best strategy in order to deal with that (although this is
by no means certain since 'wasting 1.5% at every opportunity for that'
can easily have a significant cumulative effect). But this is - at
best - a tangential aspect when technical properties of different ways
to do the same thing are discussed.
> If you are really depending upon such micro-optimizations then
> probably you should have chosen a different programming language,
> probably one that allows lower-level control like C or assembler.
I really expect that people who write code are as concerned with using
their tools efficiently as people performing different tasks with
other tools, IOW, that the 'dominant programming problem' shouldn't be
"how to I get this to work at all" but "how can I make this work
sensibly".
This is, of course, not exactly a realistic proposition ...
------------------------------
Date: Mon, 25 Jul 2011 08:47:09 +0800
From: jidanni@jidanni.org
Subject: why won't perl say which value was uninitialized?
Message-Id: <j0ieho$mj6$1@news.datemas.de>
I don't see why messages like
Use of uninitialized value in print at bla.pl line 44
can't say which value was it that was uninitialized.
Is it really that much skin off perl's back?
Why must it hold its cards so close to its chest?
It knows exactly which of the say 50 variables had the problem, why doesn't
it cough up the details and not force the user to use the debugger?
Big CPU cost? I bet not.
------------------------------
Date: Sun, 24 Jul 2011 22:09:44 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: why won't perl say which value was uninitialized?
Message-Id: <0620fb2d-a878-45ac-a811-60bdba68822e@u6g2000prc.googlegroups.com>
On Jul 24, 5:47=A0pm, jida...@jidanni.org wrote:
> I don't see why messages like
> =A0 Use of uninitialized value in print at bla.pl line 44
> can't say which value was it that was uninitialized.
> Is it really that much skin off perl's back?
> Why must it hold its cards so close to its chest?
> It knows exactly which of the say 50 variables had the problem, why doesn=
't
> it cough up the details and not force the user to use the debugger?
> Big CPU cost? I bet not.
Actually Perl tries, especially if you're using
a reasonably current version of Perl:
perl -v
This is perl 5, version 12, subversion 2 (v5.12.2)
built for MSWin32-x86-multi-thread
perl -we "my($x,$y);print $x,$y"
Use of uninitialized value $x in print at -e line 1.
Use of uninitialized value $y in print at -e line 1.
perl -w
my (%foo,%bar);
$foo{'one'}=3D1;
my $x =3D "$bar{'one'} $foo{'one'}"
^D
Use of uninitialized value $bar{"one"} in
concatenation (.) or string at - line 3.
But, sometimes Perl may have optimized the
expression and the determination can't be
made. Look at the slight difference between
the previous code and the one below:
perl -w
my(%foo, %bar);
$bar{'one'}=3D1;
my $x =3D "$bar{'one'} $foo{'one'}";
^D
Use of uninitialized value in concatenation (.)
or string at - line 3.
--
Charles DeRykus
------------------------------
Date: Mon, 25 Jul 2011 09:18:07 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: why won't perl say which value was uninitialized?
Message-Id: <877h76zscg.fsf@sapphire.mobileactivedefense.com>
jidanni@jidanni.org writes:
> I don't see why messages like
> Use of uninitialized value in print at bla.pl line 44
> can't say which value was it that was uninitialized.
There is no such thing as 'an uinitialized value' for the simple
reason that the term itself makes no sense: values aren't modified,
variables are. In this case, the message means 'something whose value
happened to be undef was used in a context where someone - for
entirely unintelligible reasons - believed that this shouldn't have
happen'.
----------
use warnings;
my ($a, $b, $c);
$b = $a + 1; # warning
$c = ++$a; # no warning
print("$a, $b, $c\n");
---------
> Is it really that much skin off perl's back?
Are you really surprised that code which makes no sense does so
consistently?
------------------------------
Date: Mon, 25 Jul 2011 04:30:48 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: why won't perl say which value was uninitialized?
Message-Id: <874o2aahjb.fsf@quad.sysarch.com>
>>>>> "RW" == Rainer Weikusat <rweikusat@mssgmbh.com> writes:
RW> jidanni@jidanni.org writes:
>> I don't see why messages like
>> Use of uninitialized value in print at bla.pl line 44
>> can't say which value was it that was uninitialized.
RW> There is no such thing as 'an uinitialized value' for the simple
RW> reason that the term itself makes no sense: values aren't modified,
RW> variables are. In this case, the message means 'something whose value
RW> happened to be undef was used in a context where someone - for
RW> entirely unintelligible reasons - believed that this shouldn't have
RW> happen'.
RW> Are you really surprised that code which makes no sense does so
RW> consistently?
again, you don't get things. is a hash or array element a value or a
variable? actually it is a container as is a scalar. you could say the
container is uninitialized but that usage isn't common enough so saying
the value is uninitialized is fine. newer perls will name an
uninitialized scalar variable.
uri
--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------
------------------------------
Date: Mon, 25 Jul 2011 10:20:05 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: why won't perl say which value was uninitialized?
Message-Id: <87tyaayawq.fsf@sapphire.mobileactivedefense.com>
"Uri Guttman" <uri@StemSystems.com> writes:
>>>>>> "RW" == Rainer Weikusat <rweikusat@mssgmbh.com> writes:
>
> RW> jidanni@jidanni.org writes:
> >> I don't see why messages like
> >> Use of uninitialized value in print at bla.pl line 44
> >> can't say which value was it that was uninitialized.
>
> RW> There is no such thing as 'an uinitialized value' for the simple
> RW> reason that the term itself makes no sense: values aren't modified,
> RW> variables are. In this case, the message means 'something whose value
> RW> happened to be undef was used in a context where someone - for
> RW> entirely unintelligible reasons - believed that this shouldn't have
> RW> happen'.
> RW> Are you really surprised that code which makes no sense does so
> RW> consistently?
>
> again, you don't get things.
Given that I gave a correct explanation of the intended meaning of the
meaningless statement, that's not a sensible conclusion.
> is a hash or array element a value or a variable?
> actually it is a container as is a scalar. you could say the
> container is uninitialized
Or, as would be factually accurate: The variable is uninitialized
since the value itself can't be initialized (2 is a value).
------------------------------
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 3453
***************************************