At 4:55 PM +1000 2002-08-31, Ken Williams wrote:
>On Saturday, August 31, 2002, at 04:31 AM, Bruce Van Allen wrote:
>
>>  At 1:20 PM -0400 2002-08-30, Warren Pollans wrote:
>>>  Hi Folks,
>>>
>>>  This is not OSX-related, but I'm hoping that some OSXer could point me in

[snip]

>answer to your question, which is to de-reference a reference to the 
>constant (!!).

>>
>>  #!/usr/bin/perl -w
>>  use strict;
>>  use constant FS => '##';
>>
>>  my $x = 'sadfjsfh##fskdjfa;s##dfjhasfjh';
>>
>>  $x =~ s/${ \FS }/ZZ/g;  # or ${ \FS() }
>>  #       ^^ ^   ^
>>  print "1:$x\n";
>>
>>  __END__
>
>
>That's probably not the best solution.  The reason is that perl 
>can't compile your regular expression statically, because now 
>there's a variable in it, and perl will have to find this "constant" 
>value every time it searches through the target string.  This 
>negates the presumed performance benefits of using the constant.

>  my $rx = qr{##};  # or my $rx = qr{${\FS}}; if you want to use FS
>  $x =~ s/$rx/ZZ/g;
>  print "1:$x\n";

Yes, that's the way I'd do it. Warren explicitly didn't want to use 
another variable, such as your $rx.

1;
-- 

   - Bruce

__bruce_van_allen__santa_cruz_ca__

Reply via email to