Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to repeat a string multiple times if found match

by tybalt89 (Monsignor)
on Mar 09, 2021 at 09:30 UTC ( [id://11129367]=note: print w/replies, xml ) Need Help??


in reply to How to repeat a string multiple times if found match

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129359 use warnings; use Path::Tiny; my $path = path( 'test3.txt' ); $path->spew(<<END); hello world foo_ foo abc def END $path->edit_lines( sub { s/^(?=(foo_))/join '', map "$1$_\n", 1..3/e } +); print $path->slurp;

Outputs:

hello world foo_1 foo_2 foo_3 foo_ foo abc def

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found