[27144] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8994 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 25 14:05:41 2006

Date: Sat, 25 Feb 2006 11:05:04 -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           Sat, 25 Feb 2006     Volume: 10 Number: 8994

Today's topics:
        A Problem With GD <markem@airmail.net>
        simple pointer operations (newbe) <ldirk@cs.tu-berlin.de>
    Re: simple pointer operations (newbe) <1usa@llenroc.ude.invalid>
    Re: simple pointer operations (newbe) <ldirk@cs.tu-berlin.de>
    Re: simple pointer operations (newbe) (Anno Siegel)
    Re: simple pointer operations (newbe) <1usa@llenroc.ude.invalid>
    Re: simple pointer operations (newbe) <abigail@abigail.nl>
    Re: simple pointer operations (newbe) <tadmc@augustmail.com>
    Re: simple pointer operations (newbe) <jurgenex@hotmail.com>
    Re: simple pointer operations (newbe) <jurgenex@hotmail.com>
    Re: simple pointer operations (newbe) <ldirk@cs.tu-berlin.de>
    Re: simple pointer operations (newbe) <jurgenex@hotmail.com>
    Re: simple pointer operations (newbe) <ldirk@cs.tu-berlin.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 25 Feb 2006 13:06:00 -0600
From: Mark Manning <markem@airmail.net>
Subject: A Problem With GD
Message-Id: <1201aimaa6bj368@corp.supernews.com>

To whomever works on GD:

I believe I may have uncovered a problem with the GIF renderer under GD. 
  I can reproduce the error and send you both the code that is causing 
the error as well as a GIF example of the error.  I can also send a PNG 
file showing what it should look like.

Synopsis of the error: Under certain color conditions, the GIF renderer 
places additional dots of color into the image that it should not do. 
In my test I am only allocating two colors.  I originally tried the 
colorAllocate routine and then tried the colorExact routine.  Neither 
had an effect on the problem.

What it is I am doing:  I am generating tiles with random dots on the 
tiles to be used in a game.  The tiles are generated on the fly.  There 
are only two colors being used per tile.  A foreground color and a 
background color.  (So GIF should be able to handle this without a 
problem.)  But I do generate multiple tiles and each individual tile 
might have a slightly different color than the one next to it.  (So in 
this case I am generating tiles to represent dirt so some tiles are 
brown, some are light brown, and some are dark brown.)

What is happening: On the slightly darker tiles I am getting lines of 
dots going across the tile.



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

Date: Sat, 25 Feb 2006 15:15:07 +0100
From: "Dirk Lehmann" <ldirk@cs.tu-berlin.de>
Subject: simple pointer operations (newbe)
Message-Id: <dtpopf$5et$02$1@news.t-online.com>

Hello,

In the following example I like to print out the array (@$b). But it don't 
works. Perl don't like converting the scalar (after incrementation) to a 
reference. How can I cast the scalar to a reference? (I know that their are 
other possibilities around to print out an array for this example.)

######
use strict;

my $b = [reverse(10..15)];
my $buf = \($b->[0]);
for(0..$#$b)
{
  print "\$buf points to address $buf and their is $$buf\n"; #line 14 in 
runtime error
  $buf++;
}
######

output:
------
$buf points to address SCALAR(0x22531c) and their is 15
Can't use string ("2249501") as a SCALAR ref while "strict refs" in use at 
/home/[...]/Pointer2.pl line 14.
------

Thanks, Dirk. 




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

Date: Sat, 25 Feb 2006 14:43:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: simple pointer operations (newbe)
Message-Id: <Xns977562F4C4479asu1cornelledu@127.0.0.1>

"Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
news:dtpopf$5et$02$1@news.t-online.com: 

> Subject: simple pointer operations (newbe)

Perl is not C. No pointers. Just references.

> How can I cast the scalar to a reference? 

You should not even want to.

> (I know that their are other possibilities around to print
> out an array for this example.)

Then use those methods.
 
> ######
> use strict;

use warnings;

missing.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Sat, 25 Feb 2006 15:53:59 +0100
From: "Dirk Lehmann" <ldirk@cs.tu-berlin.de>
Subject: Re: simple pointer operations (newbe)
Message-Id: <dtpr2b$cvo$01$1@news.t-online.com>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
news:Xns977562F4C4479asu1cornelledu@127.0.0.1...
> "Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
> news:dtpopf$5et$02$1@news.t-online.com:
>
>> How can I cast the scalar to a reference?
>
> You should not even want to.
>

Yes, I know that it is very critical to 'play' with pointers on this way ;)

