[31610] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2869 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 11 14:14:23 2010

Date: Thu, 11 Mar 2010 11:14:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 11 Mar 2010     Volume: 11 Number: 2869

Today's topics:
    Re: Well, that's the most obscure Perl bug I've ever se <no-one@unknown.com>
    Re: Well, that's the most obscure Perl bug I've ever se <devnull4711@web.de>
    Re: Well, that's the most obscure Perl bug I've ever se <devnull4711@web.de>
    Re: Well, that's the most obscure Perl bug I've ever se <tadmc@seesig.invalid>
    Re: Well, that's the most obscure Perl bug I've ever se sln@netherlands.com
    Re: Well, that's the most obscure Perl bug I've ever se <devnull4711@web.de>
    Re: Well, that's the most obscure Perl bug I've ever se <jl_post@hotmail.com>
    Re: Well, that's the most obscure Perl bug I've ever se <uri@StemSystems.com>
    Re: Well, that's the most obscure Perl bug I've ever se <glennj@ncf.ca>
    Re: Well, that's the most obscure Perl bug I've ever se <devnull4711@web.de>
        Writing to the end of a record <jruffino@gailborden.info>
    Re: Writing to the end of a record <uri@StemSystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 11 Mar 2010 14:16:30 GMT
From: pete <no-one@unknown.com>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <slrnhphupu.b0v.no-one@corv.local>

On Thu, 11 Mar 2010 14:41:01 +0100, Frank Seitz wrote:
> pete wrote:
>> 
>> $
>> 
>> # set up a counter
>> $i = 0;
>
> $$i = 0;
>
> This statement creates a scalar reference and assigns it to $i.
> This mechanism is called autovivification.
> A reference is basically an integer which you can increment:
>
> $$i = 0;
> print "$i\n";
> $i++;
> print "$i\n";
> __END__
> SCALAR(0x94a3168)
> 155857257
>
> Frank

What surprised me was that perl didn't see the $<extraneous stuff+whitespace># ...
and try to calculate the size of an array named by the comment, thus:

$# set ... 
$i = 0;

which would at least have spat out a syntax error


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

Date: Thu, 11 Mar 2010 16:17:12 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <7vsfroFco2U2@mid.individual.net>

Ben Morrow wrote:
> Quoth Frank Seitz <devnull4711@web.de>:
>> pete wrote:
>>> $
>>>
>>> # set up a counter
>>> $i = 0;
>>
>> $$i = 0;
>>
>> This statement creates a scalar reference and assigns it to $i.
>> This mechanism is called autovivification.
>> A reference is basically an integer which you can increment:
> 
> No. A reference can be numified, and will be if you apply a numeric
> operator like ++ to it.

Yes, this is what I meant. The conversion makes sense because
a reference is basically a memory address (plus type),
and a memory address is an integer.

> The result is not a reference, so you can't use
> this to go grubbing around in arbitrary bits of memory.

I did not say that I can do pointer arithmetic on the result.
We talk about Perl, not C :)

Frank
-- 
Dipl.-Inform. Frank Seitz
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2


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

Date: Thu, 11 Mar 2010 16:19:08 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <7vsfvcFco2U3@mid.individual.net>

pete wrote:
> On Thu, 11 Mar 2010 14:41:01 +0100, Frank Seitz wrote:
>>
>> $$i = 0;
>> print "$i\n";
>> $i++;
>> print "$i\n";
>> __END__
>> SCALAR(0x94a3168)
>> 155857257
> 
> What surprised me was that perl didn't see the $<extraneous stuff+whitespace># ...
> and try to calculate the size of an array named by the comment, thus:
> 
> $# set ... 
> $i = 0;
> 
> which would at least have spat out a syntax error

"# set ..." is a comment and is ignored by Perl.
The rest is syntactically ok, because Perl allows whitespace
between the dereference operator $ and the variable $i.

Frank
-- 
Dipl.-Inform. Frank Seitz
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2


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

Date: Thu, 11 Mar 2010 09:50:10 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <slrnhpi429.dkg.tadmc@tadbox.sbcglobal.net>

Frank Seitz <devnull4711@web.de> wrote:
> pete wrote:
>> On Thu, 11 Mar 2010 14:41:01 +0100, Frank Seitz wrote:
>>>
>>> $$i = 0;
>>> print "$i\n";
>>> $i++;
>>> print "$i\n";
>>> __END__
>>> SCALAR(0x94a3168)
>>> 155857257
>> 
>> What surprised me was that perl didn't see 
>> the $<extraneous stuff+whitespace># ...
>> and try to calculate the size of an array named by the comment, thus:
>> 
>> $# set ... 
>> $i = 0;
>> 
>> which would at least have spat out a syntax error
>
> "# set ..." is a comment and is ignored by Perl.


