Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • sub EffectiveVote ( Str $vote, Hash %skip ) {
        return $vote.split( ',' ).first( { ! %skip{$_}.defined } );
        die "No valid vote?!";
    }

    • Okay, that's definitely a big improvement over mine, and quite elegant. However, I'm wondering about return versus die here. (And my wondering is more complicated because I cannot find documentation for .first anywhere.)

      If no valid vote is found, won't the first line return undefined rather than not return?

      • Argh, yes. Good point.

        • Would

          sub EffectiveVote ( Str $vote, Hash %skip ) {
              return $vote.split( ',' ).first( { ! %skip{$_}.defined } )
                  err die "No valid vote?!";
          }

          do it, in theory? (In practice, I haven't gotten err die to work for me yet.)

          • Hey,

            sub EffectiveVote ( Str $vote, Hash %skip ) {
                return $vote.split( ',' ).first( { ! %skip{$_}.defined } )
                    // die "No valid vote?!";
            }

            actually compiled and it works! (I tested created a second votes file to make sure that it properly caught the condition, and it does.)