![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
Off by one key... or yet another example of why strict and warnings are always a good idea (even for "one-liners")by atcroft (Abbot) |
on Jul 18, 2019 at 00:02 UTC ( #11102960=perlmeditation: print w/replies, xml ) | Need Help?? |
"Just sit right back and you'll hear a tale Please, dear reader, learn from my mistake. (It will likely be less painful than repeating it yourself.) Earlier today I did something I have done dozens of times before-created a command-line perl script (a "one-liner", for some very long definition of a "line") to create a file containing a subset of messages from a set of compressed logs, with the intent of pulling them back to my machine for additional processing. I launched it in a screen session, saw it was running and would take some time to begin generating output, and stepped away for lunch. I was rather surprised, however, when I returned to find it throwing "No space left on device" messages-especially when I looked to find that the partition's previous 40GB of free space was now zero. After cleaning up the space, I began trying to find the cause. In digging through my code, I almost missed the issue-a line of the form if ( $str -~ m/some pattern/ ) { print $str; }. Notice the issue? An off-by-one-key error from a en.US keyboard, where [-/_] and [=/+] are beside one another. This was compounded by skipping the well-espoused logic of use strict; use warnings; because it was a "one-liner" (where "-Mstrict -Mwarnings" would have added a mere 19 characters in length). Had I have done so, instead of: I would have seen: Seeing unexpected output like that (that early) would likely have resulted in my cancelling the command to investigate, and thus likely not filling up 40GB of storage. I know this will probably be like the tone after the television broadcast day ended to a sleeping viewer, but maybe, just maybe, it will help someone. In the end, learning from others' mistakes is often less painful (but not necessarily as memorable). (And yes, I do use the the duo on most every script I write-just not always on "one-liners".)
Back to
Meditations
|
|