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

I have stumbled across a problem. I don't have any log files for my server, no real errors print to browser and my debugger shows nothing. Does anyone see any reason this isn't functioning?
#!/usr/bin/perl use CGI::Carp 'fatalsToBrowser'; use strict; use warnings; use CGI; my $query = CGI->new; print $query->header; ### next line has an error if (my $form{'method'} eq 'encode') { my @character_code = unpack("C*", "$form{'message'}"); print "@character_code"; } if ($form{'method'} eq 'decode') { my $characters = pack("C*", "$form{'message'}"); print "$characters"; }
Thanks "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us" sulfericacid

Replies are listed 'Best First'.
Re: encode/decoder
by BrowserUk (Patriarch) on Dec 31, 2002 at 13:33 UTC

    You cannot declare a member of a hash with my. Try removing the my in the if statement, the %form hash already exists, it is created by CGI.


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Re: encode/decoder
by simon.proctor (Vicar) on Dec 31, 2002 at 18:41 UTC
    you use $form but do not declare it or populate it anywhere. Perhaps you meant to do:
    my $form = $query->Vars;
    first?

    If you did, remember this from the CGI perldoc:

    When using this, the thing you must watch out for are multivalued CGI parameters.

    Because a hash cannot distinguish between scalar and list context, multivalued parameters will be returned as a packed string, separated by the ``\0'' (null) character.

    You must split this packed string in order to get at the individual values. This is the convention introduced long ago by Steve Brenner in his cgi-lib.pl module for Perl version 4

    Thats from the 'FETCHING THE PARAMETER LIST AS A HASH:' section.
Re: encode/decoder
by vek (Prior) on Dec 31, 2002 at 17:43 UTC
    newrisedesigns has a very good point regarding the lack of any log files. Are you running this program at home, at work, on a ISP's box? Are you using Apache?

    If you can, take a peek at /usr/local/apache/logs and let us know which files are in that directory. If you're running this on an ISP's box, check to see if you have a public_html dir (or something similar) in your home directory.

    One more thing, it's always good practice to remove fatalsToBrowser before placing this program into production for security reasons.

    -- vek --
Re: (nrd) encode/decoder, why no logs?
by newrisedesigns (Curate) on Dec 31, 2002 at 15:16 UTC

    The greater question is, "why don't you have any log files?"

    If your ISP doesn't give you access to them, I suggest you request it. Access to your logs would not only save you time, but also give you great insight about your readers.

    John J Reiser
    newrisedesigns.com

      Whilst that would be ideal, there ain't no reason for him not to keep logs himself (that's what I usually do anyway, at least during development)

      BEGIN { use CGI::Carp qw[ carpout ]; carpout(\*LOGGY) if open(LOGGY, '>>'.__FILE__.'.log'); }


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      ** The Third rule of perl club is a statement of fact: pod is sexy.