in reply to open() destroying my vars?

One issue that you should be aware of is that when opening a filehandle, you must use or die: $!. Also, if $basepath and $basename are different variables, there is some wierd stuff that goes on. I guess what is happening in that snippet is that Perl is being confused by you using 2 variables in that syntax and instance of using open. I walked over to another machine and threw together a little sumpthin' sumpthin' and the only thing that worked for me is catenating $basepath and $basename. So,

open HTML, ">$basepath/$basename.html";

Should be:

$foo = "$basepath"."$basename.html"; open HTML, ">foo" or die "Can't open $foo: $!";

Also make sure that if $basename is a HTML file, that the *value* of the variable has a suffix of '.html'.

redmist
redmist@users.sourceforge.net

Replies are listed 'Best First'.
RE: Re: open() destroying my vars?
by theorbtwo (Prior) on Jul 29, 2000 at 07:09 UTC

    Thank you muchly, the script works perfectly now.

    The lines in question now read:

    $filename = "$basepath/$basename.html"; open HTML, ">$filename" or die "Couldn't open $filename for output\n";

    However, I still don't know what's up with it not working in the first place. Do you know what the "wierd stuff" or the "confusion" is?

    It's nothing important; the script works and I should be able to give a bill to the customer tommorow, but I just don't like not knowning why my code didn't work.

RE: Re: open() destroying my vars?
by davorg (Chancellor) on Jul 30, 2000 at 15:48 UTC

    My advice would be that you should always check the return value from an open call, but that die is not always the most appropriate response to a failure.

    Don't get me wrong - I'm sure that in 95% of cases (at least) is is the best action, but there are definitely times where alternative courses of action (log the error and move on, perhaps) would be more appropriate.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
RE: Re: open() destroying my vars?
by theorbtwo (Prior) on Jul 30, 2000 at 02:35 UTC
    OK, I'm an idiot. I was looking at absolutly the wrong place. My code is perfect (fine, anyway), my datafile isn't. Specificly, it's missing data for the pictures I was acatualy looking at as test cases. They were at the top, so the debugging print appears to work fine -- the problem had scrolled off the top of the screen!
    Sorry guys, and thanks for the undeservied rep! <G>
    -- theorbtwo -- http://www.rtweb.net/theorb/