---------- Forwarded message ----------
From: Raj Barath <barat...@outlook.com<mailto:barat...@outlook.com>>
Date: Wed, Nov 25, 2015 at 1:16 PM
Subject: Re: regex problem?
To: Rick T <p...@reason.net<mailto:p...@reason.net>>


Hi Rick,

You can use split.

For example:
my ( $stud_surname, $stud_number ) = split ( /-/, $student_id );
You are splitting on the hyphen character.

-Raj

On Wed, Nov 25, 2015 at 1:09 PM, Rick T 
<p...@reason.net<mailto:p...@reason.net>> wrote:
The following code apparently is not doing what I wanted. My intention was to 
confirm that the general format of  $student_id was this: several uppercase 
letters followed by a hyphen followed by several digits. If not, it would 
trigger the die. Unfortunately it seems to always trigger the die. For example, 
if I let student_id = triplett-1, the script dies. I’m a beginner, so I often 
have trouble seeing the “obvious.” Any suggestions will be appreciated!

        if      ( $student_id =~
                        /
                                (\A[a-z]+)              # match and capture 
leading alphabetics
                                -                               # hyphen to 
separate surname from number
                                ([0-9]+\z)              # match and capture 
trailing digits
                        /xms                            # Perl Best Practices
                ) {
                        $student_surname = $1;
                        $student_number  = $2;
        }
        else {
                die "Bad general form for student_id: $student_id"
        };


--
To unsubscribe, e-mail: 
beginners-unsubscr...@perl.org<mailto:beginners-unsubscr...@perl.org>
For additional commands, e-mail: 
beginners-h...@perl.org<mailto:beginners-h...@perl.org>
http://learn.perl.org/




Reply via email to