Another way to do this is with "match global". In this case, we say essentially "give me the sequences of digits found". What separates the digit sequences (i.e. numbers) doesn't matter. non-digit stuff gets skipped. This is a case of specifying what we want instead of specifying and splitting upon what we don't want.
#!/volume/perl/bin/perl use warnings; use strict; use DateTime::Duration; my $time = "01:00:01.004"; my @output_list = $time =~ /(\d+)/g; print "@output_list\n"; # 01 00 01 004
Update: Also, often in Perl, it is advantageous to assign meaningful names to components of a split or match global. It is rare to see something like $output_list[3] in my Perl code because the reader has to know what the heck the value at index 3 means.
#!/volume/perl/bin/perl use warnings; use strict; use DateTime::Duration; my $time = "01:00:01.004"; my ($hour,$min,$sec,$ms) = $time =~ /(\d+)/g; print "hour=$hour\n", "minutes=$min\n", "seconds=$sec\n", "milliseconds=$ms\n"; __END__ hour=01 minutes=00 seconds=01 milliseconds=004
Update again:
another possibility if the intent is to "delete the milliseconds"
my $time = "01:00:01.004"; my ($no_ms) = $time =~ /([\d:]+)/; #any digit or colon print "no milliseconds = $no_ms\n"; no milliseconds = 01:00:01
There are many variations upon this theme. I think the above is more clear, but...
my $time = "01:00:01.004"; $time =~ s/\.\d+$//; #explictly delete the ending milli_seconds print "time stripped ms = $time\n"; #time stripped ms = 01:00:01

In reply to Re: Matching dot using regexp by Marshall
in thread Matching dot using regexp by Anonymous Monk

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.