Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: solution wanted for break-on-spaces (w/specifics)by hippo (Bishop) |
on Oct 26, 2021 at 21:47 UTC ( [id://11138089]=note: print w/replies, xml ) | Need Help?? |
Test::More is what I use for testing not random development -- Test::More is a heavy-weight solution for testing a few example RE's against lines in a file. Test::More is in Core so everyone has it and everyone who writes any significant amount of Perl has used it and is familiar with it. The same is not true of your hand-rolled testing framework so when I look at your example code I have to first analyse your testing framework not least because it might be responsible for the underlying problem your code exhibits. If Test::More is too "heavy-weight" for you then you can always use the ultra-light Test::Simple instead. prototypes -- avoid? localising $_ -- I localise it if I change it's value in a sub -- I don't want to create side effects. In code cleanup I'll often replace them with "my $var"s. Here is your subroutine txt:
It unnecessarily localizes $_ and discards 2 capture groups. Instead it could be written thus:
No need to mess with $_ or declare any lexical variables at all. No need for 3 capture groups when all you want is one. No need for prototypes either. Of course you are entirely free to ignore these suggestions but the harder you make it for others to read or run your code the less likely they are to want to unpick it all. 🦛
In Section
Seekers of Perl Wisdom
|
|