Can I do it some how with regex?

As hippo has alluded, a regex approach would seem far from ideal. Howsoever, the following seems to work, but requires Perl version 5.10+ for the  (?(condition)yes-pattern|no-pattern) construct (which embeds the experimental  (?{ CODE }) feature; see Extended Patterns in perlre):

c:\@Work\Perl>perl -wMstrict -le "use 5.010; ;; use Test::More 'no_plan'; use Test::NoWarnings; ;; my @values = qw( 11673326 11673329 11673325 11673330 11673321 11673335 ); ;; my $sorted_str = join ' ', sort { $a <=> $b } @values; ;; sub next_higher { local our ($from) = @_; ;; return $1 if $sorted_str =~ m{ \b (\d+) \b (?(?{ $from >= $^N }) (*FAIL)) }xms; ;; return; } ;; is next_higher(11673326), 11673329; is next_higher(11673335), undef; is next_higher(11673321), 11673325; done_testing; " ok 1 ok 2 ok 3 1..3 ok 4 - no warnings 1..4
I leave further testing to you :)

(NB: From, I believe, Perl version 5.18 on, the
    local our ($from) = @_;
statement in the  next_higher() function can be replaced with a more familiar lexical
    my ($from) = @_;
statement and the regex will work properly; can't test this ATM.)

Update: When discussing Perl version dependency in the first paragraph, I should also have mentioned that  (*FAIL) was introduced with 5.10 (see Special Backtracking Control Verbs in perlre). However, the effect of  (*FAIL) is exactly duplicated by  (?!) in pre-5.10 regexen, so  (?(condition)yes-pattern|no-pattern) remains the critical problem.


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


In reply to Re: get next higher number by AnomalousMonk
in thread get next higher number by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.