I am glad you enjoyed it. Perl coding is fun. I do have a couple of suggestions

suggestion 1: use strict and warnings. These will alert you to dangerous coding practices. They are a great way to learn to write solid code.

#!/usr/bin/perl use strict; use warnings;

:-)

OK here is a version of your code tidied up a bit, compiling under strict and not throwing warnings

#!/usr/bin/perl use strict; use warnings; # switch one in for testing each case. # # my $statement = "File extraction sucessfully completed in 8s 180ms"; my $statement = "File extraction sucessfully completed in 3min 8s"; # my $statement = "File extraction sucessfully completed in too much t +ime"; my @values = split(/\s+/, $statement); # split on any number/sort of w +hitespace my @time; $time[0] = pop @values; $time[1] = pop @values; # or use and array slice # my @time = @values[-2,-1]; my $seconds = 0; for my $val (@time) { if ($val =~ s/min$//) { $seconds = $seconds + $val * 60; } elsif ($val =~ s/ms$//) { $seconds = $seconds + $val / 1000; } elsif ($val =~ s/s$//) { $seconds = $seconds + $val; } else { print "Warning, strange value in expected time field: $val\n"; exit; } } print "Total time taken: $seconds seconds \n"

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re^3: Convert time into seconds by Random_Walk
in thread Convert time into seconds by Lucifer

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.