in reply to Crazy Golf : creating hex ranges from non-consecutive hex data values

my @hexv; while (<DATA>) { chomp; my @vals = split ' ', $_; @hexv = (@hexv,@vals) }

@hexv = (@hexv,@vals) Really!?    Haven't you heard of push?

And it doesn't have to be that complicated:

my @hexv; while (<DATA>) { push @hexv, split; }

Or even:

my @hexv = map split, <DATA>;


my $endex = scalar @hexv - 1;

More correctly written as:

my $endex = $#hexv;


foreach my $index ( 0 .. $endex ){ last if $index == $endex;

Why not just:

foreach my $index ( 0 .. $endex - 1 ){

Replies are listed 'Best First'.
Re^2: Crazy Golf : creating hex ranges from non-consecutive hex data values
by zentara (Cardinal) on Aug 01, 2011 at 13:36 UTC
    Thanks for pointing out all my code sloppiness jwkrahn. Would you believe that I purposely left that in there, just to see who would correct me? :-) But thanks for pointing it out, so that anyone coming upon this node in the future, won't pick up bad sloppy practices.

    I do indeed appreciate the pursuit of perfection.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re^2: Crazy Golf : creating hex ranges from non-consecutive hex data values
by Anonymous Monk on Aug 01, 2011 at 05:11 UTC

    @hexv = (@hexv,@vals) Really!? Haven't you heard of push?

    Lets see, perfectly legal syntax, perfectly understandable, and its faster than push

      Faster?

      $ perl -le' use Benchmark qw/ cmpthese /; my @data = "a" .. "z"; cmpthese -4, { copy => sub { my @array; @array = ( @array, @data ) for 1 .. 10; r +eturn @array }, push => sub { my @array; push @array, @data for 1 .. 10; return @a +rray }, } ' Rate copy push copy 908/s -- -91% push 9660/s 964% --

      Can you prove it?