Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Perl has foibles like this, too:

      DB<1> @a = (1,2,3)
      DB<2> delete $a[1]
      DB<3> x \@a
    0  ARRAY(0x90a6d0)
       0  1
       1  empty slot
       2  3

    ..and PHP has exactly what you suggested.

    <? $x = array(1,2,3); array_splice($x, 1, 1); var_dump($x); ?>
    array(2) {

    Just because PHP is often intolerable doesn't mean that everything it does is wronger than Perl.

    • PHP removes the index, which is the problematic part. Your Perl example shows exactly what my Perl example shows, which is that Perl just puts the value on undef and keeps the index, so you can iterate without a problem. This is far from a foible and is the correct and best result. This is not a Perl "feature", Python and Ruby behave the exact same way. PHP is the different here, and it is indeed stupid.

      $ my @a = (1, 2, 3)
      $ARRAY1 = [