I'm just starting with Perl, and have noticed a problem that my book can't
answer. It seems very basic.
Here is some info.
[localhost:~/Perl] tor% perl -v
This is perl, v5.6.0 built for darwin
[localhost:~/Perl] tor% cat test
this is line nr 1
this is line nr 2
etc..
...
this is the last line in the file
[localhost:~/Perl] tor% cat 23.pl
#!/usr/bin/perl
if(open(FILE1, "/Users/tor/Perl/test")) {
$line = <FILE1>;
print ("This is the contents of the file\n");
while($line ne " ") {
print ($line);
$line = <FILE1>;
}
}
[localhost:~/Perl] tor% perl 23.pl
This is the contents of the file
this is line nr 1
this is line nr 2
etc..
...
this is the last line in the file
<Here the while loops just hangs, and the program never ends without me
using ^C>
I simply can't figure out why it won't die, or end.
My understanding goes like this:
When the while-loop reaches the last line of the file test(it will be a null
string), the while-statement should become false because $line IS EQUAL to
the null string. This doesn't happen.
Does anyone have clue on why?
I also have another little quirk that the book doesn't cover.
I would like to write a more flexible program, so I want the user to input a
filename, and then open that file, and later on it the program use that
filename in a printed string.
If I use: if(open(FILE1, "/Users/tor/Perl/test")) { # The "reference" to
/Users/tor/Perl/test is FILE1
Then try something like:
print ("The contents of the file ", FILE1, " is:\n");
It doesn't print the filename(/Users/tor/Perl/test).
Some information/pointers on that would also be appreciated.
Best reguards
--
T.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]