From:  "Eric Preece" <[EMAIL PROTECTED]>
> I am very new to perl. I am writing a script that is supposed to open
> an html file and do some various tasks then later on it should print
> out the html file. I am having problems with one portion of it. I
> distilled it down to this code snippet
> 
> ==========================================
> # test
> use strict;
> 
> my $file;
> my $HTML;
> 
> sub testOpen {
>  local (*FILE);               # filehandle
>  $file = $_[0] || die ("No file specified\n");

The "my $file " should be INSIDE the subroutine, not outside, 
change the line above to

        my $file = $_[0] || die ("No file specified\n");
or
        my $file = $_[0] or die ("No file specified\n");

>  open(FILE, "$file") || die("File could not be opened - $file\n");

No NEVER enclose variables in doublequotes by themselves. If 
you need to insert the contents of a variable inside some text, the 
you have to, but 
        "$variable"
is nonsense. (Yes, it seems to do the right thing. Now.)

>   while (<FILE>) {
>    $HTML .= $_;
>   }
>  close(FILE);
>  $HTML =~ s/\$(\w+)/${$1}/g;  
>  return $HTML;        
> }
> 
> print "Content-type: text/html\n\n";
> print &testOpen("test.htm");          # Prints the contents of this file

The & in front of subroutine calls is deprecated (should not be 
used).
 
> ============================================
> 
> My problem is this works great from the command prompt. But will not
> open the file if hit the script from a browser. I am not sure why it
> behaves differently in a browser - I suspect permissions but I have
> the directory set to write, execute.
> 
> I am using a win2k IIS box with the lastest version of ActivePerl.

Use full path. The current working directory is most probably NOT 
what you might think it is.

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
                                        --- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to