Kevin Pfeiffer wrote:

>
> This is my "only slightly fancier" version - still uses DATA though;
> (critique/advice always welcome):
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> # zero_or_more
>
> my $valid_chars = get_valid_chars();
> my $regex = qr{^[$valid_chars]*$};

These might be a little better declared with our, since our communicates the
intent to use them throughout the inner scope.  Using our, you can redeclare the
variable within each scope used, and thus eliminate the
"wherethehelldidTHATcomefrom?!" phenomenon.

> while (<DATA>) {
>    # this really does an "exclude all other possibilities" match
>    # (zero or more of valid characters)
>    # but I skip empty lines
>    next if /^$/;
>    chomp;
>    print check_line($., $_);
> }
>
> ## end main ##
> ## beg subs ##
>
> sub get_valid_chars {
>    print "Enter valid characters (i.e. \"ABCD\"): ";
>    chomp (my $input = <STDIN>);
>    return $input;
> }
>
> sub check_line {
>    my ($ln_nbr, $line) = @_;
>    my $result = "Line #" . $ln_nbr . ": " . $line;
>    $result .= " Pass!" if ( $line =~ $regex );
>    $result .= "\n";
>    return $result;
> }
>
> __DATA__
> GACTNGACT
> GACCCCCCC
>
> GGAACCNNG

Thanks.  I really appreciate seeing the good use of subroutine calls here, the
greater applicibility you get by taking the character list from input, and the
escellent use of indentation.  They all set good examples for others.

Re the use of <DATA>:  yu probably could get around the need for this by having
a second parameter for the filename of a file containing the strings to check.

> -K (only 379 messages behind)

Pretty good.  At this point, my folder for this list indicates 453 unread.
Sunshine sure plays hell with techie dedication, huh?

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to