[PLUG] Perl Question

Eric Wilhelm ewilhelm at sbcglobal.net
Tue Jul 26 16:56:59 UTC 2005


# from M. Edward (Ed) Borasky
# on Monday 25 July 2005 10:04 pm:

>$hugestring =~ s/NAME=.{80}/NAME=${newname}/g;
>
>where "$newname" contains "John Doe" followed by 72 spaces, etc.

>I'm also guessing you don't want to replace every person's name with
>"John Doe" but a different name for each original name. So rather than
>use a one-shot replace command, you somehow might need to break the
>string up into individual records, replace each name field with a
> random one, then reassemble the string. Is that correct? If so, is
> there any kind of "record separator" in your input string?

Or you can add the 'e' modifier and call a function.

  $hugestring =~ s/NAME=.{80}/
	"NAME=" . make_newname($1)/ex;

Check 'perldoc perlre'.

Of course, you might have a performance issue if $hugestring is that 
huge.  Not sure if you would get a better result using substr() within 
a loop there or not.

--Eric
-- 
"It is a mistake to allow any mechanical object to realize that you are 
in a hurry."
--Ralph's Observation
---------------------------------------------
    http://scratchcomputing.com
---------------------------------------------



More information about the PLUG mailing list