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 fourfour2 on June 3, 2008, 12:50 pm
Please log in for more thread options
> 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.
>
> Frank
> --
> Dipl.-Inform. Frank Seitz;http://www.fseitz.de/
> Anwendungen f=FCr Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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";
}

This prints: potatoe is not in list
But it is.
I think it's b/c of the parenthesis in the string.

Any suggestions?

Thanks for all your answers.

Posted by Frank Seitz on June 3, 2008, 12:58 pm
Please log in for more thread options
fourfour2@gmail.com wrote:
>
> Any suggestions?

if (!grep("$potatoe eq $_", @listofpotatoes)) {
print "$potatoe is not in list\n";
}

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Posted by A. Sinan Unur on June 3, 2008, 1:01 pm
Please log in for more thread options
fourfour2@gmail.com wrote in news:bf124f95-a27d-43aa-8076-
11e9bb23bb9b@q27g2000prf.googlegroups.com:

> if (!grep(/^$potatoe$/, @listofpotatoes)) {
> print "$potatoe is not in list";

Could we please drop the Dan Quayle act?

http://en.wikipedia.org/wiki/Potatoe#Spelling

>> Frank
>> --
>> Dipl.-Inform. Frank Seitz;http://www.fseitz.de/
...

And please do *NOT* quote sigs.

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by J. Gleixner on June 3, 2008, 1:06 pm
Please log in for more thread options
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)";
[...]
> 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";
> }
>
> This prints: potatoe is not in list

Really? I don't see how it's possible that it printed 'potatoe' there
when the value is 'thisisapotatoe(one)'. Maybe it's a Dan Quayle bug.


> But it is.
> I think it's b/c of the parenthesis in the string.
>
> Any suggestions?

Ahhh.. You can always use a 'for' loop.

Posted by fourfour2 on June 3, 2008, 1:13 pm
Please log in for more thread options
wrote:
> fourfour2@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)";
> [...]
> > Since I got special characters in the string, =A0grep(EXPR,LIST) doesn't=

> > handle these.
>
> > if (!grep(/^$potatoe$/, @listofpotatoes)) {
> > =A0 print "$potatoe is not in list";
> > }
>
> > This prints: potatoe is not in list
>
> Really? =A0I don't see how it's possible that it printed 'potatoe' there
> when the value is 'thisisapotatoe(one)'. Maybe it's a Dan Quayle bug.

You're right. Sorry.

>
> > But it is.
> > I think it's b/c of the parenthesis in the string.
>
> > Any suggestions?
>
> Ahhh.. You can always use a 'for' loop.- Hide quoted text -

No. Don't want that.
Thanks.

> - Show quoted text -


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
Noob trying to understand simple Perl grep statement December 2, 2008, 12:16 pm
What does 'grep -M' do? April 14, 2007, 8:42 pm
Grep Help November 16, 2007, 12:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap