[31824] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3087 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 20 06:09:27 2010

Date: Fri, 20 Aug 2010 03:09:10 -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           Fri, 20 Aug 2010     Volume: 11 Number: 3087

Today's topics:
    Re: [ANN]VTD-XML 2.9 <tadmc@seesig.invalid>
    Re: ActivePerl Migration Win 2003 Server to Win 2008 Se <veatchla@yahoo.com>
    Re: FAQ 3.4 How do I find which modules are installed o <justin.1007@purestblue.com>
        Multiple regex operations <zacharyelliott1@gmail.com>
    Re: Multiple regex operations <jurgenex@hotmail.com>
    Re: Multiple regex operations <justin.1007@purestblue.com>
    Re: Multiple regex operations <rvtol+usenet@xs4all.nl>
    Re: parsing CSV files <monkey@joemoney.net>
    Re: parsing CSV files <xhoster@gmail.com>
    Re: parsing CSV files <tadmc@seesig.invalid>
    Re: Perl array bug? <xhoster@gmail.com>
    Re: Perl array bug? <xhoster@gmail.com>
    Re: Perl array bug? (Malcolm Hoar)
    Re: Perl array bug? <xhoster@gmail.com>
    Re: Perl array bug? (Malcolm Hoar)
    Re: Perl array bug? (Malcolm Hoar)
    Re: Perl array bug? (Malcolm Hoar)
    Re: Perl array bug? <jurgenex@hotmail.com>
    Re: Perl array bug? (Malcolm Hoar)
    Re: Perl array bug? <NoSpamPleaseButThisIsValid3@gmx.net>
    Re: Perl array bug? <hjp-usenet2@hjp.at>
    Re: Perl array bug? (Malcolm Hoar)
    Re: Perl array bug? <ben@morrow.me.uk>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@seesig.invalid
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 19 Aug 2010 22:55:11 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: [ANN]VTD-XML 2.9
Message-Id: <slrni6rut9.4le.tadmc@tadbox.sbcglobal.net>

dontcare <bchang2002@gmail.com> wrote:

> the next generation 


blah blah blah.

How is it related to the Perl programming language?


-- 
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: Thu, 19 Aug 2010 22:04:19 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: ActivePerl Migration Win 2003 Server to Win 2008 Server
Message-Id: <i4krbk$fe0$1@news.eternal-september.org>

On 8/19/2010 6:01 AM, Klaus wrote:
> Hello,
>
> I hope this post is not OT in c.l.p.m.
>
> I have got a couple of medium-sized (1000+ lines of code) of Perl
> programs (64 bits) running on Windows Server 2003, the perl version
> is:
>
> C:\>perl -v
> This is perl, v5.10.1 built for MSWin32-x64-multi-thread
> (with 2 registered patches, see perl -V for more detail)
> Binary build 1007 [291969] provided by ActiveState http://www.ActiveState.com
> Built Jan 27 2010 14:12:21
>
> I am using ADODB to connect to MSAccess databases, I read
> ActiveDirectory entries and I use StorageCentral to setup Storage
> quotas for 1000+ directories.
>
> Now I have to migrate Windows Server from 2003 to 2008.
>
> Before I embark on this adventure, I would ask for the wisdom of the
> perl user community:
>
> - Does anybody have experience with migrating perl programs from
> Windows Server 2003 to 2008 ?
>
> - Are there any pitfalls I need to be aware of ?
>
> - Do you recommend upgrading from perl 5.10 (x64) to the newer perl
> 5.12 (x64) at the same time ?

I would keep the Perl version the same during the server migration / 
upgrade so as not to complicate the migration.

I'm sure I'll catch some flak over this.  I the past on older Windows 
OSes, I would install Perl in the same drive and directory location on 
the 2008 box as it was installed on the 2003 box.  Then copy the 2003 
Perl installation to the 2008 box.  I never uncounted any problems with 
this procedure.

-- 
Len



------------------------------

Date: Fri, 20 Aug 2010 09:38:48 +0100
From: Justin C <justin.1007@purestblue.com>
Subject: Re: FAQ 3.4 How do I find which modules are installed on my system?
Message-Id: <ohr1k7-ema.ln1@zem.masonsmusic.co.uk>

On 2010-08-19, Owen <xemoth@gmail.com> wrote:
>> 3.4: How do I find which modules are installed on my system?
>>
>>     From the command line, you can use the "cpan" command's "-l" switch:
>>
>>             $ cpan -l
>
>
>
> Well just tried this and "it didn't work".

What version is your cpan? 
    cpan -v

   Justin.

-- 
Justin C, by the sea.


------------------------------

Date: Thu, 19 Aug 2010 21:40:34 -0700 (PDT)
From: =?ISO-8859-1?Q?Orion_M=EDmamei=F0r?= <zacharyelliott1@gmail.com>
Subject: Multiple regex operations
Message-Id: <58d85860-3b4e-4609-86fd-21a455f904d1@x42g2000yqx.googlegroups.com>

Is there a way to apple multiple regex operations to a single string
without writing them all out?

example.

suppose I have some variable $var and want it apple three regexs to
it. is there a faster way than

$var =~ s/foo/bar/;
$var =~ s/foo/bar/;
$var =~ s/foo/bar/;



------------------------------

Date: Thu, 19 Aug 2010 21:53:05 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Multiple regex operations
Message-Id: <k82s66l32601tpq5ngi2hqvek7dm507e2o@4ax.com>

