Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl grep and Perl 4

0 views
Skip to first unread message

four...@gmail.com

unread,
Jun 3, 2008, 2:59:29 AM6/3/08
to
Greetings,

I'm using Perl 4 and have problems getting syntax error when using a
grep BLOCK LIST.

What I am trying to do is see if a string is in a list of strings, but
using grep BLOCK LIST.
Note, I have parenthesis in the string.

This works in Perl 5 but not Perl 4:

...
$string1="thisisstring(one)";
@stringlist=("thisisstring(one)", "thisisafunnystring");


if (( !grep { $potatoe eq $_ ) @listofpotatoes {
print "Not found in list....\n"
}


>syntax error,next 2 tokens :grep {"

Is grep BLOCK LIST not supported in Perl 4 ?

In Perl 4 how can I use perl grep to grep for strings like the above.
Is it possible, supported?
I want to use perl grep, nothing else.

Thanks!

four...@gmail.com

unread,
Jun 3, 2008, 3:02:46 AM6/3/08
to
On Jun 2, 11:59 pm, fourfo...@gmail.com wrote:
> Greetings,
>
> I'm using Perl 4 and have problems getting syntax error when using a
> grep BLOCK LIST.
>
> What I am trying to do is see if a string is in a list of strings, but
> using grep BLOCK LIST.
> Note, I have parenthesis in the string.
>
> This works in Perl 5 but not Perl 4:
>
> ...
> $string1="thisisstring(one)";
> @stringlist=("thisisstring(one)", "thisisafunnystring");

I mean
$potatoe="thisisstring(one)";
@listofpotatoes=("thisisstring(one)", "thisisafunnystring");

Gunnar Hjalmarsson

unread,
Jun 3, 2008, 3:39:05 AM6/3/08
to
four...@gmail.com wrote:
>> This works in Perl 5 but not Perl 4:
>>
>> ...
>> $string1="thisisstring(one)";
>> @stringlist=("thisisstring(one)", "thisisafunnystring");
>
> I mean
> $potatoe="thisisstring(one)";
> @listofpotatoes=("thisisstring(one)", "thisisafunnystring");
>
> if (( !grep { $potatoe eq $_ ) @listofpotatoes {
> print "Not found in list....\n"
>
> }
>> syntax error,next 2 tokens :grep {"

I don't believe you when you say that the above code works in Perl 5.
Please copy and paste the code you post; don't type it with multiple typos.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

four...@gmail.com

unread,
Jun 3, 2008, 3:52:51 AM6/3/08
to
On Jun 3, 12:39 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> Email:http://www.gunnar.cc/cgi-bin/contact.pl- Hide quoted text -
>
> - Show quoted text -


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

Frank Seitz

unread,
Jun 3, 2008, 3:59:28 AM6/3/08
to
four...@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.

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

Tad J McClellan

unread,
Jun 3, 2008, 7:55:27 AM6/3/08
to
four...@gmail.com <four...@gmail.com> wrote:


> I'm using Perl 4


Why?


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Randal L. Schwartz

unread,
Jun 3, 2008, 10:04:00 AM6/3/08
to four...@gmail.com
>>>>> "fourfour2" == fourfour2 <four...@gmail.com> writes:

fourfour2> I'm using Perl 4 and have problems

I think you can stop right there. Anything after that is redundant. :)

Are you still playing DOOM too? And using Netscape 1.0?

Perl5 was released FOURTEEN YEARS AGO. Heck, it's almost old enough
to drive. :)

Your first order of business is to climb into the new millenium, new century,
new decade.

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

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

A. Sinan Unur

unread,
Jun 3, 2008, 10:51:05 AM6/3/08
to
mer...@stonehenge.com (Randal L. Schwartz) wrote in
news:86bq2ih...@blue.stonehenge.com:

>>>>>> "fourfour2" == fourfour2 <four...@gmail.com> writes:
>
> fourfour2> I'm using Perl 4 and have problems
>
> I think you can stop right there. Anything after that is redundant.
> :)
>
> Are you still playing DOOM too?

Actually, I am. It is the only game action game where I am assured of some
success (given all the practice that went into it ;-)

Sinan
--
A. Sinan Unur <1u...@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

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

four...@gmail.com

unread,
Jun 3, 2008, 12:50:12 PM6/3/08
to
On Jun 3, 12:59 am, Frank Seitz <devnull4...@web.de> wrote:


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.

Frank Seitz

unread,
Jun 3, 2008, 12:58:22 PM6/3/08
to
four...@gmail.com wrote:
>
> Any suggestions?

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

A. Sinan Unur

unread,
Jun 3, 2008, 1:01:57 PM6/3/08
to
four...@gmail.com wrote in news:bf124f95-a27d-43aa-8076-
11e9bb...@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.

J. Gleixner

unread,
Jun 3, 2008, 1:06:24 PM6/3/08
to
four...@gmail.com wrote:
> On Jun 3, 12:59 am, Frank Seitz <devnull4...@web.de> 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.

four...@gmail.com

unread,
Jun 3, 2008, 1:13:17 PM6/3/08
to
On Jun 3, 10:06 am, "J. Gleixner" <glex_n...@qwest-spam-no.invalid>
wrote:

> four...@gmail.com wrote:
> > On Jun 3, 12:59 am, Frank Seitz <devnull4...@web.de> 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.

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.

Glenn Jackman

unread,
Jun 3, 2008, 1:23:18 PM6/3/08
to
At 2008-06-03 12:50PM, "four...@gmail.com" wrote:
> On Jun 3, 12:59 am, Frank Seitz <devnull4...@web.de> 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 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

Glenn Jackman

unread,
Jun 3, 2008, 1:25:11 PM6/3/08
to
At 2008-06-03 12:50PM, "four...@gmail.com" wrote:
> On Jun 3, 12:59 am, Frank Seitz <devnull4...@web.de> 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

four...@gmail.com

unread,
Jun 3, 2008, 1:33:33 PM6/3/08
to
On Jun 3, 10:25 am, Glenn Jackman <gle...@ncf.ca> wrote:
>    standard 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

Charlton Wilbur

unread,
Jun 3, 2008, 2:48:08 PM6/3/08
to
>>>>> "f" == fourfour2 <four...@gmail.com> writes:

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
cwi...@chromatico.net

Jürgen Exner

unread,
Jun 3, 2008, 4:55:20 PM6/3/08
to
four...@gmail.com wrote:
>Yep - this works when using Perl 5.
>Unfortunately not in Perl 4.035 though.

I think you correctly pinpointed the root cause of your problems.

jue

Hans Mulder

unread,
Jun 3, 2008, 6:17:09 PM6/3/08
to
Glenn Jackman wrote:
> At 2008-06-03 12:50PM, "four...@gmail.com" wrote:
>> I'm using Perl 4 and .....
[....]

>> print "Not found in list....\n"
>> }

That's not valid perl 4. In perl 4 you must write a ';' at the end
of each statement. In perl 5 it's optional for the last statement
in the block; not so in perl 4.

> see: perldoc -f quotemeta

Perl 4 did not have quotemeta (nor perldoc, for that matter).

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

Nor did it have \Q.

> or, since you're just testing for equality:
>
> print "in list" if grep($_ eq $potatoe, @listofpotatoes)
>
> (tested in perl 5.8.8)

Try:

$potatoe="thisisstring(one)";
@listofpotatoes=("thisisstring(one)", "thisisafunnystring");

$quayle = $potatoe;
$quayle =~ s/(\W)/\\$1/g;

if ( !grep(/$quayle/, @listofpotatoes)) {


print "Not found in list....\n";
}


(tested in perl 4.036)

The OP should try to find a 15 year old copy of the FAQ.
This s/(\W)/\\$1/g thing was discussed in the FAQ back then.

Hope this helps,

-- HansM

Randal L. Schwartz

unread,
Jun 4, 2008, 12:09:55 PM6/4/08
to
>>>>> "Charlton" == Charlton Wilbur <cwi...@chromatico.net> writes:

>>>>> "f" == fourfour2 <four...@gmail.com> writes:
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

--

Charlton Wilbur

unread,
Jun 4, 2008, 1:00:07 PM6/4/08
to
>>>>> "RLS" == Randal L Schwartz <mer...@stonehenge.com> writes:

>>>>> "Charlton" == Charlton Wilbur <cwi...@chromatico.net> writes:
>>>>> "f" == fourfour2 <four...@gmail.com> writes:

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.

szr

unread,
Jun 5, 2008, 12:54:50 PM6/5/08
to
Charlton Wilbur wrote:
>>>>>> "RLS" == Randal L Schwartz <mer...@stonehenge.com> writes:
>
>>>>>> "Charlton" == Charlton Wilbur <cwi...@chromatico.net> writes:
>>>>>> "f" == fourfour2 <four...@gmail.com> writes:
>
> 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?
>
>> 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. :)
>
> 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.

That's assuming that he wasn't stuck with a server that had only Perl 4
on it (and insufficient privileges to install a newer one.)

--
szr


Charlton Wilbur

unread,
Jun 5, 2008, 2:12:14 PM6/5/08
to
>>>>> "szr" == szr <sz...@szromanMO.comVE> writes:

>> 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.

szr> That's assuming that he wasn't stuck with a server that had
szr> only Perl 4 on it (and insufficient privileges to install a
szr> newer one.)

Right, which is a bizarre choice, verging on a pathology, on the part of
the host.

Perl 4 was superseded by Perl 5 a decade and a half ago.

szr

unread,
Jun 5, 2008, 9:58:07 PM6/5/08
to

True. My point is not everyone is has quite grasped the concept of being
up to date.

--
szr


Charlton Wilbur

unread,
Jun 8, 2008, 5:21:18 PM6/8/08
to
>>>>> "szr" == szr <sz...@szromanMO.comVE> writes:


szr> That's assuming that he wasn't stuck with a server that had
szr> only Perl 4 on it (and insufficient privileges to install a
szr> newer one.)

>> Right, which is a bizarre choice, verging on a pathology, on the
>> part of the host.

>> Perl 4 was superseded by Perl 5 a decade and a half ago.

szr> True. My point is not everyone is has quite grasped the concept
szr> of being up to date.

But there's a difference between not being up to date and taking active
steps to remain out of date, and using Perl 4 in 2008 counts as the
latter.

szr

unread,
Jun 9, 2008, 1:06:53 AM6/9/08
to

Well I can't really disagree there. Though I have seen several hosting
firms using some seriously out of date setups (believe it or not there
are some still running servers with php3, apache 1.1, on kernel 2.0 and
virtually no security patches, just pure lazyness), but I agree there
really is not valid reason for it.

--
szr


0 new messages