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

O Wise Monks, I seek your advice on the following: Can anyone explain why the following simple code works on my WinXP setup but not on the HPUX 11.00 release we have on our computer at work:
$filename="auditlog.txt"; open FILE,$filename; while (<FILE>) { print "$_"; }
Prints the file, easy enough right? That's what it does on XP. On the HPUX it simply drops back to the prompt nothing displayed. I've done variations on the filename, giving the full path even though the script and log file are in the same directory. Running perl -w only tells me that I'm using an unitialized variable on line 2 A perl -v gives me
This is perl, version 4.0 $RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $ Patch level: 36 Copyright (c) 1989, 1990, 1991, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 4.0 source +kit.
I think perhaps that there isn't a full install of Perl on the machine. Any ideas? stu

update: lol, yeah I already figured on the updating of Perl and just grabbed the update package a little while ago. When I tried testing the file open condition it would error out (not in a good way) if I used "or die", and the same results as mentioned below if I used "|| die" But even with older versions and what not, this should work, right? Very odd.
---
update #2: @davis: Huh, I ran the swlist and according to it, Perl's not even installed on the machine. The perl I'm using (I found by whereis) is in our /usr/contrib/bin

Interesting...I'll do the update (gotta clear it with the powers that be first) and see if that doesn't fix the prob.

Nothing like being a *NIX newbie.

Thanks!



update #3: alaka-zam! so it was requested, so shall it be done.

Replies are listed 'Best First'.
Re: Perl 101 Problem
by trammell (Priest) on Jan 24, 2005 at 15:03 UTC
    Wow--that version of Perl is over a decade old! You might want to upgrade to a more recent perl...

    Also, you should always check the return value of open():

    open(FILE,$filename) || die "Can't open '$filename': $!";
    That should work under Perl 4.
Re: Perl 101 Problem
by tinita (Parson) on Jan 24, 2005 at 15:03 UTC
    my first suggestion is:
    always check the return code of open():
    open FILE,$filename or die "Could not open '$filename': $!";

    and, of course, always

    use warnings; use strict;
    update: that should be -w in the shebang instead of use warnings for your version of perl...
    update2: minor typo
Re: Perl 101 Problem
by davis (Vicar) on Jan 24, 2005 at 15:15 UTC
    Yikes. To echo what others have said: "Upgrade your perl!" (HP-UX 11.00 (now out of date itself) shipped with perl 4.0). HP-UX 11.11 now ships with perl 5.8.x. HP themselves make a pre-packaged version of Perl available
    Hope this helps.
    Update: After your update: Are you sure that the more recent version of perl that you installed is the one being used. IIRC, HP's distribution installs to /opt/perl5/bin/perl. You should check yourself with something like swlist -l file perl | grep perl$, and then make sure that that copy of perl is in your PATH before the default OS installation.

    davis
    It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
Re: Perl 101 Problem
by holli (Abbot) on Jan 24, 2005 at 15:05 UTC
    4.0? I suggest upgrading your perl. There is nothing wrong with the code.
    however, what does it tell you when you open FILE,$filename or die $!?

    holli, regexed monk
Re: Perl 101 Problem
by dimar (Curate) on Jan 24, 2005 at 17:34 UTC

    Update #2 Thanks for your consideration!

    Update #1 Because otherwise makes it difficult to read, and someone who is not familiar with the history of this thread will have a difficult time jumping in mid-stream.

    ---

    Could you possibly consider re-editing your question so that the updates are in order, at the bottom, and the original question appears as it did originally?

    Why would you want to do that?

    Please see update #1

    Oh yeah, please see update #2 also.

Re: Perl 101 Problem
by punkish (Priest) on Jan 25, 2005 at 01:27 UTC
    did you check the line breaks? Line breaks on Windows are different from that on Unix, and are a frequent source of bugaboo for cross-platform developers.

    And, while at it, upgrade to the latest Perl wherever possible.

Re: Perl 101 Problem
by gmpassos (Priest) on Jan 24, 2005 at 22:44 UTC
    Wow! Perl 4! Perl4 is not Perl5! You really should upgrade.

    Graciliano M. P.
    "Creativity is the expression of liberty".