in reply to A string from a file

I just tried that and it doesn't look like it changes too much from what you type in. Looking at the file that you are reading, does the text file contain the actual text "\n" (two characters) or does it contain a newline. If it contains the two separate characters, the characters won't ever get interpolated as a newline.

Something that will lighten the load of your swaps (especially on large documents) is to first delimit your swap in variables (instead of "PRINTER" put some special characters around it such as "__printer__"), and then swap in keys from a hash as in the following:
# set up a hash containing the values you want my %SWAPS = (); $SWAPS{printer} = $printer; $SWAPS{quota} = $quota; if($pagestate eq "duplex"){ $SWAPS{pagestate} = 'double sided'; }elsif ($pagestate eq "simplex"){ $SWAPS{pagestate} = 'single sided'; } if( 1 ){ $SWAPS{multiplier} = 'some_multiplier'; } # swap out things like __printer__ with $SWAPS{printer} $msg =~ s/__(\w+?)__/$SWAPS{$1}/g;

This does only one parse on the string and is a little bit more controlled than doing the multiple swap thing.

my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
Re: Re: A string from a file
by entropy (Sexton) on May 05, 2001 at 04:57 UTC
    Or if you worry about the tokens not being in the hash:
    $msg =~ s/__(\w+?)__/(defined $SWAPS{$1})?$SWAPS{$1}:"__$1__"/eg
Re: Re: A string from a file
by Grand_Phallus (Novice) on May 07, 2001 at 23:33 UTC
    Thanks, I appreciate your help. I'm pretty new to perl, and am trying to figure out ways to streamline my code wherever I can.
    Muchas Gracias