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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: Edit lines from a file and replace multiple lines.
by jwkrahn (Abbot) on Feb 11, 2023 at 04:39 UTC

    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
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Edit lines from a file and replace multiple lines.
by kcott (Archbishop) on Apr 01, 2023 at 17:46 UTC

    This node has been considered.

    Please visit "Nodes To Consider" for details and action required. Thankyou.

    Update: Node fixed by ++Athanasius. Consideration removed.

    — Ken