Match the values you want with a regex

#!perl use strict; my @tpr = qw( AC0001_F00001_S00011.tpr AC0001_F00002_S00012.tpr AC0001_F00003_S00013.tpr AC0002_F00001_S00021.tpr AC0002_F00002_S00022.tpr AC0002_F00003_S00023.tpr AC0003_F00001_S00031.tpr AC0003_F00002_S00032.tpr AC0003_F00003_S00033.tpr); foreach (@tpr) { if (/(\w{2})(\d{4})_F(\d{5})_S(\d{5})/){ my $id = "AC"; my $molec = $2; my $frame = $3; my $mdstep = $4; # molecule 1 to 2 and frame 1 to 2 if ( ($molec =~ /000[12]/) && ($frame =~ /0000[12]/) ){ print "$_\n"; } } } # end of loop through tpr files
poj

In reply to Re: foreach loop running too many times...? by poj
in thread foreach loop running too many times...? by fasoli

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.