in reply to lazy loading and memory usage

This claim doesn't sound right to me.

foreach my $gene ( @{ $first_clone->get_all_Genes() } ) { print $gene->stable_id(), "\n"; }
$first_clone->get_all_Genes() returns a reference to an array. This is de-referenced to make a list of all elements (this takes some memory), then the foreach iterates over that list of elements.

This is the same as:

my $gene_ref= $first_clone->get_all_Genes(); foreach my $gene (@$gene_ref) # or (@{$gene_ref}), the same. # extra {} only needed # when subscript is used { print $gene->stable_id(), "\n"; }
The second code:
my $genes = $first_clone->get_all_Genes(); while ( my $gene = shift @{$genes} ) { print $gene->stable_id(), "\n"; }
This code is going to create the list of @$genes just like the first code, but uses a different formulation of the iterator than "foreach". I would expect that this formulation uses the same amount of memory as the first code (i.e. that a complete de-referenced list of @$genes is built as a preliminary step). The claim appears to be that somehow this does not create a list of @$genes. I would expect that the memory usage of the second version is the same and probably runs a bit slower than the foreach() iterator would. It is certainly more obtuse from a coding style.

If this is not the case, then I would also like to hear about it. But on the surface, this claim appears to be incorrect.

Update:I didn't consider that some memory consuming operation would happen with: $gene->stable_id(). When I saw the print, I just was thinking that this printed some existing value. Kudos to BrowerUk.