December 3rd, 2006, 07:32 PM
Perl open function
've just started doin Perl on my own...
I have a doubt.
the following program named openpage.pl is not working and shows the error below
syntax error at openpage.pl line 2, near "while<page>"
Execution of openpage.pl aborted due to compilation errors.
December 4th, 2006, 02:51 AM
The reason I made it capitalized is because that's a convention in perl. Otherwise, the parenthesis should make it work for you. It may have worked if you had put spaces between while and <page> also, not sure. Hope this helps.
open(PAGE, "text.txt") or die("could not open text.txt\n");
December 4th, 2006, 02:10 PM
There's a ton of ways to skin a cat in perl, here's another:
Another note on the open, input redirection is not needed if you are just reading a file, it is only needed if you are writing to it (> file). Also, don't forget to close the file once you are done.
open(PAGE, "text.txt") || die "Open text.txt failed ($!)\n";
my @lines = <PAGE>;
There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.
(Merovingian - Matrix Reloaded)
December 4th, 2006, 04:26 PM
Thanx for the response..
I'll try them and do let you know.
December 5th, 2006, 12:32 AM
Thanx a lot!
It worked very well..
Can i request a little more info on the writing and just opening files with the open function..
I also wanna know the conventions.
December 5th, 2006, 06:03 AM
should give you all the info you need, and for a book that should help pick up the perl Cookbook. Gives plenty of examples and should help you.