On Dec 31, 2007 5:43 PM, gst <[EMAIL PROTECTED]> wrote: > hi, > > iirc, in C if I store somwhere a pointer to a "stack" value (e.g.: > call a function with an auto variable, return its pointer) i know i'm > going to mess things, since that piece of data will be most probably > overwritten by subsequent calls. > > if I do the same in Perl (with a hard ref), do I have any guarantee > that the same behavior (implicit aliasing) does - or does not (every > new scalar is guaranteed to not alias the old non existant value) - > apply? > > thank you in advance > gst
When you say my @refs; for (1 .. 5) { my $value; push @refs, \$value; } You get five distinct memory locations. Each time the my function is executed you get a new memory address. This is why things like closures work. Saying my in Perl is like* saying struct scalar_struct* var = malloc(sizeof(struct scalar_struct)); with the call to free() being handled for by the garbage collection system (when the number of references goes to zero). * this is not literal -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/