[ale] PHP -> Perl

attriel attriel at d20boards.net
Mon Apr 21 09:05:15 EDT 2003


> <PHP CODE>
> while(!preg_match("/^(\d+)\s+(\S+)$/", $retstr, $matches))
> </PHP CODE>
>
> I have not been able to mimic this functionality in perl.  I have gotten
> as far as:
>
> <PERL CODE>
> while (not ($retstr =~ /^(\d+)\s+(\S+)\1\2$/g ))

try:
while ($retstr !~ /^(\d+)\s+(\S+)$/)

Not sure what the g does on match, i never use it there :o

the \1\2 makes it a different re

> {
>     #DO STUFF;
> }
> $matches[1] = $1;
> $matches[2] = $2;
> </PERL CODE>

Er, that'll work, after you run out of while, and it will set [1] and [2]
to be the previous set of matches (or [2] anyway. [1] might work).  Either
way, it probably isn't what you wanted to be doing.  Not being entirely
sure what you wanted, I'd guess it's more:

{
  my (@matches) = ($1, $2);
  # Do Stuff
}

Then @matches has $1 in [0] and $2 in [1] (or you can do = (0, $1, $2) to
get them in [1] and [2]), and the stuff will have $matches[x] to play
with, and it won't be all moving and stuff when you add the next while. 
If you want it outside, then:

my (@matches);
while (blah)
{
#  @matches = (0, $1, $2);
# or
#  push(@matches, $1, $2);
  # Do Stuff
}
depending on how many mayches you want to retain.

--attriel



_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list