>
>> ######
>> use strict;
>
> use warnings;
>

It wasn't the complete code:

######
#!/usr/local/bin/perl -w

use strict;

my $a = \12345;
print "\$a points to address $a and their is $$a\n\n";

my $b = [reverse(10..15)]; #equal to '$b = \(reverse(10..15))'
print "\$b points to address $b and their is (@$b)\n";
print "output with pointer operations:\n";
my $buf = \($b->[0]);
for(0..$#$b)
{
  print "\$buf points to address $buf and their is $$buf\n";
  $buf++;
}
######

Sorry for my bad english,
Dirk. 




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

Date: 25 Feb 2006 15:04:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: simple pointer operations (newbe)
Message-Id: <dtprld$m5f$1@mamenchi.zrz.TU-Berlin.DE>

Dirk Lehmann <ldirk@cs.tu-berlin.de> wrote in comp.lang.perl.misc:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
> news:Xns977562F4C4479asu1cornelledu@127.0.0.1...
> > "Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
> > news:dtpopf$5et$02$1@news.t-online.com:
> >
> >> How can I cast the scalar to a reference?
> >
> > You should not even want to.
> >
> 
> Yes, I know that it is very critical to 'play' with pointers on this way ;)

It's not critical, it's nonsense.

When you increment a reference, Perl uses the reference address as an
integer and increments that.  If you were to re-interpret the incremented
number as a memory address, that wouldn't even be correctly aligned on most
machines.  In any case it points to a random place in memory, there is
no way of predicting what will be found there.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Sat, 25 Feb 2006 15:14:44 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: simple pointer operations (newbe)
Message-Id: <Xns97756853038E2asu1cornelledu@127.0.0.1>

"Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
news:dtpr2b$cvo$01$1@news.t-online.com: 

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
> news:Xns977562F4C4479asu1cornelledu@127.0.0.1...
>> "Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
>> news:dtpopf$5et$02$1@news.t-online.com:
>>
>>> How can I cast the scalar to a reference?
>>
>> You should not even want to.
>>
> 
> Yes, I know that it is very critical to 'play' with pointers on this
> way ;) 

Smiley notwithstanding, you missed my point about there not being any 
pointers in Perl. Only references.

>>> ######
>>> use strict;
>>
>> use warnings;
>>
> 
> It wasn't the complete code:
> 
> ######
> #!/usr/local/bin/perl -w
> 
> use strict;
> 
> my $a = \12345;
>
> print "\$a points to address $a and their is $$a\n\n";

$a is now a reference. When you dereference it, you get the value it 
references. $a is not a pointer.

> my $b = [reverse(10..15)]; #equal to '$b = \(reverse(10..15))'
> print "\$b points to address $b and their is (@$b)\n";

$b does not point to an address. It references the specific anonymous 
array you have created. Not to any of its elements, including the first 
element. Perl is not C. 

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 25 Feb 2006 16:24:27 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: simple pointer operations (newbe)
Message-Id: <slrne0115r.h1.abigail@alexandra.abigail.nl>

Dirk Lehmann (ldirk@cs.tu-berlin.de) wrote on MMMMDLXI September MCMXCIII
in <URL:news:dtpr2b$cvo$01$1@news.t-online.com>:
:)  
:)  It wasn't the complete code:
:)  
:)  ######
:)  #!/usr/local/bin/perl -w
:)  
:)  use strict;
:)  
:)  my $a = \12345;
:)  print "\$a points to address $a and their is $$a\n\n";
:)  
:)  my $b = [reverse(10..15)]; #equal to '$b = \(reverse(10..15))'

