David, if you don't mind, could you give an explanation of what you're doing here? I'm not sure if everyone is familiar with the method you're using to look ahead.
-----Original Message----- From: david [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 5:28 PM To: [EMAIL PROTECTED] Subject: Re: misunderstanding the /g modifier on REGEX M Z wrote: > hello all - > > I am trying to do the following to this data: > input: > X|Y||||Z||A > > desired output: > X|Y| | | |Z| |A > > simply replacing || with | | > whereever it may occur in the string. > > This bit of code doesn't seem to do all of the job. > > What is wrong with this code? > > while (<>) { > while($_ =~ /([|])([|])/g) { > $_ =~ s/([|])([|])/$1 $2/g; > print "$_"; > } > } > > The problems seems that my bit of code doesn't > completely catch "all" of the || occurences within a > given line. Please help!!! > try: #!/usr/bin/perl -w use strict; (my $string = 'X|Y||||Z||A') =~ s/\|(?=\|)/| /g; print "GET: $string\n"; print "EXPECTED: X|Y| | | |Z| |A\n"; __END__ prints: GET: X|Y| | | |Z| |A EXPECTED: X|Y| | | |Z| |A david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
