Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Update to smartmatch

by perldigious (Priest)
on Dec 28, 2017 at 14:09 UTC ( #1206323=note: print w/replies, xml ) Need Help??


in reply to Re^2: Update to smartmatch
in thread Update to smartmatch

On rare occasions I've found it very convenient for debugging purposes, such as when I want to quickly compare two arrays.

If I recall correctly, last time I used it I was "cleaning up" some old code and I wanted a quick way to double check that the output array from the old code and the output array from the new code were exactly the same.

Just another Perl hooker - My clients appreciate that I keep my code clean but my comments dirty.

Replies are listed 'Best First'.
Re^4: Update to smartmatch
by 1nickt (Abbot) on Dec 28, 2017 at 16:03 UTC

    But why live with the warnings and the uncertainty about the function's future?

    perl -wE ' my @foo = (1, 2, 3); my @bar = (1, 2, 3); my @baz = (1, 2, 4); say "@foo" eq "@bar"; say "@foo" eq "@baz"; ' 1
    Or:
    perl -MTest::Deep::NoTest=eq_deeply -wE ' my @foo = (1, 2, 3); my @bar = (1, 2, 3); my @baz = (1, 2, 4); say eq_deeply \@foo, \@bar; say eq_deeply \@foo, \@baz; ' 1 0
    smartmatch:
    perl -wE ' my @foo = (1, 2, 3); my @bar = (1, 2, 3); my @baz = (1, 2, 4); say @foo ~~ @bar; say @foo ~~ @baz; ' Smartmatch is experimental at -e line 5. Smartmatch is experimental at -e line 6. 1

    The way forward always starts with a minimal test.

      I don't, that's why I only use it when I'm doing debugging/verification. I usually just comment out any such quick checks if not outright delete them in the end. It's mostly just a convenience for me to make sure data structures are the same before/after some code I change.

      In all honesty, I probably would have skipped learning about it had I known it was "experimental", but I went ahead and read through the chapter of Learning Perl that covered Smart Match and Given-When (also experimental) without knowing that, and only found out when I went to do the exercises at the end. I've never had a reason occur to me as to where I would use given-when, but I have found Smart Match occasionally useful for quick and dirty (i.e. lazy one line) debugging. :-)

      Just another Perl hooker - My clients appreciate that I keep my code clean but my comments dirty.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2019-10-19 22:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?