You are reading in the entire file, but are accessing it wrong. As others have pointed out, your program is a little mangled, but despite this, it is surprisingly close to working.
It may not have been explained why you were getting the first line of the file, but not the others. Here's the reason:
my $text = $text[$line];
Here, because of the way you have structured your loop,
$line contains a line from your file. This is then used to look up an entry in the
@text array, so it has to be converted to a number. Since your text file probably doesn't have any numbers, this is always 0, which is the "first" line of your file. If your file had numbers in it, you would get quite a different result. Also note that even though you delete the control characters, you just print the same old line unmodified, instead of your fixed variable.
Your whole program could probably be replaced with:
% perl -pi -e 'tr/\x0c-\x0d//d' /usr/spool/lpd/dom/dom.work
If you want to use it as a script, it has to be re-worked.
A few notes:
- Don't reference your subroutines with ampersand. Just use them with brackets. foo() and not &foo.
- Indent your code properly, it makes it way more readable.
- You don't need to select your filehandle, just print to it: print DOM_WORK "stuff"
- Try and declare your subroutines before you use them. This backwards programming can cause subtle problems with order-of-operations, usually related to using variables before they are fully defined.
- Don't forget to trap errors if you can't open