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

Hello All, thank you for your great site and allowing a minion such as myself to have access to the great Perl Masters.

I have a script I have been attempting to run on my shared web server running Perl 5.8.8.

This script checks out ok during error checks and runs just fine on my own pc via Strawberry Perl. This has also been excuted on a stand alone box running 5.4.4, again with no issues.

However when posting on my web servers, I continuously get the "Internal Server Error". A check of the error log reveals syntax errors on lines 30 and 35. This script has been tried on different servers from different hosts as well.

I am not a Perl guru, so I am looking for some assistance. I have been through numerous trouble shooters to attempt a solution, but have run out of options. This script was given to me by a friend that uses it as is. This script outputs a preformatted text file it you will.

I appreciate anybody's help they could give to enable this script to run properly on my webserver.I would like to learn Perl in the future, just haven't had the time.

#!/usr/bin/perl -w use LWP::Simple; @show = ( 'Mike Cox*', 'Willard Sharp', ); print "Content-type: text/plain\n\n"; print <<EOF; Refresh: 1 Threshold: 999 Title: Into The Meso SN Locations Font: 1, 14, 0, "Arial" IconFile: 1, 22, 22, 11, 11, "http://www.spotternetwork.org/icon/spott +ernet.png" IconFile: 2, 15, 25, 8, 25, "http://www.spotternetwork.org/icon/arrows +.png" IconFile: 6, 22, 22, 11, 11, "http://www.spotternetwork.org/icon/spott +ernet_new.png" EOF my $sn = get 'http://www.spotternetwork.org/feeds/gr.txt'; $x = length $sn; $sn = substr($sn, 343, $x-343); my @values = split('End:', $sn); foreach my $val (@values){ if($val =~ m/Text:\s15\,\s10\,\s1\,\s\"(.+)\"/g){ my $name = $1; if ($name ~~ @show){ print $val; print "End:\n" } } }

Replies are listed 'Best First'.
Re: Script Issues
by stevieb (Canon) on Apr 08, 2016 at 00:39 UTC

    Welcome to the Monastery, Iowachaser!

    First thing I notice, in your if() statement near the end of the script, you use ~~. That's the SmartMatch operator, and only became available in 5.10.1, so on 5.8.8, you'll get syntax errors.

    You can rephrase it like the following, so at least that part will work:

    if (grep {$name eq $_} @show){ ...; }
