in reply to A Case with 5 Var's

Of course, you don't need to use this incredible elsif :)

Just save your variables as values in a hash and use a simple grep:

#!usr/bin/perl my ($name, $vorname, $plz, $tel, $tel49); my %vars; while (<DATA>) { print; chomp; ($name, $vorname, $plz, $tel, $tel49) = split /\s*,\s*/, $_, -1; @vars{qw/name vorname plz tel tel49/} = ($name, $vorname, $plz, $t +el, $tel49); my @good = grep {$vars{$_}} keys %vars; printf " %s %s good\n", @good ? join ", ", @good : "No variables", @good == 1 ? "is" : "are"; } __DATA__ john, stuart, some_plz, 123456, 234557 john, stuart, some_plz, 123456, john, stuart, some_plz,, 234557 , stuart, , 123456, 234557 , , , , 234557 ,,,,
It prints:
john, stuart, some_plz, 123456, 234557 tel49, vorname, tel, plz, name are good john, stuart, some_plz, 123456, vorname, tel, plz, name are good john, stuart, some_plz,, 234557 tel49, vorname, plz, name are good , stuart, , 123456, 234557 tel49, vorname, tel are good , , , , 234557 tel49 is good ,,,, No variables are good

     s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print

Replies are listed 'Best First'.
Re^2: A Case with 5 Var's
by roboticus (Chancellor) on Jan 25, 2007 at 14:51 UTC
    If you don't actually care about the variable names, then a variation on leronim's example might do the trick:

    #!/usr/bin/perl -w use strict; use warnings; my @varNames = qw { name vorname plz tel tel49 }; my @vars; while (<DATA>) { print; chomp; (@vars) = split /\s*,\s*/; print "\t"; for my $var (@varNames) { print $var, ":", shift @vars ? "good " : "bad "; } print "\n\n"; } __DATA__ john, stuart, some_plz, 123456, 234557 john, stuart, some_plz, 123456, john, stuart, some_plz, 123456 john, stuart, some_plz,, 234557 , stuart, , 123456, 234557 ,,,123456, 234557 john,,some_plz,, 234557
    Which prints:

    john, stuart, some_plz, 123456, 234557 name:good vorname:good plz:good tel:good tel49:good john, stuart, some_plz, 123456, name:good vorname:good plz:good tel:good tel49:bad john, stuart, some_plz, 123456 name:good vorname:good plz:good tel:good tel49:bad john, stuart, some_plz,, 234557 name:good vorname:good plz:good tel:bad tel49:good , stuart, , 123456, 234557 name:bad vorname:good plz:bad tel:good tel49:good ,,,123456, 234557 name:bad vorname:bad plz:bad tel:good tel49:good john,,some_plz,, 234557 name:good vorname:bad plz:good tel:bad tel49:good
    --roboticus