You miss pete's point, which was that the "#" was part of "$#...".

"$#set" is the last index of the @set array.

"$# set" is a syntax error.

> The rest is syntactically ok, because Perl allows whitespace
> between the dereference operator $ and the variable $i.


But it does not allow whitespace between the $# and the array name.

---------------------------
#!/usr/bin/perl
use warnings;
use strict;

my @set = qw(one two);

#print $#set, "\n"; # works fine
print $# set, "\n"; # syntax error
---------------------------


-- 
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, 11 Mar 2010 08:02:20 -0800
From: sln@netherlands.com
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <jt3ip5l98o6u8m899m39u13qekic420j30@4ax.com>

On Thu, 11 Mar 2010 14:41:01 +0100, Frank Seitz <devnull4711@web.de> wrote:

>pete wrote:
>> 
>> $
>> 
>> # set up a counter
>> $i = 0;
>
>$$i = 0;
>
>This statement creates a scalar reference and assigns it to $i.
>This mechanism is called autovivification.

But, a scalar dereference can't be declared as in:
my $$i = 0;

So, from a declaration standpoint, this
  $$i = 0  
is actually this
  my $i = \0;
a reference to a read-only constant.

>A reference is basically an integer which you can increment:

A reference is a pseudo pointer to other data (of any type).
The reference count increments as below.

$$i = \6;
print "$i\n";
print "$$i\n";
print "$$$i\n";

print "\n";

my $B = \\\\9;
print "$B\n";
print "$$B\n";
print "$$$B\n";
print "$$$$B\n";
print "$$$$$B\n";
__END__

REF(0x22ab94)
SCALAR(0x22ac44)
6

REF(0x182a9bc)
REF(0x182a99c)
REF(0x182a98c)
SCALAR(0x182a92c)
9

-sln


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

Date: Thu, 11 Mar 2010 17:07:37 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <7vsiq9Fco2U4@mid.individual.net>

Tad McClellan wrote:
> Frank Seitz <devnull4711@web.de> wrote:
>> pete wrote:
>>>
>>> What surprised me was that perl didn't see 
>>> the $<extraneous stuff+whitespace># ...
>>> and try to calculate the size of an array named by the comment, thus:
>>>
>>> $# set ... 
>>> $i = 0;
>>>
>>> which would at least have spat out a syntax error
>>
>> "# set ..." is a comment and is ignored by Perl.
> 
> You miss pete's point, which was that the "#" was part of "$#...".
> 
> "$#set" is the last index of the @set array.
> 
> "$# set" is a syntax error.

I talked about the original code. In that code is whitespace
between the $ and the #, i.e. # starts a comment.

Frank
-- 
Dipl.-Inform. Frank Seitz
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2


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

Date: Thu, 11 Mar 2010 08:48:34 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <f44d82a3-8990-42b1-b25a-2084bad8ffbe@t34g2000prm.googlegroups.com>


> On Thu, 11 Mar 2010 14:19:26 +0100, ace wrote:
>
> > It's your own fault actually. Put use strict; on top of your program an=
d
> > try to reproduce misbehavior.


On Mar 11, 7:04=A0am, pete <no-...@unknown.com> wrote:
>
> Not practical - it's not my original code, just my original bug :-(


   I once inherited several Perl scripts with about one thousand lines
of code in each one.  Unfortunately, none of those scripts had "use
strict" and "use warnings" in them.

   Originally, I decided it was not practical to add "use strict" and
"use warnings" to the top of the scripts (although I did include them
in the blocks I added).  Eventually, maintaining the scripts became
such a huge hassle that I "bit the bullet" and added "use strict" and
"use warnings" to the top of the scripts (and modified the code enough
to comply).

   It wasn't easy adding "use strict" and "use warnings" to the files,
but now maintaining the scripts is about ten times easier.

   So I recommend adding "use strict" and "use warnings" to the script
you're maintaining, even if it takes you several hours to do so.  But
if you can't do that, I still recommend adding them in new blocks you
write (like inside loops, subroutines, and if-blocks).  That's not
normally done, but I find it's much better than just never using
"strict" and "warnings" altogether.

   -- Jean-Luc


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

