From: yitzle <[EMAIL PROTECTED]>
> On 10/10/07, Kaushal Shriyan <[EMAIL PROTECTED]> wrote:
> >
> > Can you please explain me with a sample code. If I understand it correctly
> > does the below code holds true for your explanation
>
> Lets put it this way.
> I the world of C/C++, there's something called a pointer.
In the world of Perl, there's something called a reference.
> The syntax of Perl and C/C++ is not the same, but I'll make an effort....
> You can have code like this:
>
> *c = 5; // The thing that $c points to now is 5
$$c = 5;
> a = c; // Now a and c are the same, ie refer to the same item. printing "$a
> = $c" would print "5 = 5"
$a = $c; # now, just like in C, $a and $c have the same value,
# ie refer to the same item
# printing "$$a = $$c" would print "5 = 5"
# and just like you have to dereference the variables in
# Perl, you'd have to dereference them in C:
# printf( '%s = %s', *a, *c);
> *c = 6; // The thing that $c points to now is 6. $a points to the same thing
> as $c does, so now print "$a" would print 6. Even though $a wasn't changed!!
$$c = 6; # and print "$$a" would print 6.
> Anyhow, the point is that Perl doesn't have those confusing weird "pointer"
> stuff. $a and $c do not "point" to the same place, the just got the same
> value. (Well, Perl /does/ have pointers, but... whatever.)
Yeah, it does seem you are pretty confused by pointers in C. And
probably by references in Perl too. I wonder how can you program
without understanding pointers/references, but whatever.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/