[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] reg exp fun



Ronald, Chris,

Man, do I feel stupid. It was my inappropriate use of 'while (..) {....}' 
that was the culprit.

Thanks!


Scott


Ronald J. Kimball wrote...
>.*? at the beginning of a regex is generally unnecessary.  The regex engine
>already handles stepping through the target string until it finds a match.
>
>.*? at the end of a regex will never, ever match anything.
>
>A straightforward regex:
>
>/\$(\w+)->?/

Interesting, because that's one of the first ones I used, and it didn't 
work and still doesn't in this case. Seems reasonable since (quoting from 
Perl5 pocket ref.) "Each Charater matches itself, unless it is one of the 
special characters +?.*^$()[]{}|\ ...".

On a related note, I had originally used

/\$(\w+)/

to find scalars, and found that it was not matching in every case. So I 
tried

/.*?\$(\w+).*?/

and in every test found them all, which makes no sense to me since I see 
no difference between the minimum of zero or more occurances(zero) of 
something, and nothing at all.

on 3/7/99 5:18 AM, Chris Sansom wrote...
>Scott, I think the problem is the fact that you have both types of quote in
>this string.

Yes, but in actual use it is parsing a script and $q is a line from 
'while (<SCRIPT>) {...' . The script opens the target script(itself) just 
like any other file reading one line at a time. Is there any reason that 
it wouldn't be parsed just like any other text file?


Scott


>At 22:55 -0500 6/3/99, Scott Prince spoke thusly:
>>I'm playing with a sub routine to parse a script and gather a list of
>>variables, but there's one I can't seem to get a handle on.
>>
>># $q, is the string, in this case...
>>#
>># "#$hashref->{'hjkjg'} = "isahashreftoo";3sdfgdkjldskjd sdjkdfsklj"
>>
>>while ($q =~ /.*?\$(\w+)-.*?/)
>>{
>>$xref = $1;
>>$q =~ s/\$$xref//;
>>  if ((!(defined($hashes{$xref}))) && ($xref !~ /arrays|hashes|scalars/))
>>  {
>>  $hashes{$xref} = 1;
>>  }
>>}
>>
>>I just want to match '$hashref-' or '$hashref->'. I'm pretty sure that
>>the problem is the '-'. Any ideas?


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org