Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Edit lines from a file and replace multiple lines.

by harangzsolt33 (Chaplain)
on Feb 11, 2023 at 02:39 UTC ( [id://11150311]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150311]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 15:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found