mikesname has asked for the wisdom of the Perl Monks concerning the following question:

Hello there, I'm pretty brand-new to perl (and programming, actually) and am banging my head repeated against the desk trying to solve the following problem. I'm trying to write a script that'll list sequences of files, like, say
blah.1-100.jpg, rubarb1-56.psd
etc etc. The method I'm using seems to work well, except for one thing - it can't distinguish between a padded sequence and an unpadded sequence, for example:
1.jpg, 2.jpg, 3.jpg .. 200.jpg
and
0001.jpg, 0002.jpg, 0003.jpg .. 0200.jpg
Is there any reasonably simple way I can get perl to evaluate 1 == 0001 as false?

Thanks, Mike

  • Comment on Distinguishing between padded and non-padded literal numbers...

Replies are listed 'Best First'.
Re: Distinguishing between padded and non-padded literal numbers...
by Roy Johnson (Monsignor) on Sep 29, 2005 at 20:35 UTC
    Use eq instead of ==.

    Caution: Contents may have been coded under pressure.
Re: Distinguishing between padded and non-padded literal numbers...
by revdiablo (Prior) on Sep 30, 2005 at 00:18 UTC

    Another approach might be checking length before doing a numeric comparison. Without seeing any code, though, it's kind of hard to know exactly what you're talking about. Maybe you could post something more specific and we might have some more concrete suggestions?

Re: Distinguishing between padded and non-padded literal numbers...
by MrNiceGuy (Initiate) on Oct 02, 2005 at 00:55 UTC
    Remember one thing:

    if ( '0001' eq '1' ) { print "they are equal\n"; } else { print "they aren't equal\n"; }

    will print "they aren't equal";