in reply to Large data processing ...

sub get_exon { return substr($_[0], $_[1] - 1, $_[2] - $_[1] + 1); }

Note that by using $_[0] directly, you're accessing $chromosome without copying it. This is because the @_ array is aliased to the parameters passed. So this saves you a reference and a dereference on top of the savings that you would have when passing a reference, while you lose out on readability.

Liz

Replies are listed 'Best First'.
Re: Re: Large data processing ...
by demerphq (Chancellor) on Oct 18, 2003 at 18:53 UTC

    This is because the @_ array is aliased to the parameters passed.

    Its worth explaining aliasing a little better I think: I like to think of it as a reference that doesn't need dereferencing. Which is essentially how its implemented as well. :-)

    while you lose out on readability.

    Well, you could use for:

    sub get_exon { my $end=pop; my $begin=pop; # alias $_[0] to $chromosome to avoid copy semantics speed penalty for my $chromosome (@_) { return substr($chromosome, $begin - 1, $end - $begin + 1); } } # or perhaps sub get_exon { my ($begin,$end)=@_[1,2]; # alias $_[0] to $chromosome to avoid copy semantics speed penalty for my $chromosome (@_) { return substr($chromosome, $begin - 1, $end - $begin + 1); } }

    But of course its not as efficient as the straight forward access to @_, but it is worth remembering that for (LIST) aliases the iterator var to the values being iterated over. As such this might be a nice middle ground between super-optimised and unreadable, and optimised and relatively readable.

    :-)


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi