Mumia,

thanks for your work on answering my help request.  I really
appreciate it.  However, while your solution works perfectly in your
sample program, since I am new to perl, I am having trouble
understanding some of the techniques you used, and i am having trouble
integrating the solution that you came up with into my own program.

how do i get all of this inside my if statement?  I don't understand
why the second line works(I know its comparing the values for
greater/lesser, but not how in the world perl is interpreting it, if
i'm making any sense)

what are the ':'s doing?, and lastly, what is eg?

i know you spent too much time on this already, but i'd really
appreciate you clearing this up for me.  this stuff isn't in my perl
book. . .

########
  $str =~ s/(?:(\d+)-(\d+)|(\d+));?/
       $3 ? '' : ($2 > $1 ? '' : 'y')
       /eg;
   '' eq $str;
########


my program
######################
   foreach ($temp2 = <>) {

        $list1 = $temp2;

       if ($list1 =~ /regex/){

            print "yay\n";

        }else {print "boo\n";};
######################

Mumias solution:
##########################
our ($datastr, @F);
my @data = \('1-10;25;33;100-250', '1-10;25;33;x100-250',
   '1-10;25;33;100-250-90', '1-10;25;33-9-18;100-250',
   '1-10;25;33-18;100-250');

my @checkranges;

push @checkranges, sub {
   # F1: Okay
   my $str = shift;
   $str =~ s/(\d+-\d+|\d+);?//g;
   '' eq $str;
};

push @checkranges, sub {
   # F2: Buggy
   my $str = shift;
   $str =~ m/^((\d+-\d+|\d+);?)+$/g;
};

push @checkranges, sub {
   # F3: Okay
   my $str = shift;
   $str =~ m/^((\d+-\d+|\d+)(;|$))+$/g;
};

push @checkranges, sub {
   # F4: Okay, the best; it checks ranges.
   my $str = shift;
   $str =~ s/(?:(\d+)-(\d+)|(\d+));?/
       $3 ? '' : ($2 > $1 ? '' : 'y')
       /eg;
   '' eq $str;
};

my $truefalse = sub {
   shift() ? 'true' : 'false';
};


$~ = 'FUNFORMAT';
$datastr = \'STRING';
@F = qw(FUNC-1 FUNC-2 FUNC-3 FUNC-4);
write;

for $datastr (@data) {
   @F = ();
   push @F, $truefalse->($_->($$datastr)) for
(@checkranges);
   write;
}

format FUNFORMAT =
@<<<<<<<<<<<<<<<<<<<<<    @<<<<<<<<   @<<<<<<<<   @<<<<<<<<    @<<<<<<<
$$datastr,    $F[0],       $F[1],       $F[2],  $F[3]
.

__END__
Output:

STRING                    FUNC-1       FUNC-2       FUNC-3       FUNC-4
1-10;25;33;100-250        true         true         true         true
1-10;25;33;x100-250       false        false        false        false
1-10;25;33;100-250-90     false        true         false        false
1-10;25;33-9-18;100-25    false        false        false        false
1-10;25;33-18;100-250     true         true         true         false
################################

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to