Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Filling in missing values in an array

by Neighbour (Friar)
on Jun 29, 2011 at 14:32 UTC ( #911976=note: print w/replies, xml ) Need Help??


in reply to Re: Filling in missing values in an array
in thread Filling in missing values in an array

Very informative...this helps me get the hang of tests :)
Though I'm not quite sure how tests 3-5 are supposed to go. If I let the sub execute die "No values found" when that is the case, the app dies instead of showing testresults.

Replies are listed 'Best First'.
Re^3: Filling in missing values in an array
by FunkyMonk (Canon) on Jun 29, 2011 at 16:37 UTC
    Though I'm not quite sure how tests 3-5 are supposed to go
    Neither was I! So I made it die (a.k.a throws an exception) when the array consists only of NULLs. Garbage in, garbage out, as we used to say. Exceptions prevent the garbage leaking out.

    If you decide it should do something other than die, just change this line:

    die "No values found" if @arr && 0 == grep $_ ne '_', @arr;
      Yea, but when it dies, the tests are never executed (in my case). That's probably not what's supposed to happen :).
        If you don't want the code to die, you need to use something to catch the exception. I like Try::Tiny:
        use Try::Tiny; my @bad = try { fill_in_the_blanks(qw<_ _ _>) } # fails catch { print "bad data!\n" }; my @good = try { fill_in_the_blanks(qw<_ 1 _>) } # succeeds catch { print "bad data!\n" };
        Ah, found out where things went wrong:
        My code dies with a 'No values found' for is_deeply [fill_in_the_blanks(qw< >)], [qw< >], "( )";.
        I thought that throws_ok didn't catch the die but that wasn't the case.
        Seems our approach of the 'empty array'-situation differs :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://911976]
help
Chatterbox?
[1nickt]: Ah, I see. I did read some gamer mag reviews, and yes, they lamented the fact that laptops with no discrete video card are sold as "gaming" hardware.
[1nickt]: But, they do have red keyboard backlighting! And gargoyles on the front, or words like "Maxxx" here and there. They know their demographic!
[1nickt]: True gamers don;t buy Dells, HPs, or Lenovos, I think ;-)
[ambrus]: The keyboard I bought doesn't have backlighting. I specifically had to select for that, because so many keyboards these days have lights. Why would I want lights in the keyboard? I want lights in the room, such as on the ceiling, not in the keyboard.
choroba has a small USB lamp
[ww]: ++ all (phony labels re "gaming"
[1nickt]: ambrus perhaps you know where the keys are?
[ww]: OTOH, -- for ads suggesting that being good at games is somehow eq "greatness"

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2017-03-27 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.