in reply to Re^3: Time to seconds
in thread Time to seconds

Hmm, I thought your code was idempotent: it would find the parts in any location of the string. So it should swollow the parts in the wrong order, or you can try the parts in any order. You delete out of the string each one you find, so anything left is stuff you didn't recognise and that causes an error, when you're done with everything you do know.

If it's not, get rid of the ^ and give it a spin.

—John

P.S. it's the to_string you want the correct order for, right? That wasn't part of the original problem, but that's not a problem:

@value_sorted_keys= sort { $x{a} <=> $x{b} } (keys %x);

Replies are listed 'Best First'.
Re^5: Time to seconds
by tadman (Prior) on Nov 16, 2001 at 22:27 UTC
    It is true that it would find them in any order, but that if there were duplicates, it would generate an error. I wasn't sure if there might be some circumstance where '3s2m' might be valid input. Hey, you never know!

    You need the correct order for the encoding only, yes, not the decoding. The only reason I made that function was for the sake of completeness, and to validate that my decodes were correct using the test harness.
    A definition of idempotent for the curious.