in reply to search and print in perl
Next, don't use global variables if you can avoid it. Lexical variables (those that start with "my" are the way forward.
The open operator is best used with lexical variables and with 3 arguments:
(BTW: the text input.txt does not need to be interpolated, so put it in single quotes.my $filename = 'input.txt'; open (my $IN, '<', $filename) or die "Can't open file $filename : $! " +;
Now you have to start reading in the contents of the file and much will depend on the format of your input.txt-file and I'm not sure that it is a good idea to concatenate the whole file into one scalar while still keeping the "End-Of-Line" characters. Perhaps you can show us a small excerpt of your input.txt-file? If you do that we can continue helping you.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search and print in perl
by CountZero (Bishop) on Jun 01, 2009 at 12:05 UTC | |
by hellworld (Novice) on Jun 01, 2009 at 12:09 UTC | |
by CountZero (Bishop) on Jun 01, 2009 at 12:31 UTC | |
|
Re^2: search and print in perl
by hellworld (Novice) on Jun 01, 2009 at 11:58 UTC | |
by almut (Canon) on Jun 01, 2009 at 12:09 UTC | |
by citromatik (Curate) on Jun 01, 2009 at 12:11 UTC |