Nkuvu has asked for the wisdom of the Perl Monks concerning the following question:

I'm attempting to write a quick script for my Unix account at work, and I am running into some errors. It's an HPUX system running (gasp!) Perl 4.0 (Revision 4.0.1.8). I don't have any privileges to upgrade to Perl 5.x.

I started creating a script, and wondered if Getopt::Long was available. So I perl -wc'ed it. And it says that use may clash with a future reserved word, and use strict is a syntax error.

Here is the test script (after I tried to simplify it down to the base problem):

#!/usr/contrib/bin/perl # Note that this path to Perl was # verified using 'which perl' use strict; use Getopt::Long; print "Hello, HPUX.\n";

And this is the error message from perl -wc try.pl:

"use" may clash with future reserved word at try.pl line 3. syntax error in file try.pl at line 3, next 2 tokens "use strict" "use" may clash with future reserved word at try.pl line 4. try.pl had compilation errors.

The perldoc -f use reports that all is like it should be. Removal of the Getopt::Long module provides similar results, and this script was created using nano compiled for HPUX (so there isn't an issue with line endings). And just for giggles I checked the results before and after a chmod +x try.pl call, with no changes.

Pointers to web pages would be welcomed, as would ideas to try out. This isn't mission critical or anything, but it is slightly annoying. I don't know enough shell scripting to be able to write my script without Perl...

And of course, a swift kick would be appreciated if I am missing something glaringly obvious. :)

Replies are listed 'Best First'.
Re: Perl 4 errors (look)
by tye (Sage) on Feb 21, 2003 at 18:33 UTC

    If you have "perldoc" to run "perldoc -f use", then you have Perl v5 somewhere also (because Perl v4 did not have "perldoc" and Perl v4 did not have use).

    So look for other versions of Perl under different executable names (such as "perl5") or in different directories. "which perldoc" or "whereis perldoc" might be a good start.

                    - tye

      Beautiful. I didn't realize that perldoc was a perl5 object. And finding that binary pointed me to where the perl 5.005_2 binary lives. And somewhat obviously, I didn't realize that Perl 4 didn't have use. ;)

      Many thanks.

•Re: Perl 4 errors
by merlyn (Sage) on Feb 21, 2003 at 18:21 UTC
    Your seriously best bet is to install a Perl that was written within the past decade into your account. Set -Dprefix=$HOME during the configure, and all will be well.

    I can't believe anyone still runs Perl4. Sheesh.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thanks for the advice about the -Dprefix. I was a little uneasy about installing Perl, since I've never installed on the Unix side of things. I didn't want my sysadmin yelling at me for installing something that I shouldn't have. :) I will be installing a later version of Perl in a little bit, since 5.005_2 is still not quite what I am used to.

      The fact that Perl4 is on this system isn't too much of a surprise to me. The sysadmin didn't know what the chown command did, and about half the manpages are MIA. Which is, of course, why I didn't ask the sysadmin to install a decent version of Perl...

        psst.... between you and me (and anyone else reading this :P), I think you need to find a new computer to live on if possible. If the sysadmin doesn't have a clue about anything, then you're just plain in a bad spot. What if something goes wrong? I'm quite sure if he doesn't know about the 'chown' command that he wouldn't be able to repair the smallest bit of damage to the system. Perhaps this sysadmin does not know what 'shutdown' does either? Maybe he just unplugs the computer to turn it off :)


        If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.

Re: Perl 4 errors
by Ovid (Cardinal) on Feb 21, 2003 at 18:30 UTC

    I dunno if perldoc is available in Perl4 (I wish I had my pink camel handy), but that or "man perl" would be good places to start. Any documentation on your system will be, I suspect, more likely to conform to what you actually have.

    As for your immediate problem, you can forget out strict, but IIRC correctly, you can still use local. It's not great, but it's a way to at least restrict scope. Also, for options, you can use the -s switch.

    Interprets -xxx on the command line as a switch and sets the corresponding $xxx variable in the script.

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Perl 4 errors
by VSarkiss (Monsignor) on Feb 21, 2003 at 18:37 UTC

    I find it really odd that

    perldoc -f use reports that all is like it should be
    I could be wrong, but I thought use came in with Perl 5. I do know perldoc first appeared in 1995, which is about the same time as Perl 5.001.

    Are you sure you don't already have two versions of Perl installed? I haven't worked on HP-UX in a while, but it used to come with both Perl 5 and Perl 4. In the systems I was on, /usr/bin/perl was Perl 4, and /users/contrib/bin/perl was Perl 5. Try looking around your system awhile.

    Sorry if this is all so obvious that you've already tried it. If you have, then follow merlyn's advice above. ;-)

      No problem about obvious-ness. I suspected that I had missed something obvious.

      /usr/bin doesn't contain any perl binaries. /usr/contrib/bin contained the perl 4 binary, and (after following tye's advice) I was able to find that /opt/local/bin contains the perl 5 binaries. So all is good.