[Please do not top-post.  TIA]


David le Blanc wrote:

On Tue, 05 Oct 2004 04:03:21 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote:

Mallik wrote:

I have the below code.

my $a = ":-:m:-:a:-:l:-:i:-:k"; # Here each letter is separated by :-:
my $del = ':-:'; # Delimeter
my $b;

while ($a ne $b)
{
   $a =~ /^$b$del(.?)($del)?/;
   my $c = $1;
   print "$c\n";
   $b .= $del . $c;
}

The above code is working fine. But when I change the text in $a like below

$a = ":-:m:-:a:-:l:-::-:k";  # Here I removed the letter l between two '::'s

Now the code is not working properly.

Any help in this is appreciated.

Note: There may be non-alpha numeric chars between ':-:'.

Perhaps you need to use split and join:

$a = ':-:m:-:a:-:l:-::-:k';

my $del = ':-:'; # Delimeter

$b = join $del, split $del, $a, -1;

> Your use of (.?)($del)? does not do what you expect.  In the case of
> :-:a:-:   you will find (.?) = 'a' and ($del)? matches a delimiter, BUT
> :-::-:    you will find (.?) = ":" and ($del)? matches nothing.
>
> Check out 'look-ahead' matches for a way to solve this.

What do you mean?  I am not using (.?)($del)? in my example.


John -- use Perl; program fulfillment

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