Apr 4, 2005 #1 nfaber Technical User Oct 22, 2001 446 US Hello all, How can I tell for sure if the variable I am operating on is a string or an integer? Can't 01 also be a string "01"?? Thanks I got a Biz Degree! How the h*ll did I get here?
Hello all, How can I tell for sure if the variable I am operating on is a string or an integer? Can't 01 also be a string "01"?? Thanks I got a Biz Degree! How the h*ll did I get here?
Apr 4, 2005 #2 PaulTEG Technical User Sep 26, 2002 4,469 IE Perl can determine the type of a variable depending on the operator and context 01 is technically 1 "01" is a string, but can be 1 in a numerical context $var eq 1 is wrong $var == 1 is right $var eq "01" is right $var == "01" is wrong I hope I got that right --Paul cigless ... Upvote 0 Downvote
Perl can determine the type of a variable depending on the operator and context 01 is technically 1 "01" is a string, but can be 1 in a numerical context $var eq 1 is wrong $var == 1 is right $var eq "01" is right $var == "01" is wrong I hope I got that right --Paul cigless ...
Apr 4, 2005 Thread starter #3 nfaber Technical User Oct 22, 2001 446 US Ok Paul...how about this one: Code: my $date = "03-20-2005"; my ($month,$day,$year) = split (/-/, $date); Is $month an integer or string? I got a Biz Degree! How the h*ll did I get here? Upvote 0 Downvote
Ok Paul...how about this one: Code: my $date = "03-20-2005"; my ($month,$day,$year) = split (/-/, $date); Is $month an integer or string? I got a Biz Degree! How the h*ll did I get here?
Apr 4, 2005 #4 varakal IS-IT--Management Mar 18, 2004 114 US String to my knowledge. In fact, a scalar. If you say Code: if ($month == 3) it will accept and is true as internal conversion will be done. Upvote 0 Downvote
String to my knowledge. In fact, a scalar. If you say Code: if ($month == 3) it will accept and is true as internal conversion will be done.
Apr 4, 2005 #5 sfi MIS Apr 5, 2001 34 if all the characters in the string are numeric use ==, else use eq. Upvote 0 Downvote
Apr 5, 2005 #6 PaulTEG Technical User Sep 26, 2002 4,469 IE Nick, in a word both --Paul cigless ... Upvote 0 Downvote
Apr 5, 2005 Thread starter #7 nfaber Technical User Oct 22, 2001 446 US A little confusion here I see. Paul, you say both, does that mena either eq or == will work? I got a Biz Degree! How the h*ll did I get here? Upvote 0 Downvote
A little confusion here I see. Paul, you say both, does that mena either eq or == will work? I got a Biz Degree! How the h*ll did I get here?
Apr 5, 2005 #8 audiopro Programmer Apr 1, 2004 3,165 GB Taking the value from a string will mean that the value of month is "03" but it also has a value of 3. It depends how you wish to use the result. Keith http://www.studiosoft.co.uk Upvote 0 Downvote
Taking the value from a string will mean that the value of month is "03" but it also has a value of 3. It depends how you wish to use the result. Keith http://www.studiosoft.co.uk
Apr 5, 2005 #9 MikeLacey MIS Nov 9, 1998 13,212 GB Paul's quite right, if you have a string containing '01' it can be interpreted by Perl in a couple of ways. As a string '01', so the test $var eq '01' will evaulate true. As a number 01 or 1, so the test $var == 1 will evaluate true. What won't work is this $var eq '1' or $var eq 1. Both of these compare $var to the string '1', which it won't match. Mike You cannot really appreciate Dilbert unless you've read it in the original Klingon. Want great answers to your Tek-Tips questions? Have a look at faq219-2884 Upvote 0 Downvote
Paul's quite right, if you have a string containing '01' it can be interpreted by Perl in a couple of ways. As a string '01', so the test $var eq '01' will evaulate true. As a number 01 or 1, so the test $var == 1 will evaluate true. What won't work is this $var eq '1' or $var eq 1. Both of these compare $var to the string '1', which it won't match. Mike You cannot really appreciate Dilbert unless you've read it in the original Klingon. Want great answers to your Tek-Tips questions? Have a look at faq219-2884