Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: A Case with 5 Var's

by GrandFather (Sage)
on Jan 25, 2007 at 21:56 UTC ( #596636=note: print w/replies, xml ) Need Help??

in reply to Re^2: A Case with 5 Var's
in thread A Case with 5 Var's

It depends a lot on where you want to go with this. One technique would be to use a hash to generate a dispatch table. Consider:

use strict; use warnings; my %dispatch = ( 0b000001 => \&noneTrue, 0b111110 => \&allTrue, 0b001101 => \&firstLine, ); my $name = ''; my $vorname = 'full'; my $plz = 1; my $tel = 0; my $tel49 = undef; while (<DATA>) { chomp; my ($name, $vorname, $plz, $tel, $tel49) = split ','; my $vector = (!$name) || 2; $vector |= (!$vorname) || 4; $vector |= (!$plz) || 8; $vector |= (!$tel) || 16; $vector |= (!$tel49) || 32; $dispatch{$vector}->($.) if exists $dispatch{$vector}; } sub noneTrue { print "None true in input line $_[0]\n"; } sub allTrue { print "All true in input line $_[0]\n"; } sub firstLine { print "Matched first line pattern at input line $_[0]\n"; } __DATA__ ,full,1,0, first,second,3,4, 1,2,3,4,5 ,,3,4, last,,,,


Matched first line pattern at input line 1 All true in input line 3 None true in input line 5

DWIM is Perl's answer to Gödel

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://596636]
[Your Mother]: :P
[ambrus]: YourMother: my brother told me their cat wants to climb into the dishwasher if they leave the door open. Not when the dishwasher is started, but after it's done washing, because it's still warm and cats like warm.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-12-18 15:30 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (491 votes). Check out past polls.