On 8/1/07, Jeff Pang <[EMAIL PROTECTED]> wrote: > > > -----Original Message----- > >From: Jay Savage <[EMAIL PROTECTED]> > >Sent: Aug 2, 2007 5:29 AM > >To: Perl List <beginners@perl.org> > >Subject: Re: parsing a log file by date > > > >'2 == 2' is a Perl test for numeric equality, which has nothing to do > >with string comparisons. '1 = 1', on the other hand, is a statement of > >fact. > > > > I notice that in shell we can say '1 = 1' and this is true. > but in perl we can't say 1=1. > > $ perl -e 'print "true" if 1=1' > Can't modify constant item in scalar assignment at -e line 1, at EOF > Execution of -e aborted due to compilation errors. > > $ if [ 1 = 1 ];then echo "true";fi > true > > > OT: Why shell support this strange attribute?
I'm not sure this is the case in "the shell," meaning "in all shells. In bash, though, within the context of a [ test ] "==" is a synonym for "=". That means that in Bash, "=" is both an assignment operator and a test, depending on context. This is a holdover from sh, and a source of much confusion. Most people recommend using '==' for string equality tests and '=' for assignment. The other gotcha for Perl programmers scripting the shell is that '==' and '-eq' have precisely opposite meanings. '==' (or '=') tests string equality, and '-eq' tests numeric equality. HTH, --jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!