Date: Thu, 11 Mar 2010 13:35:48 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <87tysmvh8b.fsf@quad.sysarch.com>

>>>>> "FS" == Frank Seitz <devnull4711@web.de> writes:

  FS> Yes, this is what I meant. The conversion makes sense because
  FS> a reference is basically a memory address (plus type),
  FS> and a memory address is an integer.

to be clear, a ref will return a number (the address) in a numeric
context or the TYPE(0xfdddd) style in a string context. it is not a
number but a multivalued thing that returns different things in
different contexts. it is a ref, number AND string all in the same
scalar if you want to see it that way. but once you modify it with ++ it
becomes only a number thereafter.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: 11 Mar 2010 18:45:03 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <slrnhpiehg.5j.glennj@smeagol.ncf.ca>

At 2010-03-11 11:07AM, "Frank Seitz" wrote:
>  Tad McClellan wrote:
> > Frank Seitz <devnull4711@web.de> wrote:
> >> pete wrote:
> >>>
> >>> What surprised me was that perl didn't see 
> >>> the $<extraneous stuff+whitespace># ...
> >>> and try to calculate the size of an array named by the comment, thus:
> >>>
> >>> $# set ... 
> >>> $i = 0;
> >>>
> >>> which would at least have spat out a syntax error
> >>
> >> "# set ..." is a comment and is ignored by Perl.
> > 
> > You miss pete's point, which was that the "#" was part of "$#...".
> > 
> > "$#set" is the last index of the @set array.
> > 
> > "$# set" is a syntax error.
>  
>  I talked about the original code. In that code is whitespace
>  between the $ and the #, i.e. # starts a comment.

We can ask perl what it sees:

    perl -MO=Deparse -e '
        $
        # a comment
        $i = 0;
        print $i;
    '

which gives

    $$i = 0;
    print $i;
    -e syntax OK


-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous


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

Date: Thu, 11 Mar 2010 20:02:44 +0100
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Well, that's the most obscure Perl bug I've ever seen
Message-Id: <7vst2kFhiaU1@mid.individual.net>

Uri Guttman wrote:
>>>>>> "FS" == Frank Seitz <devnull4711@web.de> writes:
> 
>   FS> Yes, this is what I meant. The conversion makes sense because
>   FS> a reference is basically a memory address (plus type),
>   FS> and a memory address is an integer.
> 
> to be clear, a ref will return a number (the address) in a numeric
> context or the TYPE(0xfdddd) style in a string context. it is not a
> number but a multivalued thing that returns different things in
> different contexts. it is a ref, number AND string all in the same
> scalar if you want to see it that way. but once you modify it with ++ it
> becomes only a number thereafter.

Very good explanation, except that I would not say that
a reference "returns" something, because it is a (passive) data structure.

Frank
-- 
Dipl.-Inform. Frank Seitz
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2


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

Date: Thu, 11 Mar 2010 10:36:28 -0800 (PST)
From: Joe <jruffino@gailborden.info>
Subject: Writing to the end of a record
Message-Id: <d7bbdbd9-7269-4d0a-a808-ab9577db7f1f@t20g2000yqe.googlegroups.com>

Hi,

I am trying to write to the end of a record once I find the data
needed, but everything I have tried and the Internet is no real help.

I open my data file by using 'open (LOCATE +<$filename') and the data
is processed correctly when a match is found.  It is when I try to
write to the end is when I have trouble.

I have tried, using 'print LOCATE ($_ . ", done")', but when I run the
program the data is never written to the file

 If someone could tell me what i am doing wrong, I would really
appreciate it.


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

Date: Thu, 11 Mar 2010 14:05:16 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Writing to the end of a record
Message-Id: <878w9yvfv7.fsf@quad.sysarch.com>

>>>>> "J" == Joe  <jruffino@gailborden.info> writes:

  J> Hi,
  J> I am trying to write to the end of a record once I find the data
  J> needed, but everything I have tried and the Internet is no real help.

  J> I open my data file by using 'open (LOCATE +<$filename') and the data
  J> is processed correctly when a match is found.  It is when I try to
  J> write to the end is when I have trouble.

hopefully that isn't the full open call as it won't compile. please show
real code when you post and not something you typed here.

  J> I have tried, using 'print LOCATE ($_ . ", done")', but when I run the
  J> program the data is never written to the file

try doing a seek between the read and write. see perldoc -f seek for why
and how to do that.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

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 2869
***************************************


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