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 @output_list = $time =~ /(\d+)/g; print "@output_list\n"; # 01 00 01 004
Update again:#!/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
There are many variations upon this theme. I think the above is more clear, but...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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |