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!
I mean
$potatoe="thisisstring(one)";
@listofpotatoes=("thisisstring(one)", "thisisafunnystring");
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
#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
> I'm using Perl 4
Why?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
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
>>>>>> "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/
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.
if (!grep("$potatoe eq $_", @listofpotatoes)) {
print "$potatoe is not in list\n";
> 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.
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.
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.
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
see: perldoc -f quotemeta
Yep - this works when using Perl 5.
Unfortunately not in Perl 4.035 though.
Thanks
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
I think you correctly pinpointed the root cause of your problems.
jue
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
>>>>> "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" == 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.
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
>> 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.
True. My point is not everyone is has quite grasped the concept of being
up to date.
--
szr
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.
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