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
In reply to Re: search and print in perl
by CountZero
in thread search and print in perl
by hellworld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |