On Tue, Jul 24, 2001 at 05:15:35PM -0500,
[EMAIL PROTECTED] wrote:
>
> I have an array ... @effort. I want to match the first instance
> of /AbC/ in @effort and push that element into a new array
> @newarray.
>
> Immediately after that, I want to match the first instance of
> /ZyX[andall13charactersfollowingZyX]{anddontmatchanymoreZyX}/
> in @effort and push that element into @newarray.
>
> Then I want to repeat the entire sequence and match the next
> instance of /AbC/ .. push that into @newarray ..
> and then match the next instance of
> /ZyX[andall13charactersfollowingZyX]{anddontmatchanymoreZyX}/
> and push that into @newarray ....
>
>
> And repeat entire sequence,
> repeat entire sequence,
> repeat entire sequence ........
You don't specify a few things in your problem description, such as when
this loop is supposed to stop, and what's supposed to happen if the element
-just after- an /AbC/ sequence is not your /ZyX/ sequence. It's also rather
confusing why you want to match ZyX, followed by thirteen characters,
followed by nothing more; do you want to pull out /ZyX.{13}/, or does the
string have to match /ZyX.{13}$/? Furthermore, you should probably ask
about your -actual- problem, rather than making up some odd sequences as
examples; we could possibly suggest a better solution.
Be that as it may, here's a push in one right direction, possibly.
my @newarray;
for (my $i = 0; $i < @effort; $i++) {
my $abc = $effort[$i ];
my $zyx = $effort[$i + 1];
if ( defined($abc) && $abc =~ /AbC/
&& defined($zyx) && $zyx =~ /ZyX.{13}$/
) {
push(@newarray, $abc, $zyx);
$i++; # Force a skip of the next element, we just used it.
}
}
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]