Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: solution wanted for break-on-spaces (w/specifics)

by perl-diddler (Chaplain)
on Oct 26, 2021 at 17:43 UTC ( [id://11138082]=note: print w/replies, xml ) Need Help??


in reply to Re: solution wanted for break-on-spaces (w/specifics)
in thread solution wanted for break-on-spaces (w/specifics)

re strict/warnings -- they were their and got deleted as I deleted chunks of template-prefix code...*oops*.

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.

prototypes -- avoid? only when I need to avoid them to make it work. Most of my prototypes are documentary -- in that I put them on Class-methods where they aren't used, with the expectation that the "this" ptr doesn't count.

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.

capture groups -- don't think there were any such that I didn't use. I use (?:...) if I don't use the result.

Avoid P? If I don't use it, who would? ;-)

As for being able to 'help' me -- I'm beyond help, but anyone who tried to write a regex seemed to have no problem giving me clues about things that worked or things to try.

  • Comment on Re^2: solution wanted for break-on-spaces (w/specifics)

Replies are listed 'Best First'.
Re^3: solution wanted for break-on-spaces (w/specifics)
by hippo (Bishop) on Oct 26, 2021 at 21:47 UTC
    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?

    Yes, 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.
    capture groups -- don't think there were any such that I didn't use. I use (?:...) if I don't use the result.

    Here is your subroutine txt:

    sub txt($) { local $_=shift; my (undef, undef,$txt)=m{^\s*(\d+)\s+(\d+),(.*)}; $txt; }

    It unnecessarily localizes $_ and discards 2 capture groups. Instead it could be written thus:

    sub txt { shift =~ /^\s*\d+\s+\d+,(.*)/; return $1; }

    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.


    🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138082]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-18 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found