in reply to Script Issues

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

Replies are listed 'Best First'.
Re^2: Script Issues
by haukex (Archbishop) on Apr 08, 2016 at 20:43 UTC

    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:

        Hi Mike,

        I don't have a copy of 5.8.8 at the moment to test on, but I did take a look at your code. Here's what I found so far:

        You're missing a my in front of the first mention of @show and $x, and you're missing an else between the if and its following block, assuming you didn't want just a bare {...} block after the if. I'd also very much recommend you indent your blocks, perltidy or a good IDE can help there.

        It looks like the regex for extracting the name works, it's just that at the moment there's no "Mike Cox" in the list. Assuming you want to print only the records that match the names in @show, then you've got your logic reversed: the print $val; print "End:\n"; needs to go in the if block, not the else block (it can also be written print $val, "End:\n";). Also, I notice you've got an asterisk in the string 'Mike Cox*', is that intentional? Is it supposed to be a regex, or do you want to match 'Mike Cox*' literally?

        When I make the above changes and add a name that's on the list to @show, the code works for me and the output looks like what you wanted. If you're still having problems, it would be very helpful if you could include the actual output your program is giving you (including error messages).

        Here's another small optimization: the declaration of @show can be changed to my %show = map {$_=>1} 'Mike Cox*', '...'; (i.e. turn it into a hash %show where the keys are the names and the values are just "1", or any other true value), and then you can replace if(grep {$name eq $_} @show) with a simple hash lookup if($show{$name}).

        Hope this helps,
        -- Hauke D

        Thanks for everyone's help!

        I was finally able to get the script to run successfully on my web server as well as learning a few things about Perl scripting.

        I will definitely be utilizing the resources on this sight to help learn Perl more in depth and to possibly help others in the future.

        Again, I appreciate everyone who chipped in to help me with my script and I'm grabbing the offering plate to show my gratitude.

        Until next time,

        Mike