Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Yet Annoying Problem

Status
Not open for further replies.

chitownclone

Programmer
Mar 30, 2004
22
0
0
US
A variable in my program is an AE Code ($aenum) that contains both numbers and letters, which are assigned via .dat file. Example $aenum is c15, c16, c17.

However, I can't get my if then to work and error when a newly input AE code is the same as an existing.

If ($aenum eq $aenum2) {
ERROR;
}

Use == works fine if its numeric, eq works fine if its all letters...but what do I have to do to make eq or == work when the variable contains both letters and numbers??

Thanks
 
eq should work for both, perl does not 'type' its variables so if you compare to numbers using 'eq' perl will do a string comparison and come out properly.

 
Hi chitownclone, are you making sure there's no trailing or leading whitspace either end of the strings you're comparing?

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Code:
sub trim {
    my @out= @_;
    for (@out) {
        s/^\s+//;
        s/\s+$//;
    }
    return wantarray ? @out : $out[0];
}
If you need a trim sub
--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top