Terminology not withstanding, it's again the lexical scoping.
Basically, what you're doing wrong is by declaring the scalar test inside the
while block.
As long as the code is exiting within the while block, $test is still alive.
The code exits out of the while block and $test is no more.

Also- by having $text = <TEXT> , you're going to end up with just the last
line of the text.txt file.  You need to do concatenation (unless I'm mistaken
in your intent)...
Either way, try this-
<code>

my $test;       #by declaring $test here, it remains valid in this block- so when
                # you try accessing it further down it still exists.
 open(TEXT,"text.txt") or die ("error:  text.txt failed\n");
        while (<TEXT>) {
                $text .= <TEXT>;  #concatenate, rather then just assign
        }
close(TEXT) or die("error:  close text.txt failed\n");

print <<"EndOfHTML";

$text

EndOfHTML

</code>
~Harring

On Monday 01 July 2002 11:36, Kyle Babich wrote:
> Ok, thank you, but now I'm having another problem with this:
>
> open(TEXT,"text.txt") or die ("error:  text.txt failed\n");
>       while (<TEXT>) {
>               my $text = <TEXT>;
>       }
> close(TEXT) or die("error:  close text.txt failed\n");
>
> print <<"EndOfHTML";
>
> $text
>
> EndOfHTML
>
> It tells me $text requires explicit package name but I do give it 'my'
> so why is it still giving me that error?  And once that error is fixed
> will the document be put into $text and then print properly even after
> I closed text.txt?
>
> Thank you again.  I don't know what I would do without this list.  :)
>
> On 1 Jul 2002 15:36:19 -0000, "Felix Geerinckx"
>
> <[EMAIL PROTECTED]> said:
> > on Mon, 01 Jul 2002 15:22:00 GMT, [EMAIL PROTECTED] (Kyle Babich) wrote:
> > > open(text,"text.txt") or die ("error:  text.txt failed\n");
> > > [...]
> > > bash-2.05$ perl -Tcw index.pl
> > > Unquoted string "text" may clash with future reserved word at
> > > index.pl line 17.
> > > [..]
> > > How do I fix it?
> >
> > From perldoc perldiag:
> >
> >      Unquoted string ""%s"" may clash with future reserved word
> >            (W reserved) You used a bareword that might someday be
> >            claimed as a reserved word.  It's best to put such a
> >            word in quotes, or capitalize it somehow, or insert an
> >            underbar into it.  You might also declare it as a
> >            subroutine.
> > --
> > felix
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]


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

Reply via email to