Rev Lebaredian <[EMAIL PROTECTED]> wrote:

> >>>  | > +        my $large_string = eval ' "a" x 5_000_000 ';
> 
> I'm not sure of this but it seems to me that the expression will work 
> without the eval.  I'm guessing the eval is there as form of exception 
> handling in case the allocation fails.  If this is the case then the 
> eval is being used for a well documented and recommended technique.

No. In Perl, each operator, such as 'x', is (at compile time) allocated
a private SV for storing its result. This SV is stored in the
scratchpad of the sub the op is compiled into, and only gets deleted
when the sub is deleted - this is usually at program exit, but happens
earlier with an eval.
Since in this context the eval is purely a way round a pecularity of the
current implementation of perl,  its use is probably not be be encouraged.


Dave M.

Reply via email to