Re: Script Issues
by LanX (Saint) on Apr 08, 2016 at 01:48 UTC
    >  $name ~~ @show

    The smart match operator wasnt available in 5.8.

    Try using a hash lookup instead.

    And please use strict and warnings and indentation.

    >  This has also been excuted on a stand alone box running 5.4.4

    Very unlikely!

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re: Script Issues
by james28909 (Deacon) on Apr 08, 2016 at 00:41 UTC
    at the top of your script ALWAYS:
    use strict; use warnings;
      How would that help with this script?

        From the OP:

        I am not a Perl guru, so I am looking for some assistance. I have been through numerous trouble shooters ... This script was given to me ... I appreciate anybody's help ... I would like to learn Perl ...
        Iowachaser is a Perl tyro and needs to change a Perl script, perhaps radically. warnings are already enabled globally with the  -w switch (assuming the shebang line is being interpreted — a big assumption), but are better used in a smaller scope. Enabling strictures with strict will enforce a number of syntactic requirements that will make a novice's life much easier. Use of these two modules in the revised script (and future scripts) will enable Perl to give Iowachaser some assistance and help even when all the trouble shooters have gone home (or off-line).


        Give a man a fish:  <%-{-{-{-<

        It helps us, if the OP does at least some rudimentary checking by himself before posting.

        It helps him, because "clean" questions (this includes indentation) attract more and better support.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

        Global symbol "@show" requires explicit package name at H:\Users\James +\Dropbox\perl\scripts\header\New folder\lwp.pl line 5. Global symbol "$x" requires explicit package name at H:\Users\James\Dr +opbox\perl\scripts\header\New folder\lwp.pl line 22. Global symbol "$x" requires explicit package name at H:\Users\James\Dr +opbox\perl\scripts\header\New folder\lwp.pl line 23. Global symbol "@show" requires explicit package name at H:\Users\James +\Dropbox\perl\scripts\header\New folder\lwp.pl line 30.
        Those are all errors, which the script does run, it still has errors which can come back and bite you on the ass. The script runs fine for me though, just thought I would point out to always use strict and use warnings since he is a "beginner"
Re: Script Issues
by Iowachaser (Novice) on Apr 08, 2016 at 19:12 UTC

    First off, thanks for the welcome!

    Secondly -- I have run the script previously during my initial troubleshooting with the "strict" and "warnings" put in the code. I did put those back into the code and I understand their uses. Thanks for that suggestion.

    Next -- I did make the changes to the smart match lines as suggested with the script still not working correctly. I understand the changes due to the versions updates, etc.

    After reading the responses, I see now that the 5.4.4 version must have been told to me in error. ;-)

    The 3 web hosts I have access to are all running Perl 5.8.8. Ultimately, I think it would be helpful for me to locate a new web host with a more current version of Perl installed, so that I can a) get this script to run correctly, without doing a major overhaul, and b) be able to use more current versions of Perl scripts in the future if/when I decide to jump in the learn it in earnest.

    Thanks to all who have responded!

    Mike

      Hi Mike,

      Some webhosts have multiple versions of Perl installed; the perl at /usr/bin/perl is just the system perl. One place to look might be /usr/local/bin/, on one of my hosts I've got a bunch of different perls there (perl5.22.1, perl5.14.1, etc.). (Or another trick if you've got a bash shell, might work on others too: try typing "perl" and pressing tab twice, then use the which command to locate the binaries bash shows you.)

      If you're still having problems, feel free to post your code and error messages here, or input and expected vs. actual output. BTW, one thing that might help you get better error messages instead of "500 Internal Server Error" is if you put use CGI::Carp qw(fatalsToBrowser); at the top of your script.

      Regards,
      -- Hauke D

        Hauke, thanks for the additional help. The fatalstobrowser definitely helps in not having to refresh the error log continuously.

        I did attempt to look around for another Perl install, but didn't have any luck. It looks as if I'm stuck with 5.8.8 for the moment.

        Basically what I'm attempting to do, is copy information for an user (listed at the top of the code) from the main gr.txt file as listed in the code, and place it along with some other text in a pre-formatted output file. I've attached a copy of the output below, along with my updated script based on the suggestions made here.

        Updated Code:

        #!/usr/bin/perl -w use LWP::Simple; use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; @show = ( 'Mike Cox*', ); print <<EOF; Refresh: 1 Threshold: 999 Title: Into The Meso SN Locations Font: 1, 14, 0, "Arial" IconFile: 1, 22, 22, 11, 11, "http://www.spotternetwork.org/icon/spott +ernet.png" IconFile: 2, 15, 25, 8, 25, "http://www.spotternetwork.org/icon/arrows +.png" IconFile: 6, 22, 22, 11, 11, "http://www.spotternetwork.org/icon/spott +ernet_new.png" EOF my $sn = get 'http://www.spotternetwork.org/feeds/gr.txt'; $x = length $sn; $sn = substr($sn, 343, $x-343); my @values = split('End:', $sn); foreach my $val (@values){ if($val =~ m/Text:\s15\,\s10\,\s1\,\s\"(.+)\"/g){ my $name = $1; if (grep {$name eq $_} @show){ ...; }{ print $val; print "End:\n" } } }
        Sample output:
        Refresh: 1 Threshold: 999 Title: Into The Meso SN Locations Font: 1, 14, 0, "Arial" IconFile: 1, 22, 22, 11, 11, "http://www.spotternetwork.org/icon/spott +ernet.png" IconFile: 2, 15, 25, 8, 25, "http://www.spotternetwork.org/icon/arrows +.png" IconFile: 6, 22, 22, 11, 11, "http://www.spotternetwork.org/icon/spott +ernet_new.png" Object: 41.3149986,-93.1019974 Icon: 0,0,000,6,2,"Mike Cox*\n2016-04-09 01:22:27 UTC\nSTATIONARY\nEma +il: mike@iowachaser.com\nHam: 146.550 - K0SVR\nTwitter: https://twitt +er.com/IntoTheMeso\nWeb: www.intothemeso.com\nNote: Into The Meso Cha +se Team" Text: 15, 10, 1, "Mike Cox*" End: