in reply to Re: Edit lines from a file and replace multiple lines.
in thread Edit lines from a file and replace multiple lines.

Hello harangzsolt33,

It would be nice if you used <code> </code> tags for your code instead of <tt> </tt> tags.

When you're dealing with a relatively small file, then it's okay to read the entire file into memory. Next, you can split it so it occupies an array where each line is stored in an array element. I split it like this:
my @ARRAY = split(/[\r\n]+/, $ENTIRE_FILE_CONTENT);

Or you could use Tie::File:

use Tie::File; tie my @array, 'Tie::File', filename or die "Cannot open 'filename' be +cause: $!";
for (my $i = 0; $i < @ARRAY; $i++) { print "\n$ARRAY[$i]"; }

That is usually written as:

for my $i ( 0 .. $#ARRAY ) { print "$ARRAY[$i]\n"; }
Naked blocks are fun! -- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.