- Because
<TRY>
in list context consumes all the data in theTRY
filehandle, making subsequent calls to<TRY>
return empty. If you want to reuse the data in the filestream, either
a. save the stream to a variable
my @try = <TRY>;
if ( grep ..., @try ) {
...
}
if ( grep ..., @try ) {
...
}
b. reopen the file or seek
back to the beginning
open TRY, '<', $try_file
...
if (grep ..., <TRY>) {
...
}
close TRY;
open TRY, '<', $try_file
if (grep ..., <TRY>) {
...
}
open TRY, '<', $try_file
...
if (grep ..., <TRY>) {
...
}
seek TRY, 0, 0; # reset cursor position to start of file
if (grep ..., <TRY>) {
...
}