Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Ignore a range of numbers ina List

by CountZero (Bishop)
on Jun 25, 2017 at 08:09 UTC ( #1193493=note: print w/replies, xml ) Need Help??

in reply to Re^2: Ignore a range of numbers ina List
in thread Ignore a range of numbers ina List

Building upon your very elegant solution, but changing it somewhat so it now adds to the valid output a sequence at the end that starts with a 6 but never gets ended by a 7.

use Modern::PBP::Perl; my $aref = [1, 6, 2, 2, 7, 1, 6, 99, 99, 7, 1, 2, 6, 9, 8, 6, 5]; my @copy; my @stack; (($_ == 6 .. $_ == 7) and push @stack, $_) or (push @copy, $_ and @sta +ck=()) for @$aref; push @copy, @stack; use Data::Dumper; print Dumper \@copy;


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^4: Ignore a range of numbers ina List
by AnomalousMonk (Archbishop) on Jun 25, 2017 at 09:22 UTC
    ... your ... solution ...

    Not mine (unfortunately), but tybalt89's here :)

    Give a man a fish:  <%-{-{-{-<

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2023-03-24 15:37 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.