My [update: broken] entry:
(/^..$/...$_)||print for@Array # 30 chars, with named array
Caution: Contents may have been coded under pressure.
| [reply] [d/l] |
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'. | [reply] [d/l] |
Please, recheck your code - it is skipping more elements.
Another 31 chars:
print split' ..( \S+){3}',"@_"
| [reply] [d/l] |
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.
| [reply] [d/l] |
Problems:
- The array is called @Array, not @_.
- Modifying an array you're looping over isn't well defined.
- It will attempt to skip over 2 elements for all strings less than 3 characters, not just strings of exactly 2 characters.
| [reply] |
my @Array = ('AAA','BB','CCCC','DD','EEEEE','FFF','GGGG');
my @Skipped = split' ..( \S+){3}',"@Array";
print "@Skipped"
__END__
STDOUT: AAA EEEEE FFF GGGG
Right?
| [reply] [d/l] |
That would fail if the strings contain spaces.
| [reply] |