Bowie Bailey wrote:

> [EMAIL PROTECTED] wrote:
> 
>>Er, aren't hash keys interpreted as strings, even if they contain
>>digits? 
> 
> Perl does not have a strict distinction between string and numeric
> data.  They are both considered scalars.  The difference comes in how
> you use the scalar value.
> 
> Try this:
> 
>     $a = "10";
>     $b = "2";

You can get around this by using fixed length numerics if you for example
want to intermix them with non-numeric strings and still have them sort:

        my $a = sprintf '%04u', 10;     # assuming 4 digits max
        my $b = sprintf '%04u', 2;

Then you can sort them using string compares and mix them in with your
other strings.  Let's not get into what happens when a string has alpha
and numerics in it (unless of course they're fixed in position - eg:
abcd0001).

A prime example of comparing numbers as strings would be dates.  If you
specify a date as YYYYMMDD (or DDMMYYYY), you can easily sort them with
a string compare and is a good way to store dates if binary epoch time
isn't an option.

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to