Frank <mailto:[EMAIL PROTECTED]> wrote:

: Thanks Octavian,   I do need analyze element by element.  but the
: problem for me is  like this
: 
: my @array = (
: ">blue"
: "sky"
: "skirt"
: "sea"
: ">white"
: "paper"
: "flower"
: ">red"
: "face"
: "flower"
: ">green"
: "grand"
: "tree"
: )
: 
: Say, I need get all elements after ">white" before ">red". Be
: notice, any new color begin with ">",  so, I think I can

    Frank, you don't need to know the indexes for that. You could
use a flag. A flag is a variable we set to true when a particular
condition becomes true. Then we can test its value to see if the
condition was true previously.

    In this case, we use $after_white, which will test as false
until we see '>white' or 'white'. We exit the loop when we see
'>red' or 'red'.


my @items = qw(
    >blue    sky        skirt    sea
    >white   paper      flower   >red
    face     flower     >green   grand   tree
);

my $after_white;
foreach my $item ( @items ) {

    if ( $after_white ) {
        last if $item =~ /^>?red$/;
        print "$item\n";
    }

    $after_white = 1 if $item =~ /^>?white$/;
}

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
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