Click here to get back home

Perl grep and Perl 4

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Perl grep and Perl 4 fourfour2 06-03-2008
Get Chitika Premium
Posted by Glenn Jackman on June 3, 2008, 1:25 pm
Please log in for more thread options
At 2008-06-03 12:50PM, "fourfour2@gmail.com" wrote:
> > fourfo...@gmail.com wrote:
> >
> > >>>>syntax error,next 2 tokens :grep {"
> > [...]
> > > #this works in perl 5, not perl 4
> > > $potatoe="thisisapotatoe(one)";
> > > @listofpotatoes=("thisisapotatoe(one)", "thisisanoldpottit");
> >
> > > if ( !grep { $potatoe eq $_ } @listofpotatoes) {
> > >    print "Not found in list....\n";
> > > }
> >
> > The error message says that the block syntax is not
> > allowed in Perl 4. Use grep(EXPR,LIST) instead.
>
> Since I got special characters in the string, grep(EXPR,LIST) doesn't
> handle these.
>
> if (!grep(/^$potatoe$/, @listofpotatoes)) {
> print "$potatoe is not in list";
> }

see: perldoc -f quotemeta

print "in list" if grep(/^\Q$potatoe\E$/, @listofpotatoes);

or, since you're just testing for equality:

print "in list" if grep($_ eq $potatoe, @listofpotatoes)

(tested in perl 5.8.8)

--
Glenn Jackman
"If there is anything the nonconformist hates worse than a conformist,
it's another nonconformist who doesn't conform to the prevailing
standard of nonconformity." -- Bill Vaughan

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

Posted by Charlton Wilbur on June 3, 2008, 2:48 pm
Please log in for more thread options

f> Yep - this works when using Perl 5. Unfortunately not in Perl
f> 4.035 though.

Why are you using Perl 4? Why are you using a version of Perl 4 that
isn't the latest version?

What's next, writing web pages to conform with Mosaic's view of HTML,
and complaining that there's no version of Emacs for System 7?

Charlton


--
Charlton Wilbur
cwilbur@chromatico.net

Posted by Randal L. Schwartz on June 4, 2008, 12:09 pm
Please log in for more thread options

f> Yep - this works when using Perl 5. Unfortunately not in Perl
f> 4.035 though.

Charlton> Why are you using Perl 4? Why are you using a version of Perl 4 that
Charlton> isn't the latest version?

The difference between 4.035 and 4.036 was a very trivial patch, although
I think it was a security patch. I'm not good at recalling things
from a decade ago, though. :)

print "Just another Perl hacker,"; # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Posted by Charlton Wilbur on June 4, 2008, 1:00 pm
Please log in for more thread options


f> Yep - this works when using Perl 5. Unfortunately not in Perl
f> 4.035 though.

Charlton> Why are you using Perl 4? Why are you using a version of
Charlton> Perl 4 that isn't the latest version?

RLS> The difference between 4.035 and 4.036 was a very trivial
RLS> patch, although I think it was a security patch. I'm not good
RLS> at recalling things from a decade ago, though. :)

Oh, right, but there's something pathological here - using Perl 4
instead of Perl 5, and then, in this day and age, where you have to go
through extra effort to get Perl 4 in the first place, not using the
latest version, trivial patch or no.

Charlton



--
Charlton Wilbur
cwilbur@chromatico.net

Similar ThreadsPosted
using grep in Perl November 10, 2006, 3:50 am
(Perl) FILE/IO and grep causes 100% CPU November 25, 2004, 4:27 am
perl grep problem May 25, 2005, 8:01 am
Want to use equivalent of grep function in perl November 9, 2005, 5:31 pm
system calls (mv + grep) within Perl script January 6, 2006, 3:19 pm
Linux find and grep to pure Perl August 3, 2006, 7:58 pm
problem running grep within system command in perl March 19, 2006, 12:53 pm
What does 'grep -M' do? April 14, 2007, 8:42 pm
Grep Help November 16, 2007, 12:56 am
Grep -v option November 4, 2004, 3:05 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap