Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Wierd sub-routine argument values

Wierd sub-routine argument values

Wierd sub-routine argument values

It might just be the norm (and as yet I haven't encountered it in my perl travels ) but this seems strange to me and is also annoying. I am writing a sub-routine and want to check the 2 args I pass to it e.g.:


$param = 2;

sub check_params
        if ($_[0] gt "10")
                print "Perl thinks $_[0] is greater than 10\n";

And when this run I get the line:

<298-> ./paramtest.pl
Perl thinks 2 is greater than 10

What's going on?


RE: Wierd sub-routine argument values

What happens if you use the ">" operator to test the values?  What I think is happening is that perl is doing an ASCII comparison on the values, and in that case "2" will be greater than "10".

To illustrate this, create a file that contains values from 1 to 15 in ascending order.  Then run sort myfile.  See how it gets ordered as "1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9"?  That's what perl is doing, and so "2" is greater than "10".

Use the ">" operator and all should be OK.

0 1 - Just my two bits

RE: Wierd sub-routine argument values

It does indeed, if I'd been more with it I might even have guessed about the implicit ASCII conversion...

I hate wednesdays.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close