in reply to Re: Build your array with push
in thread Build your array with push

That style of code is totally ugly and unusable. What if your original list of data erroneously switched two characters and you now have to swap the last and next-to-last character? This coding style is flawed in that aspect. You should use the following coding style instead:

push (@Hibbs_Daglish_Schwartz_Vroom, "" . chr(0b1010110) . chr(0b1110010) . chr(0b1101111) . chr(0b1101111) . chr(0b1101101) );

Actually I use this coding style when manipulating SQL SELECT statements:

SELECT monkey, bananas from my_table where 1 = 1 and flung_poo is null and size > 800 ;

Replies are listed 'Best First'.
Re^3: Build your array with push
by blazar (Canon) on Feb 06, 2006 at 08:11 UTC
    That style of code is totally ugly and unusable [...] You should use the following coding style instead:

    No, no, no! Yours is better than the previous alternatives but one may still get confused when swapping bits. And all those calls to chr, oh my! Now pack can do all this for cheap. Thus you should use the following coding style instead:

    push @Hibbs_Daglish_Schwartz_Vroom, pack qw/(B8)* 01010110 01110010 01101111 01101111 01101101 /;

    Except that one would almost certainly want to write a specialized sub to do this, should he later change his mind with respect to the order in which to store bits into chars, chars into strings and strings into the array:

    sub insert (\@@) { my $arr=shift; push @$arr, pack '(B8)*', @_; } # ... insert @Hibbs_Daglish_Schwartz_Vroom, qw/ 01010110 01110010 01101111 01101111 01101101 /;