Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Yet another approach (founded, in part, on moritz' point that the rule for dealing with decimals is UNspecified).

Given the OP, if the the spec is that trailing decimal digits should be truncated to integers (let us hope there's no hidden requirement for rounding :) ) then a two-part approach is also viable.

So, less elegantly but, IMO, very obvious in its tactics and using regular expressions similar to those proposed above, a TIMTOWTDI might look like this:

#!/usr/bin/perl use 5.014; #1004756 my @init_array = ("text text text 1 text", "1 text text text 2 text 3 ", "text 1 text text 2 text", "text text text 1 text 2 3.0", "1 2 3 4 5 6 7 8 9 10 11", "text text text text", ); my ($sub_select, $select, @selected); for $_(@init_array) { $_ =~ s/(.+)\.0\z/$1/; # Truncate trailing decimal numbers say "\t \$_: $_"; # debug ($select) = $_ =~ / .+? (?:(\d+)) (?:[\D]*) $ # EOL /x; push @selected, $select; } my $i = 0; for my $captured(@selected) { say "\t\t" . '#test_filtered' . "[$i]: " . '"' . $captured . '"'; $i++; } =head EXECUTION: C:\>perl $_: text text text 1 text $_: 1 text text text 2 text 3 $_: text 1 text text 2 text $_: text text text 1 text 2 3 $_: 1 2 3 4 5 6 7 8 9 10 11 $_: text text text text #test_filtered[0]: "1" #test_filtered[1]: "3" #test_filtered[2]: "2" #test_filtered[3]: "3" #test_filtered[4]: "11" #test_filtered[5]: "" =cut

In reply to Re: Array Filter and Lookahead by ww
in thread Array Filter and Lookahead by daugh016

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2017-08-19 22:41 GMT
    Find Nodes?
      Voting Booth?
      Who is your favorite scientist and why?

      Results (312 votes). Check out past polls.