in reply to Re: Skipping Elements in an Array
in thread Skipping Elements in an Array

/.../&&print||splice@_,0,2for@_ #31 chars


Replies are listed 'Best First'.
Re^3: Skipping Elements in an Array
by Roy Johnson (Monsignor) on Apr 07, 2005 at 12:52 UTC
    My [update: broken] entry:
    (/^..$/...$_)||print for@Array # 30 chars, with named array

    Caution: Contents may have been coded under pressure.
      my @Array = ('AAA','BB','CCCC','DD','EEEEE','FFF','GGGG'); (/^..$/...$_)||print for@Array; __END__ AAAFFFGGGG
      But according to the OP, it should not exclude the 'EEEEE'. Your solution excludes the entry that has 2 characters, and the next one (or rather, until the next one that is true). The result of your program will change if you replace 'CCCC' with '0', or 'DD' with 'DDD'.
      Please, recheck your code - it is skipping more elements.

      Another 31 chars:
      print split' ..( \S+){3}',"@_"


        28, using the @_ instead of @Array (otherwise 32):
        ($.=/^..$/...2)||print for@_
        Save another char by changing ... to .., but you get a warning.

        Caution: Contents may have been coded under pressure.
Re^3: Skipping Elements in an Array
by Anonymous Monk on Apr 07, 2005 at 14:16 UTC
    Problems:
    1. The array is called @Array, not @_.
    2. Modifying an array you're looping over isn't well defined.
    3. It will attempt to skip over 2 elements for all strings less than 3 characters, not just strings of exactly 2 characters.
      my @Array = ('AAA','BB','CCCC','DD','EEEEE','FFF','GGGG'); my @Skipped = split' ..( \S+){3}',"@Array"; print "@Skipped" __END__ STDOUT: AAA EEEEE FFF GGGG Right?


        That would fail if the strings contain spaces.