Hi,

On Wed, Feb 22, 2012 at 3:43 AM, John W. Krahn <jwkr...@shaw.ca> wrote:

> s...@missionstclare.com wrote:
>
>> I'm running PERL under the MACOSX.
>>
>
> It is spelled Perl, not PERL.   :-)
>
>
>
>  The line
>>
>> $text=~s/george/tim/;
>>
>> causes a global substituion of "george" with "tim"
>>
>> How can I limit the substituion to the first instance only?
>>
>
> Global substitution only works if you use the /g option but your example
> does not use the /g option so it will only replace the first 'george' it
> finds.
>
>    Correct, but sometimes this doesn't work all of the time, especially
with some very funny text files.
So, if John suggestion doesn't work as it should, then you may have to
enable slurp mode like this:
    $/=undef or local $/;
  So your code could read:

  {
     .....
     $/=undef;   ## or use local $/;
     $text=~s/george/tim/;
      ........
  }

  You could check *perldoc perlvar* for more information.
-- 
Tim

Reply via email to