Eh, no. 

    $ perl -wle '$b = [reverse (10 .. 15)]; print ref $b'
    ARRAY
    $ perl -wle '$b = \(reverse (10 .. 15)); print ref $b'
    SCALAR



Once again, Perl has references. Not pointers. And while the
stringification of a reference of an array contains a memory address,
and that memory address is indeed the address of the array, it's NOT the
address of the first element. It's the address of a struct (the array)
of which one element points to an array of pointers of structures
containing scalars.

Perl is not C.



Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


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

Date: Sat, 25 Feb 2006 10:29:26 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: simple pointer operations (newbe)
Message-Id: <slrne011f6.h79.tadmc@magna.augustmail.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Dirk Lehmann <ldirk@cs.tu-berlin.de> wrote in comp.lang.perl.misc:
>> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
>> news:Xns977562F4C4479asu1cornelledu@127.0.0.1...
>> > "Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
>> > news:dtpopf$5et$02$1@news.t-online.com:
>> >
>> >> How can I cast the scalar to a reference?
>> >
>> > You should not even want to.
>> >
>> 
>> Yes, I know that it is very critical to 'play' with pointers on this way ;)
> 
> It's not critical, it's nonsense.


I assumed Dirk didn't get the translation to English quite right.

I think he meant to say:

   I know that it is often criticized to 'play' with pointers this way.

ie. he realizes the pitfalls of pointer arithmetic.



Dirk,

The way you said it might well be taken to mean:

  I know that it is essential to 'play' with pointers on this way

Which is the meaning that I think prompted Anno's followup here.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 25 Feb 2006 16:34:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: simple pointer operations (newbe)
Message-Id: <kG%Lf.345$3W5.220@trnddc02>

Dirk Lehmann wrote:
> Hello,
>
> In the following example I like to print out the array (@$b). But it
> don't works. Perl don't like converting the scalar (after
> incrementation) to a reference.

A reference _is_ a scalar already.

> How can I cast the scalar to a
> reference?

Perl does not have casting. I think you are confusing programming languages.
Perl references are much more advanced than pointers in those other 
languages and you don't do arithmetic on them.

jue




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

Date: Sat, 25 Feb 2006 16:39:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: simple pointer operations (newbe)
Message-Id: <aL%Lf.1794$%v4.250@trnddc03>

Dirk Lehmann wrote:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
> news:Xns977562F4C4479asu1cornelledu@127.0.0.1...
>> "Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
>> news:dtpopf$5et$02$1@news.t-online.com:
>>
>>> How can I cast the scalar to a reference?
>>
>> You should not even want to.
>>
>
> Yes, I know that it is very critical to 'play' with pointers on this
> way ;)

No, it is not critical.
It is dangerous and plain stupid and therefore Perl doesn't support it.

> my $a = \12345;
> print "\$a points to address $a and their is $$a\n\n";

References are not memory addresses and memory addresses are not references.
Either get used to that or use a more low-level programming language where 
the programmer may be able to access the memory via pointers directly but in 
return is forced to implement all memmory allocation and garbage collection 
himself.

jue 




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

Date: Sat, 25 Feb 2006 17:51:57 +0100
From: "Dirk Lehmann" <ldirk@cs.tu-berlin.de>
Subject: Re: simple pointer operations (newbe)
Message-Id: <dtq1vi$k3n$03$1@news.t-online.com>

