in reply to add character to all lines starting with..

If it's just a one off then you can take advantage of perl's command-line switches e.g
perl -pi -e 'm{^/index} and s/$/%/' file
Or if you want to do it programmatically and are working with relatively small files then make use of Dominus' marvellous Tie::File
use Tie::File; tie my @fl, 'Tie::File', "filename.here" or die "ack: $!"; for(@fl) { m{^/index} and s/$/%/; }
And if you're working with large files then this might be a better solution
open(my $in_fh, '<', "input.filename") or die "ack: $!"; open(my $out_fh, '>', "output.filename") or die "ack: $!"; while(<$in_fh>) { m{^/index} and $_ .= "%"; print {$out_fh} $_; } close $in_fh; close $out_fh; rename( "output.filename", "input.filename" ) or die "ack: $!";

HTH

_________
broquaint

update: have fixed code to DTRT, thanks to delirium

Replies are listed 'Best First'.
Re: add character to all lines starting with..
by delirium (Chaplain) on Sep 24, 2003 at 20:31 UTC
    Broquaint,

    All these are going to add the percent sign after $/, no?

    I'd use -l from the command line (e.g., Abigail's solution), or something like

    $_=~s/$/%/;

    replacing the

    $_.='%';

    (Update: autochomp will take care of this in Tie::File)