|
Posted by fourfour2 on June 3, 2008, 1:33 pm
Please log in for more thread options
> At 2008-06-03 12:50PM, "fourfo...@gmail.com" wrote:
>
>
>
>
>
> > > fourfo...@gmail.com wrote:
>
> > > >>>>syntax error,next 2 tokens :grep {"
> > > [...]
> > > > #this works in perl 5, not perl 4
> > > > $potatoe=3D"thisisapotatoe(one)";
> > > > @listofpotatoes=3D("thisisapotatoe(one)", "thisisanoldpottit");
>
> > > > if ( !grep { $potatoe eq $_ } @listofpotatoes) {
> > > > =A0 =A0print "Not found in list....\n";
> > > > }
>
> > > The error message says that the block syntax is not
> > > allowed in Perl 4. Use grep(EXPR,LIST) instead.
>
> > =A0Since I got special characters in the string, =A0grep(EXPR,LIST) does=
n't
> > =A0handle these.
>
> > =A0if (!grep(/^$potatoe$/, @listofpotatoes)) {
> > =A0 =A0print "$potatoe is not in list";
> > =A0}
>
> see: perldoc -f quotemeta
>
> =A0 =A0 print "in list" if grep(/^\Q$potatoe\E$/, @listofpotatoes);
>
> or, since you're just testing for equality:
>
> =A0 =A0 print "in list" if grep($_ eq $potatoe, @listofpotatoes)
>
> (tested in perl 5.8.8)
>
> --
> Glenn Jackman
> =A0 "If there is anything the nonconformist hates worse than a conformist,=
> =A0 =A0it's another nonconformist who doesn't conform to the prevailing
> =A0 =A0standard of nonconformity." -- Bill Vaughan- Hide quoted text -
>
> - Show quoted text -
Yep - this works when using Perl 5.
Unfortunately not in Perl 4.035 though.
Thanks
|