Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Ignore a range of numbers ina List

by CountZero (Bishop)
on Jun 25, 2017 at 08:09 UTC ( [id://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;

CountZero

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2024-04-16 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found