Orion Mímameiğr <zacharyelliott1@gmail.com> wrote:
>Is there a way to apple multiple regex operations to a single string
>without writing them all out?

Regular expressions are expessions, not operations.

>example.
>
>suppose I have some variable $var and want it apple three regexs to
>it. is there a faster way than

You don't "apply" a regular expression. Well, unless you are talking
about matches/doesn't match. 

>$var =~ s/foo/bar/;
>$var =~ s/foo/bar/;
>$var =~ s/foo/bar/;

If it has to be exactly three times you can do a simple loop:

	for my $x (1..3) {
		$var =~ s/foo/bar/;
	}

If you want to do it for all 'foo' in a string then use the g modifier:
	$var =~ s/foo/bar/g;

jue


------------------------------

Date: Fri, 20 Aug 2010 09:50:30 +0100
From: Justin C <justin.1007@purestblue.com>
Subject: Re: Multiple regex operations
Message-Id: <m7s1k7-ema.ln1@zem.masonsmusic.co.uk>

On 2010-08-20, Orion Mímameiğr <zacharyelliott1@gmail.com> wrote:
> Is there a way to apple multiple regex operations to a single string
> without writing them all out?
>
> example.
>
> suppose I have some variable $var and want it apple three regexs to
> it. is there a faster way than
>
> $var =~ s/foo/bar/;
> $var =~ s/foo/bar/;
> $var =~ s/foo/bar/;

my $var = "To make foo you will need orange and whisky.\n";

my @old = qw/foo orange whisky/;
my @new = qw/bar lemon gin/;

print $var;
foreach my $old (@old) {
   my $new = shift (@new);
   $var =~ s/$old/$new/;
}
print $var;

Though this only becomes less to type when you have more @old and @new.

TMTOWTDI.

   Justin.

-- 
Justin C, by the sea.


------------------------------

Date: Fri, 20 Aug 2010 11:35:16 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Multiple regex operations
Message-Id: <4c6e4c54$0$22944$e4fe514c@news.xs4all.nl>

Orion Mímameiğr wrote:
> Is there a way to apple multiple regex operations to a single string
> without writing them all out?
> 
> example.
> 
> suppose I have some variable $var and want it apple three regexs to
> it. is there a faster way than
> 
> $var =~ s/foo/bar/;
> $var =~ s/foo/bar/;
> $var =~ s/foo/bar/;

