[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl to Unix Perl Gotcha :-)



not really specific to MacPerl or even perl, but my last posting was very
definitiely about MacPerl and unfortunately didn't generate any responses.
Maybe Matthias is the only one who knows enough about batch etc modes, but
I certainly don't expect him to answer.


mark@cheers.jsc.nasa.gov (Mark Manning/Metrica) writes
>Well - these programs also generated HTML code and sent
>that back to the server.  BUT!  There's one thing I had
>completely overlooked!  :-)  The SYSTEM command - sometimes
>- returns a status.  In this case, it sometimes would
>return "No Mail" if the $userName variable did not contain
>anything.  This (of course) caused all of the HTML pages to
>return an error since the first line returning to the web
>server wasn't a "Content-type:" command.
>
>So what's the morale of the story?  Hell - I don't know.
>I'm just trying to show where an error can occur in a
>program when you move from one OS to another.  Make up your
>own morale!  ;-)

if I'm understanding it properly, this story is a very old and
unfortunately familiar one: not checking the return status of
system/library calls. The moral is similarly old and familiar:
check all return values. Once you get in the practice it adds very
little to coding time, but pays off big in situations like this.
I also find that the habit of thinking about possible error
returns does prevent me from writing some buggy code. Of course
I still find plenty of other places to add bugs 8-(

People should always run under "perl -w" and "use strict".
The "- w" will notify you when undefined values get used. This will
catch many cases when you're using bad return values, but not this
sort of case when the system call is executed just for effect.

sub prototypes and strict also help me a lot in passing hashes
and other non-scalar values as parameters. I don't have a real
intuitive feel for this and often need to cast parameter values
(passed as scalar refs) into the appropriate type.

cheers,
Danny Thomas  <D.Thomas@vthrc.uq.edu.au>