Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: 1 vs "1"

by dragonchild (Archbishop)
on Sep 12, 2001 at 19:11 UTC ( #111924=note: print w/replies, xml ) Need Help??


in reply to 1 vs "1"

It sounds like you're trying to do something in C, not Perl. If the string you're passing is an integer, then it's an integer, not a string!

I'm not trying to be dense, but that's the way Perl looks at things. If you want to pass integers in, but treat them as strings, the easiest way I can think of it to pass a second variable in that would tell you if this scalar is to be viewed as an integer or string.

Of course, I would personally write two functions, one for integers and one for strings. Then, you decide outside the function which to do. Right now, you've got a function doing two different things. Make each do one thing and one thing well.

You can tell this really easily if your function has the form:

sub foo { my ($a, $b, $c) = @_; if ($a == 1) { # Do something } else { # Do something else } }

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://111924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2022-08-18 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?