perl -Mstrict -wle '
   { my $qr= 2;
     my @qr= ( qr/\s+\z/, qr/\A\s+/, qr/\s+/ );
     sub qr {
       $qr= ( $qr + 1 ) % 3;
       if ( $qr == 2 ) { s/$qr[$qr]/ /g } else { s/$qr[$qr]// }
     }
   }

   my $s = " abc \t def  \n  ghi   ";

   for ( "apple" .. "apply" ) {
     &qr for $s;
   }
   print "<$s>";
'
<abc def ghi>


-- 
Ruud


------------------------------

Date: Thu, 19 Aug 2010 22:28:07 -0400
From: monkeys paw <monkey@joemoney.net>
Subject: Re: parsing CSV files
Message-Id: <zdudnXwKYfGkdfDRnZ2dnUVZ_tmjnZ2d@insightbb.com>

On 8/19/2010 8:01 PM, Ben Morrow wrote:
>
> Quoth monkeys paw<monkey@joemoney.net>:
>> FILE contains:
>> US,S,2009,Alexander L,R,"AGRICULTURE, NUTRITION AND FORESTRY."
>> US,S,2009,Alexander L,R,ARMED SERVICES.
>>
>> If i parse the above lines with a split /,/  i will
>> correctly get field[5] = "ARMED SERVICES" on line 2,
>> but incorrectly field[5] = "AGRICULTURE," on line 1.
>>
>> while  ($line =<IN>) {
>>       @field = split /,/, $line;
>>       print "$field[5]\n";
>> }
>>
>> Is there a way to modify the split to handle this file format?
>
> No. Don't use split for parsing CSV. Use a module that parses CSV. I
> would recommend Text::CSV_XS.
>
> Ben
>

OK, thanks


------------------------------

Date: Thu, 19 Aug 2010 19:36:09 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: parsing CSV files
Message-Id: <4c6dee2c$0$17339$ed362ca5@nr5-q3a.newsreader.com>

monkeys paw wrote:
> FILE contains:
> US,S,2009,Alexander L,R,"AGRICULTURE, NUTRITION AND FORESTRY."
> US,S,2009,Alexander L,R,ARMED SERVICES.
> 
> If i parse the above lines with a split /,/  i will
> correctly get field[5] = "ARMED SERVICES" on line 2,
> but incorrectly field[5] = "AGRICULTURE," on line 1.
> 
> while  ($line = <IN>) {
>     @field = split /,/, $line;
>     print "$field[5]\n";
> }
> 
> Is there a way to modify the split to handle this file format?

Yes,  but it would *probably* be better use a module instead.

split /,(?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)/ ;

Xho


------------------------------

Date: Thu, 19 Aug 2010 22:29:19 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: parsing CSV files
Message-Id: <slrni6rtcp.4le.tadmc@tadbox.sbcglobal.net>

monkeys paw <monkey@joemoney.net> wrote:
> FILE contains:
> US,S,2009,Alexander L,R,"AGRICULTURE, NUTRITION AND FORESTRY."
> US,S,2009,Alexander L,R,ARMED SERVICES.
>
> If i parse the above lines with a split /,/  i will
> correctly get field[5] = "ARMED SERVICES" on line 2,
> but incorrectly field[5] = "AGRICULTURE," on line 1.
>
> while  ($line = <IN>) {
>      @field = split /,/, $line;
>      print "$field[5]\n";
> }
>
> Is there a way to modify the split to handle this file format?


    perldoc -q split

        How can I split a [character] delimited string except when
        inside [character]?


-- 
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: Thu, 19 Aug 2010 18:18:00 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Perl array bug?
Message-Id: <4c6dd696$0$17356$ed362ca5@nr5-q3a.newsreader.com>

Steve C wrote:
> Malcolm Hoar wrote:
>> I believe I may have found a bug in ActivePerl 5.12.1.1201 (64-bit).
>>
>> This problem does *not* arise with ActivePerl 5.10.1.1007 (64-bit).
>>
> 
> Many people have claimed "This doesn't happen with X" as
> proof that Y must somehow be at fault.  Its a fallacy.

It may not be proof, but it pretty good evidence. Some people, when they 
have nothing useful to say, just resort to gratuitous insults.

Xho


------------------------------

Date: Thu, 19 Aug 2010 18:15:35 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Perl array bug?
Message-Id: <4c6dd694$0$17355$ed362ca5@nr5-q3a.newsreader.com>

Uri Guttman wrote:
>>>>>> "MH" == Malcolm Hoar <malch@malch.com> writes:
> 
>   MH> $Big1[$index] = $value;
> 
>   MH> However, the array contains many "holes" (undefined elements).
>   MH> So, this amounts to something like:
> 
>   MH> $Big1[538] = 0;
>   MH> $Big1[53487] = 1;
>   MH> $Big1[35306] = 2;
>   MH> etc.
> 
>   MH> Later, we interate over the array:
> 
>   MH> foreach $key (@Big1) {
>   MH>   $len = length ($key);
>   MH>   if ($len) {
>   MH>     if ($key eq '' && $len == 4) {print "You're kidding me!\n"; }

Instead of printing "You're kidding me", try dumping the value using 
Devel::Peek.  That might give a clue for further debugging.


> 
> you are obviously not using warnings or you would get several
> there. length and eq will warn on undef.

Maybe he does.  Whether he gets warnings or not changes the issue at 
issue not one little bit.

>   MH> I have tried to create a small standalone program that
>   MH> demonstrates the problem but without any success.
> 
> that is important. you can't claim a bug unless you can isolate and show
> it to others with code.

Of course he can.

Xho


------------------------------

Date: Fri, 20 Aug 2010 01:30:20 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Perl array bug?
Message-Id: <i4klrc4q1kg002malch@news.sonic.net>

In article <dlo0k7-t811.ln1@osiris.mauzo.dyndns.org>, Ben Morrow <ben@morrow.me.uk> wrote:

>If you can reproduce the problem at will, try inserting
>
>    use Devel::Peek ();
>    Devel::Peek::Dump $key;

Thank you, sir.

Yes, it's a bit of hassle but I can reproduce the problem
at will. 

So here's the offending part of the code:

foreach $key (@Big1) {
  $len = length ($key);
  if ($len) {
    if ($key eq '') {
      print "Here's our bad boy\n";
      use Devel::Peek ();
      Devel::Peek::Dump $key;
    }

and the output:

Here's our bad boy
SV = PVLV(0x2c4488) at 0x32979a8
  REFCNT = 2
  FLAGS = (GMG,SMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x34932d8
    MG_VIRTUAL = &PL_vtbl_defelem
    MG_TYPE = PERL_MAGIC_defelem(y)
  TYPE = y
  TARGOFF = 1601
  TARGLEN = -1
  TARG = 0x24d760
  SV = PVAV(0x2e5d378) at 0x24d760
    REFCNT = 3
    FLAGS = ()
    ARRAY = 0x34b23e8
    FILL = 63273
    MAX = 65533
    ARYLEN = 0x0
    FLAGS = (REAL)
    Elt No. 0
    Elt No. 1
    Elt No. 2
    Elt No. 3

Unfortunately, I don't understand any of that. If you or anyone
else sees any clues in there, I would be most happy to hear
from you!

I think the array is too large to dump the whole thing. 

And, yes, I fully appreciate your point about code changes
and debugging modes causing the problem to disappear.
Been there and done that a few times before with malloc()
related issues!

-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Thu, 19 Aug 2010 19:16:54 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Perl array bug?
Message-Id: <4c6de4e5$0$17323$ed362ca5@nr5-q3a.newsreader.com>

Malcolm Hoar wrote:
> 
> So here's the offending part of the code:
> 
> foreach $key (@Big1) {
>   $len = length ($key);
>   if ($len) {
>     if ($key eq '') {
>       print "Here's our bad boy\n";
>       use Devel::Peek ();
>       Devel::Peek::Dump $key;
>     }
> 
> and the output:
> 
> Here's our bad boy
> SV = PVLV(0x2c4488) at 0x32979a8
>   REFCNT = 2
>   FLAGS = (GMG,SMG)
>   IV = 0
>   NV = 0
>   PV = 0
>   MAGIC = 0x34932d8
>     MG_VIRTUAL = &PL_vtbl_defelem
>     MG_TYPE = PERL_MAGIC_defelem(y)

This looks like the magic undef that Perl uses in sparse arrays.  All 
(more or less) of the the sparce undefs point to the same structure, to 
save memory.  That structures knows that, if assigned to, it has to 
mutate the thing pointing to it into a real scalar.

 ....

> 
> Unfortunately, I don't understand any of that. If you or anyone
> else sees any clues in there, I would be most happy to hear
> from you!

I don't understand much of it either.  But your format differs from mine 
shortly after where I trimmed it, but I'm using a different version and 
different OS, so that might be expected.

Could you also Dump out another undefined element (one that reports a 
length of zero) for comparison?

Xho


------------------------------

Date: Fri, 20 Aug 2010 02:48:49 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Perl array bug?
Message-Id: <i4kqeh4q1kg006malch@news.sonic.net>

In article <4c6de4e5$0$17323$ed362ca5@nr5-q3a.newsreader.com>, Xho Jingleheimerschmidt <xhoster@gmail.com> wrote:
>Malcolm Hoar wrote:
>> 
>> So here's the offending part of the code:
>> 
>> foreach $key (@Big1) {
>>   $len = length ($key);
>>   if ($len) {
>>     if ($key eq '') {
>>       print "Here's our bad boy\n";
>>       use Devel::Peek ();
>>       Devel::Peek::Dump $key;
>>     }
>> 
>
>Could you also Dump out another undefined element (one that reports a 
>length of zero) for comparison?

Hmmmm, well I just tried Dumping some known elements 
before the foreach loop:

use Devel::Peek ();
print "Big1[1599] should be undef\n";
Devel::Peek::Dump $Big1[1599];
print "Big1[1600] first populated element of this array\n";
Devel::Peek::Dump $Big1[1600];
print "Big1[1601] this is the bad boy with length > 0 and no value\n";
Devel::Peek::Dump $Big1[1601];

This gave very different looking output:

Big1[1599] should be undef
SV = NULL(0x0) at 0x31566c0
  REFCNT = 1
  FLAGS = ()
Big1[1600] first populated element of this array
SV = PV(0x3308370) at 0x3154cf8
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x32e8ac8 "\0\0\0Y"\0
  CUR = 4
  LEN = 8
Big1[1601] this is the bad boy with length > 0 and no value
SV = NULL(0x0) at 0x31559e8
  REFCNT = 1
  FLAGS = ()

So the foreach loop and $key iterator seem to be playing
a role here. 

Let me explore that and compare Dumps directly from the
array with those from $key and $len inside the loop.

-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Fri, 20 Aug 2010 04:46:45 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Perl array bug?
Message-Id: <i4l1bl7210k002malch@news.sonic.net>

In article <dlo0k7-t811.ln1@osiris.mauzo.dyndns.org>, Ben Morrow <ben@morrow.me.uk> wrote:
>> Where we encounter a bizarre situation whereby an element
>> is undefined but has a positive length.
>
>If you can reproduce the problem at will, try inserting

Here's the original code snippet:

foreach $key (@Big1) {
  $len = length ($key);
  if ($len) {
    if ($key eq '' && $len == 4) {print "You're kidding me!\n"; }

When I examined the array elements outside of the foreach
loop, the data seemed clean as best as I could tell.

So, I decided to try and different loop structure and reworked
it in the form:

for ($i = 0; $i < @Big1 - 1; $i++) {
  $key = $Big1[$i];
  $len = length ($key);
  if ($len) {
 ..

That didn't seem to make any difference; the problem still
arose.

Since the bad data seemed to be associated with the value
of $len rather than the value of $key, I decided to attack
the length() call and reworked the code thus:


foreach $key (@Big1) {
  $len = &mylen ($key);
  if ($len) {
 ..

sub mylen {
my ($var) = @_;
$sss = length ($var);
return $sss;
}

And it fixed the problem.

At this point, I am fairly certain it is a bug. Rather less
sure that it is a malloc() related issue. I am wondering if
Perl is trying to optimize the code within the loop and taking
some kind of (inappropriate) shortcut when evaluating the
call to the length() intrinsic?

To summarize, I reduced the salient bit of code to:

foreach $key(@Big1){
  #$len=length($key);
  $len=&mylen($key);
  if ($len && $key eq '') {print "Got the bad boy\n"; exit;}
}
exit;

And this works fine. If I flip the comment to activate the
regular call to length() I get the "bad boy" error.

Obviously, this small snippet is surrounded by gobs of other
code and data which clearly have a bearing on the problem.
I will seek to reduce that to something which would be
reasonable to post for others to study.









-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Fri, 20 Aug 2010 05:35:08 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Perl array bug?
Message-Id: <i4l46c5827q002malch@news.sonic.net>

Here's some isolated code that demonstrates my problem:

@Big1 = ();
$Big1[4] = 0;
$Big1[9] = 1;
$Big1[6] = 2;
my $len = 0; # This appears to be significant
foreach $key (@Big1) {
  $len = length ($key);
  print "key = $key, len=$len\n";
}
exit;

Operating system is 64-bit Windows 7.

Using ActivePerl version 5.12.1.1201 64-bit I get:

C:\ZIP>c:\perl512\bin\perl.exe test.pl
key = , len=0
key = , len=0
key = , len=0
key = , len=0
key = 0, len=1
key = , len=1     <==== ???
key = 2, len=1
key = , len=1     <==== ???
key = , len=1     <==== ???
key = 1, len=1

Using ActivePerl version 5.10.1.1007 64-bit I get:

C:\ZIP>C:\perl510\bin\perl.exe test.pl
key = , len=0
key = , len=0
key = , len=0
key = , len=0
key = 0, len=1
key = , len=0
key = 2, len=1
key = , len=0
key = , len=0
key = 1, len=1

So, what say you guys? Bug or user error?

-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Thu, 19 Aug 2010 23:12:04 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Perl array bug?
Message-Id: <bm6s66d470jgcf94lhfkrj7704im67ghlr@4ax.com>

malch@malch.com (Malcolm Hoar) wrote:
>Here's some isolated code that demonstrates my problem:
>
>@Big1 = ();
>$Big1[4] = 0;
>$Big1[9] = 1;
>$Big1[6] = 2;
>my $len = 0; # This appears to be significant
>foreach $key (@Big1) {
>  $len = length ($key);
>  print "key = $key, len=$len\n";
>}
>exit;
>
>Operating system is 64-bit Windows 7.
>
>Using ActivePerl version 5.12.1.1201 64-bit I get:
>
>C:\ZIP>c:\perl512\bin\perl.exe test.pl
>key = , len=0
>key = , len=0
>key = , len=0
>key = , len=0
>key = 0, len=1
>key = , len=1     <==== ???
>key = 2, len=1
>key = , len=1     <==== ???
>key = , len=1     <==== ???
>key = 1, len=1

>
>So, what say you guys? Bug or user error?

Clearly programmer error. Neither printing the value of nor computing
the length of undef is well defined. It is like division by zero. 
It is an illegal operation, therefore the system can do whatever it
pleases to do. If it is nice then it may fail with an error message like
perl would have done if you had used warnings and strict.
But returning some garbage is just as legitimate. And it just happens
that 5.10 and 5.12 are returning different garbage.

jue


------------------------------

Date: Fri, 20 Aug 2010 07:01:35 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Perl array bug?
Message-Id: <i4l98f4m1fi002malch@news.sonic.net>

In article <bm6s66d470jgcf94lhfkrj7704im67ghlr@4ax.com>, Jürgen Exner <jurgenex@hotmail.com> wrote:
>Clearly programmer error. Neither printing the value of nor computing
>the length of undef is well defined. It is like division by zero. 
>It is an illegal operation, therefore the system can do whatever it
>pleases to do. If it is nice then it may fail with an error message like
>perl would have done if you had used warnings and strict.
>But returning some garbage is just as legitimate. And it just happens
>that 5.10 and 5.12 are returning different garbage.

Well, that's a point of view.

I do not agree that it is like division by zero which clearly
has no meaning (at least in ordinary arithmetic).

In my view, an undef must have a zero length. And, as far as
I know, Perl 5.10.1 and every major version going back 10+
years have reflected that quite consistently.

An undef is rather more like a null pointer, and other
languages (that I have used) will typically handle those 
in a consistent (not random) manner.

I know not whether the change in behavior at 5.12.1 was by
design or happenstance. But I for one consider it somewhat
unfortunate and probably misguided.

Sadly, I'm going to have to review a great deal of code and
I suspect that I am far from alone.

In addition, the role of the "my $len" statement in this
situation troubles me a little and leaves me wondering
whether the changes made at 5.12.1 have other possibly
ugly manifestations.

On balance, I'm inclined to disagree with your position 
and it's certainly inconvenient for me. But I accept that
it has some merit worthy of consideration and I thank you
for making it.

-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Fri, 20 Aug 2010 09:22:10 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Perl array bug?
Message-Id: <4c6e2d22$0$6889$9b4e6d93@newsspool2.arcor-online.net>

On 20.08.2010 08:12, Jürgen Exner wrote:
> malch@malch.com (Malcolm Hoar) wrote:
>> Here's some isolated code that demonstrates my problem:
>>
>> @Big1 = ();
>> $Big1[4] = 0;
>> $Big1[9] = 1;
>> $Big1[6] = 2;
>> my $len = 0; # This appears to be significant
>> foreach $key (@Big1) {
>>  $len = length ($key);
>>  print "key = $key, len=$len\n";
>> }
>> exit;
>>
>> Operating system is 64-bit Windows 7.
>>
>> Using ActivePerl version 5.12.1.1201 64-bit I get:
>>
>> C:\ZIP>c:\perl512\bin\perl.exe test.pl
>> key = , len=0
>> key = , len=0
>> key = , len=0
>> key = , len=0
>> key = 0, len=1
>> key = , len=1     <==== ???
>> key = 2, len=1
>> key = , len=1     <==== ???
>> key = , len=1     <==== ???
>> key = 1, len=1
> 
>>
>> So, what say you guys? Bug or user error?
> 
> Clearly programmer error. Neither printing the value of nor computing
> the length of undef is well defined.

This is Perl, not C. Undef is an empty string when converted to a
string, not some random garbage. It is zero when used in calculations.

It *is* well defined!

Read perlsyn!
------
The only things you need to declare in Perl are report formats and
subroutines (and sometimes not even subroutines).  A variable holds the
undefined value ("undef") until it has been assigned a defined value,
which is anything other than "undef".  When used as a number, "undef" is
treated as 0; when used as a string, it is treated as the empty string,
""; and when used as a reference that isn't being assigned to, it is
treated as an error.
------

This is clearly a bug.

Wolf



------------------------------

Date: Fri, 20 Aug 2010 09:26:59 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Perl array bug?
Message-Id: <slrni6sbi3.esp.hjp-usenet2@hrunkner.hjp.at>

On 2010-08-19 18:08, Malcolm Hoar <malch@malch.com> wrote:
> foreach $key (@Big1) {
>   $len = length ($key);
>   if ($len) {
>     if ($key eq '' && $len == 4) {print "You're kidding me!\n"; }
>
> Where we encounter a bizarre situation whereby an element
> is undefined but has a positive length.

Your code doesn't test whether it is undefined. It tests whether it is
equal to the empty string. However, I don't see how the empty string
could have length 4, so there is something fishy going on. Use the
Dump() function from Devel::Peek to look at the affected values.

	hp



------------------------------

Date: Fri, 20 Aug 2010 07:40:49 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Perl array bug?
Message-Id: <i4lbi1443iq002malch@news.sonic.net>

In article <4c6e2d22$0$6889$9b4e6d93@newsspool2.arcor-online.net>, Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net> wrote:

>This is Perl, not C. Undef is an empty string when converted to a
>string, not some random garbage. It is zero when used in calculations.
>
>It *is* well defined!
>
>Read perlsyn!
>------
>The only things you need to declare in Perl are report formats and
>subroutines (and sometimes not even subroutines).  A variable holds the
>undefined value ("undef") until it has been assigned a defined value,
>which is anything other than "undef".  When used as a number, "undef" is
>treated as 0; when used as a string, it is treated as the empty string,
>""; and when used as a reference that isn't being assigned to, it is
>treated as an error.
>------

Ahhh, thank you. I had been searching for a more formal definition
and explanation of the undef value and had not yet found this.
I kept finding more and more references to the undef function
which wasn't what I needed.

This basically confirms and formalizes all of my instincts!

I am very curious to know if anyone can reproduce the problem
on a non-Windows system. If the issue is Windows specific, I
will certainly contact ActiveState directly. 

It's been a while since I've formally reported a Perl bug.
What's the preferred channel these days? perlbug, or something
else?

-- 
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar           "The more I practice, the luckier I get". |
| malch@malch.com                                     Gary Player. |
| http://www.malch.com/               Shpx gur PQN.                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------

Date: Fri, 20 Aug 2010 10:29:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl array bug?
Message-Id: <rgu1k7-it71.ln1@osiris.mauzo.dyndns.org>


Quoth malch@malch.com (Malcolm Hoar):
> In article <dlo0k7-t811.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
> <ben@morrow.me.uk> wrote:
> 
> >If you can reproduce the problem at will, try inserting
> >
> >    use Devel::Peek ();
> >    Devel::Peek::Dump $key;
> 
> Thank you, sir.
> 
> Yes, it's a bit of hassle but I can reproduce the problem
> at will. 
> 
> So here's the offending part of the code:
> 
> foreach $key (@Big1) {
>   $len = length ($key);
>   if ($len) {
>     if ($key eq '') {
>       print "Here's our bad boy\n";
>       use Devel::Peek ();
>       Devel::Peek::Dump $key;
>     }
> 
> and the output:
> 
> Here's our bad boy
> SV = PVLV(0x2c4488) at 0x32979a8
>   REFCNT = 2
>   FLAGS = (GMG,SMG)
>   IV = 0
>   NV = 0
>   PV = 0

Well, there's nothing that looks wrong there, and the length() of that
scalar should definitely be 'undef', which is false. Hmm.

Wild random guess: are you modifying the array in the loop? There is a
fairly long-standing bug in perl that causes double frees if you do
this, with associated memory corruption. The fact it worked on 5.10 may
just have been coincidence.

Ben



------------------------------

Date: Fri, 20 Aug 2010 02:14:08 -0500
From: tadmc@seesig.invalid
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Message-Id: <6sSdnfc8i7XdtvPRnZ2dnUVZ5smdnZ2d@giganews.com>

Outline
   Before posting to comp.lang.perl.misc
      Must
       - Check the Perl Frequently Asked Questions (FAQ)
       - Check the other standard Perl docs (*.pod)
      Really Really Should
       - Lurk for a while before posting
       - Search a Usenet archive
      If You Like
       - Check Other Resources
   Posting to comp.lang.perl.misc
      Is there a better place to ask your question?
       - Question should be about Perl, not about the application area
      How to participate (post) in the clpmisc community
       - Carefully choose the contents of your Subject header
       - Use an effective followup style
       - Speak Perl rather than English, when possible
       - Ask perl to help you
       - Do not re-type Perl code
       - Provide enough information
       - Do not provide too much information
       - Do not post binaries, HTML, or MIME
      Social faux pas to avoid
       - Asking a Frequently Asked Question
       - Asking a question easily answered by a cursory doc search
       - Asking for emailed answers
       - Beware of saying "doesn't work"
       - Sending a "stealth" Cc copy
      Be extra cautious when you get upset
       - Count to ten before composing a followup when you are upset
       - Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------

Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
    This newsgroup, commonly called clpmisc, is a technical newsgroup
    intended to be used for discussion of Perl related issues (except job
    postings), whether it be comments or questions.

    As you would expect, clpmisc discussions are usually very technical in
    nature and there are conventions for conduct in technical newsgroups
    going somewhat beyond those in non-technical newsgroups.

    The article at:

        http://www.catb.org/~esr/faqs/smart-questions.html

    describes how to get answers from technical people in general.

    This article describes things that you should, and should not, do to
    increase your chances of getting an answer to your Perl question. It is
    available in POD, HTML and plain text formats at:

     http://www.rehabitation.com/clpmisc.shtml

    For more information about netiquette in general, see the "Netiquette
    Guidelines" at:

     http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

    A note to newsgroup "regulars":

       Do not use these guidelines as a "license to flame" or other
       meanness. It is possible that a poster is unaware of things
       discussed here.  Give them the benefit of the doubt, and just
       help them learn how to post, rather than assume that they do 
       know and are being the "bad kind" of Lazy.

    A note about technical terms used here:

       In this document, we use words like "must" and "should" as
       they're used in technical conversation (such as you will
       encounter in this newsgroup). When we say that you *must* do
       something, we mean that if you don't do that something, then
       it's unlikely that you will benefit much from this group.
       We're not bossing you around; we're making the point without
       lots of words.

    Do *NOT* send email to the maintainer of these guidelines. It will be
    discarded unread. The guidelines belong to the newsgroup so all
    discussion should appear in the newsgroup. I am just the secretary that
    writes down the consensus of the group.

Before posting to comp.lang.perl.misc
  Must
    This section describes things that you *must* do before posting to
    clpmisc, in order to maximize your chances of getting meaningful replies
    to your inquiry and to avoid getting flamed for being lazy and trying to
    have others do your work.

    The perl distribution includes documentation that is copied to your hard
    drive when you install perl. Also installed is a program for looking
    things up in that (and other) documentation named 'perldoc'.

    You should either find out where the docs got installed on your system,
    or use perldoc to find them for you. Type "perldoc perldoc" to learn how
    to use perldoc itself. Type "perldoc perl" to start reading Perl's
    standard documentation.

    Check the Perl Frequently Asked Questions (FAQ)
        Checking the FAQ before posting is required in Big 8 newsgroups in
        general, there is nothing clpmisc-specific about this requirement.
        You are expected to do this in nearly all newsgroups.

        You can use the "-q" switch with perldoc to do a word search of the
        questions in the Perl FAQs.

    Check the other standard Perl docs (*.pod)
        The perl distribution comes with much more documentation than is
        available for most other newsgroups, so in clpmisc you should also
        see if you can find an answer in the other (non-FAQ) standard docs
        before posting.

    It is *not* required, or even expected, that you actually *read* all of
    Perl's standard docs, only that you spend a few minutes searching them
    before posting.

    Try doing a word-search in the standard docs for some words/phrases
    taken from your problem statement or from your very carefully worded
    "Subject:" header.

  Really Really Should
    This section describes things that you *really should* do before posting
    to clpmisc.

    Lurk for a while before posting
        This is very important and expected in all newsgroups. Lurking means
        to monitor a newsgroup for a period to become familiar with local
        customs. Each newsgroup has specific customs and rituals. Knowing
        these before you participate will help avoid embarrassing social
        situations. Consider yourself to be a foreigner at first!

    Search a Usenet archive
        There are tens of thousands of Perl programmers. It is very likely
        that your question has already been asked (and answered). See if you
        can find where it has already been answered.

        One such searchable archive is:

         http://groups.google.com/advanced_search

  If You Like
    This section describes things that you *can* do before posting to
    clpmisc.

    Check Other Resources
        You may want to check in books or on web sites to see if you can
        find the answer to your question.

        But you need to consider the source of such information: there are a
        lot of very poor Perl books and web sites, and several good ones
        too, of course.

Posting to comp.lang.perl.misc
    There can be 200 messages in clpmisc in a single day. Nobody is going to
    read every article. They must decide somehow which articles they are
    going to read, and which they will skip.

    Your post is in competition with 199 other posts. You need to "win"
    before a person who can help you will even read your question.

    These sections describe how you can help keep your article from being
    one of the "skipped" ones.

  Is there a better place to ask your question?
    Question should be about Perl, not about the application area
        It can be difficult to separate out where your problem really is,
        but you should make a conscious effort to post to the most
        applicable newsgroup. That is, after all, where you are the most
        likely to find the people who know how to answer your question.

        Being able to "partition" a problem is an essential skill for
        effectively troubleshooting programming problems. If you don't get
        that right, you end up looking for answers in the wrong places.

        It should be understood that you may not know that the root of your
        problem is not Perl-related (the two most frequent ones are CGI and
        Operating System related), so off-topic postings will happen from
        time to time. Be gracious when someone helps you find a better place
        to ask your question by pointing you to a more applicable newsgroup.

  How to participate (post) in the clpmisc community
    Carefully choose the contents of your Subject header
        You have 40 precious characters of Subject to win out and be one of
        the posts that gets read. Don't waste them. Take care while
        composing them, they are the key that opens the door to getting an
        answer.

        Spend them indicating what aspect of Perl others will find if they
        should decide to read your article.

        Do not spend them indicating "experience level" (guru, newbie...).

        Do not spend them pleading (please read, urgent, help!...).

        Do not spend them on non-Subjects (Perl question, one-word
        Subject...)

        For more information on choosing a Subject see "Choosing Good
        Subject Lines":

         http://www.cpan.org/authors/id/D/DM/DMR/subjects.post

        Part of the beauty of newsgroup dynamics, is that you can contribute
        to the community with your very first post! If your choice of
        Subject leads a fellow Perler to find the thread you are starting,
        then even asking a question helps us all.

    Use an effective followup style
        When composing a followup, quote only enough text to establish the
        context for the comments that you will add. Always indicate who
        wrote the quoted material. Never quote an entire article. Never
        quote a .signature (unless that is what you are commenting on).

        Intersperse your comments *following* each section of quoted text to
        which they relate. Unappreciated followup styles are referred to as
        "top-posting", "Jeopardy" (because the answer comes before the
        question), or "TOFU" (Text Over, Fullquote Under).

        Reversing the chronology of the dialog makes it much harder to
        understand (some folks won't even read it if written in that style).
        For more information on quoting style, see:

         http://web.presby.edu/~nnqadmin/nnq/nquote.html

    Speak Perl rather than English, when possible
        Perl is much more precise than natural language. Saying it in Perl
        instead will avoid misunderstanding your question or problem.

        Do not say: I have variable with "foo\tbar" in it.

        Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
        or I have $var = <DATA> (and show the data line).

    Ask perl to help you
        You can ask perl itself to help you find common programming mistakes
        by doing two things: enable warnings (perldoc warnings) and enable
        "strict"ures (perldoc strict).

        You should not bother the hundreds/thousands of readers of the
        newsgroup without first seeing if a machine can help you find your
        problem. It is demeaning to be asked to do the work of a machine. It
        will annoy the readers of your article.

        You can look up any of the messages that perl might issue to find
        out what the message means and how to resolve the potential mistake
        (perldoc perldiag). If you would like perl to look them up for you,
        you can put "use diagnostics;" near the top of your program.

    Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.

    Provide enough information
        If you do the things in this item, you will have an Extremely Good
        chance of getting people to try and help you with your problem!
        These features are a really big bonus toward your question winning
        out over all of the other posts that you are competing with.

        First make a short (less than 20-30 lines) and *complete* program
        that illustrates the problem you are having. People should be able
        to run your program by copy/pasting the code from your article. (You
        will find that doing this step very often reveals your problem
        directly. Leading to an answer much more quickly and reliably than
        posting to Usenet.)

        Describe *precisely* the input to your program. Also provide example
        input data for your program. If you need to show file input, use the
        __DATA__ token (perldata.pod) to provide the file contents inside of
        your Perl program.

        Show the output (including the verbatim text of any messages) of
        your program.

        Describe how you want the output to be different from what you are
        getting.

        If you have no idea at all of how to code up your situation, be sure
        to at least describe the 2 things that you *do* know: input and
        desired output.

    Do not provide too much information
        Do not just post your entire program for debugging. Most especially
        do not post someone *else's* entire program.

    Do not post binaries, HTML, or MIME
        clpmisc is a text only newsgroup. If you have images or binaries
        that explain your question, put them in a publically accessible
        place (like a Web server) and provide a pointer to that location. If
        you include code, cut and paste it directly in the message body.
        Don't attach anything to the message. Don't post vcards or HTML.
        Many people (and even some Usenet servers) will automatically filter
        out such messages. Many people will not be able to easily read your
        post. Plain text is something everyone can read.

  Social faux pas to avoid
    The first two below are symptoms of lots of FAQ asking here in clpmisc.
    It happens so often that folks will assume that it is happening yet
    again. If you have looked but not found, or found but didn't understand
    the docs, say so in your article.

    Asking a Frequently Asked Question
        It should be understood that you may have missed the applicable FAQ
        when you checked, which is not a big deal. But if the Frequently
        Asked Question is worded similar to your question, folks will assume
        that you did not look at all. Don't become indignant at pointers to
        the FAQ, particularly if it solves your problem.

    Asking a question easily answered by a cursory doc search
        If folks think you have not even tried the obvious step of reading
        the docs applicable to your problem, they are likely to become
        annoyed.

        If you are flamed for not checking when you *did* check, then just
        shrug it off (and take the answer that you got).

    Asking for emailed answers
        Emailed answers benefit one person. Posted answers benefit the
        entire community. If folks can take the time to answer your
        question, then you can take the time to go get the answer in the
        same place where you asked the question.

        It is OK to ask for a *copy* of the answer to be emailed, but many
        will ignore such requests anyway. If you munge your address, you
        should never expect (or ask) to get email in response to a Usenet
        post.

        Ask the question here, get the answer here (maybe).

    Beware of saying "doesn't work"
        This is a "red flag" phrase. If you find yourself writing that,
        pause and see if you can't describe what is not working without
        saying "doesn't work". That is, describe how it is not what you
        want.

    Sending a "stealth" Cc copy
        A "stealth Cc" is when you both email and post a reply without
        indicating *in the body* that you are doing so.

  Be extra cautious when you get upset
    Count to ten before composing a followup when you are upset
        This is recommended in all Usenet newsgroups. Here in clpmisc, most
        flaming sub-threads are not about any feature of Perl at all! They
        are most often for what was seen as a breach of netiquette. If you
        have lurked for a bit, then you will know what is expected and won't
        make such posts in the first place.

        But if you get upset, wait a while before writing your followup. I
        recommend waiting at least 30 minutes.

    Count to ten after composing and before posting when you are upset
        After you have written your followup, wait *another* 30 minutes
        before committing yourself by posting it. You cannot take it back
        once it has been said.

AUTHOR
    Tad McClellan and many others on the comp.lang.perl.misc newsgroup.

-- 
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: 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 3087
***************************************


home help back first fref pref prev next nref lref last post