On 6/11/09 Thu Jun 11, 2009 1:51 AM, "Michael Alipio" <daem0n...@yahoo.com> scribbled:
> > Hi, > > I have a program that computes the number of elapsed minutes and seconds. > > > if the outputs are: > > 2 minutes, and 8 seconds. > > How do I print those two values to look like "Elapsed time: 02:08" This is how I would do it (untested): my $text = '2 minutes, and 8 seconds'; if( $text =~ m{ (\d+) \s* minutes .* and \s* (\d+) \s* seconds }x ) { printf "Elapsed time: %02d:%02d\n"; }else{ print "Invalid format: $text\n", $1, $2; } Note that it is important to test whether the regular expression matches before using the capture variables $1 and $2. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/