Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Manipulating Array Indexes

by tybalt89 (Monsignor)
on Sep 08, 2020 at 02:00 UTC ( [id://11121475]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Manipulating Array Indexes
in thread Manipulating Array Indexes

A) There was no test case for that indicating it is not possible for his data set.
B) This is one thing I really like about perl - it's easily fixed with just two words and a comma :)

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11121442 use warnings; my @data = qw( 5 ); my $target = 5; my @answers = grep defined, map { $data[$_] == $target ? @data[$_ + 1 +.. $_ + 3] : () } 0 .. $#data; print "@answers\n";

Replies are listed 'Best First'.
Re^4: Manipulating Array Indexes
by GrandFather (Saint) on Sep 08, 2020 at 02:30 UTC

    While I agree with B, I think A is rather a stretch. More importantly, good pedagogy suggests showing how to deal with edge cases is an important element of example code. Golf or obfuscation on the other hand tend to be an impediment to teaching concepts. Slices are important enough to be shown free of clutter.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121475]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found