Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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 1004756.pl $_: 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

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2014-10-23 02:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (123 votes), past polls