--- "Nguyen, Andy" <[EMAIL PROTECTED]> wrote:
> Hi List,
> 
> I am new to perl and looking for a shortcut way of doing this.
> 
> # $letter could be any letter from A to L.
> if ( $letter eq "A" || $letter "B" || $letter "C" || $letter eq "D" ............ || 
>$letter eq
> "L" )
> {
>   do something
> }
> 
> I really don't want to repeat $letter for every letter (B-L).

One way:

    if ( $letter =~ /^[A-L]$/ ) {
        # do something
    }

In the regular expression, [] defines a character class and A-L tells the regex that 
we're trying
to match a character that is in the range A through L.  I put the ^ and $ anchors on 
the beginning
and end of the regex to ensure that we only have one character.  ^ at the beginning of 
a regex
matches the beginning of the line and $ at the end of a regex matches the end.  Thus, 
the regex
reads:

    match the beginning of the string, find one 
    character from A to L inclusize and match the 
    end of the string

See 'perldoc perlre' for more info.

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

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

Reply via email to