[Melbourne-pm] Wierd CGI Error - different displays for different executers

Sam Brent sambrent at gmail.com
Sun Mar 26 18:45:48 PST 2006

Hi Paul,
Thanks so much for your help, I tried adding $round into the
start_html() so it prints the value of $round into the titlebar, but
it printed fine so i don't think it's an issue of path.

Also, since I'm not getting any "erorrs" per se, fatalsToBrowser
doesn't do anything :(

Thanks for trying though mate, I really appreciate it.


On 3/27/06, Paul Fenwick <pjf at perltraining.com.au> wrote:
> G'day Sam,
> Sam Brent wrote:
> > Has anyone ever had a CGI script that creates the right output when
> > run in a terminal but the incorrect ouput when run in a browser?
> I just glanced through your code, and my guess would be that when it is run from
> a browser it's using a different current working directory than when you're
> executing it from the command line.  As such, your code that opens and reads
> your file will fail.
> This is an easy theory to test.  Presently your code using the following line,
> which does not check to see if the file was opened successfully:
>         open ROUND,"<round"; $round=<ROUND>; chomp $round; close ROUND;
> Instead you may wish to try:
>         open(ROUND,"<round") or die "Cannot open round - $!";
>         $round=<ROUND>;
>         chomp $round;
>         close(ROUND);
> Or, if you want a solution with a more best-practice coding style using scalar
> filehandles and lexical variables:
>         open(my $round_fh, "<", "round") or die "Cannot open round - $!";
>         my $round = <$round_fh>;
>         chomp($round);
>         close($round_fh);
> The advantage here is that your program will die noisy if it cannot open the
> file it's after.  You can even add:
>         use CGI::Carp qw(fatalsToBrowser);
> to have those errors display to the browser, which may make debugging and
> development easier.
> All the very best,
>         Paul
> --
> Paul Fenwick <pjf at perltraining.com.au> | http://perltraining.com.au/
> Director of Training                   | Ph:  +61 3 9354 6001
> Perl Training Australia                | Fax: +61 3 9354 2681

Samuel James Brent
MSN: sammyleephd at hotmail.com
Mobile: 0419201806

More information about the Melbourne-pm mailing list