"Abigail" <abigail@abigail.nl> wrote in 
news:slrne0115r.h1.abigail@alexandra.abigail.nl...
> Dirk Lehmann (ldirk@cs.tu-berlin.de) wrote on MMMMDLXI September MCMXCIII
> in <URL:news:dtpr2b$cvo$01$1@news.t-online.com>:
> :)
> :)  It wasn't the complete code:
> :)
> :)  ######
> :)  #!/usr/local/bin/perl -w
> :)
> :)  use strict;
> :)
> :)  my $a = \12345;
> :)  print "\$a points to address $a and their is $$a\n\n";
> :)
> :)  my $b = [reverse(10..15)]; #equal to '$b = \(reverse(10..15))'
>
> Eh, no.
>
>    $ perl -wle '$b = [reverse (10 .. 15)]; print ref $b'
>    ARRAY
>    $ perl -wle '$b = \(reverse (10 .. 15)); print ref $b'
>    SCALAR
>
>
>
> Once again, Perl has references. Not pointers. And while the
> stringification of a reference of an array contains a memory address,
> and that memory address is indeed the address of the array, it's NOT the
> address of the first element. It's the address of a struct (the array)
> of which one element points to an array of pointers of structures
> containing scalars.
>
> Perl is not C.
>

Okay, I think that I should learn much more about the differences between a 
pointer and a reference. I'm just at the beginning to understand references 
because the most introductions to Perl let references shown like a pointer 
and don't tell the reader what are the differences.

Thanks and sorry for my bad english again,
Dirk. 




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

Date: Sat, 25 Feb 2006 17:04:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: simple pointer operations (newbe)
Message-Id: <y60Mf.762$FE2.730@trnddc01>

Dirk Lehmann wrote:
> Okay, I think that I should learn much more about the differences
> between a pointer and a reference. I'm just at the beginning to
> understand references because the most introductions to Perl let
> references shown like a pointer

Which actually is correct. References do point to thingies, so they are 
pointers.

> and don't tell the reader what are
> the differences.

Which only becomes a problem if you make assumptions based on you previous 
experience in other programming languages where "pointer" has a different 
and unfortunately overlapping meaning.

It's like on airplanes the rudder and therefore stearing on the ground is 
controlled by foot pedals. Now, don't try to push the right pedal to make a 
right turn when you are in a car.

jue




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

Date: Sat, 25 Feb 2006 19:36:32 +0100
From: "Dirk Lehmann" <ldirk@cs.tu-berlin.de>
Subject: Re: simple pointer operations (newbe)
Message-Id: <dtq83l$dv4$01$1@news.t-online.com>

"Tad McClellan" <tadmc@augustmail.com> wrote in 
news:slrne011f6.h79.tadmc@magna.augustmail.com...
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> Dirk Lehmann <ldirk@cs.tu-berlin.de> wrote in comp.lang.perl.misc:
>>> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
>>> news:Xns977562F4C4479asu1cornelledu@127.0.0.1...
>>> > "Dirk Lehmann" <ldirk@cs.tu-berlin.de> wrote in
>>> > news:dtpopf$5et$02$1@news.t-online.com:
>>> >
>>> >> How can I cast the scalar to a reference?
>>> >
>>> > You should not even want to.
>>> >
>>>
>>> Yes, I know that it is very critical to 'play' with pointers on this way 
>>> ;)
>>
>> It's not critical, it's nonsense.
>
>
> I assumed Dirk didn't get the translation to English quite right.
>
> I think he meant to say:
>
>   I know that it is often criticized to 'play' with pointers this way.
>
> ie. he realizes the pitfalls of pointer arithmetic.
>
>
>
> Dirk,
>
> The way you said it might well be taken to mean:
>
>  I know that it is essential to 'play' with pointers on this way
>
> Which is the meaning that I think prompted Anno's followup here.
>
>

Ooh sorry,

I surveyed this posting.

I meant: I know that it is dangerous to use the pointer arithmetic because 
if you do a wrong calculation or do not check if you have left your data 
structure, you can points outside this. And it's very dangerous if an user 
overwrite items in your stack, for example a return-address! That's what I 
mean.

But, now I know that you don't have this problem in Perl. ;)

Dirk. 




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8994
***************************************


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