Think about Loose Coupling | |
PerlMonks |
Re^3: While loop not printing anything after using grepby haukex (Archbishop) |
on Dec 29, 2020 at 16:36 UTC ( [id://11125941]=note: print w/replies, xml ) | Need Help?? |
Else clause is alwayse executed, why (should only be executed if 'Friday' is not found in 'input.txt')? You haven't used the <> operator, as in grep {/Monday/} <$in_file>. if ($. == 1) { If you use seek, you need to reset $. as I showed. Empty block in the if statement; how can I avoid this? You can invert the condition in the if, as in if ( !( ... ) ) or if ( not ... ) (just be aware of Operator Precedence and Associativity). Perl also offers the equivalent unless (...) {...}, but IMHO sometimes if (not ... is still more readable than unless (.... As far as I understand it, in Perl you first need to create a new file with the desired output then rename that file to the original name. So in my case that would be with the rename function Yes, that is one way to do it - if you don't mind me plugging my own module, see File::Replace.
In Section
Seekers of Perl Wisdom
|
|