in reply to To repeat each word in a line

This is not "modified code" since the code you have presented is not Perl at all. However here is just one of the many, many ways to achieve this in Perl.

#!/usr/bin/env perl use strict; use warnings; use Path::Tiny; my @r = path (shift)->lines; s/(.*),$/.$1($1),/ for @r[1..$#r]; $r[-1] =~ s/,$/);/; print @r;

And if you save it to a file called double.pl here is how it runs:

$ cat input.txt module abc( rist_top_tck, rist_top_tdi, rist_top_tdo, $ ./double.pl input.txt module abc( .rist_top_tck(rist_top_tck), .rist_top_tdi(rist_top_tdi), .rist_top_tdo(rist_top_tdo)); $

See the docs for Path::Tiny, s/// and print for more.


🦛

Replies are listed 'Best First'.
Re^2: To repeat each word in a line
by kulua (Initiate) on May 23, 2021 at 10:35 UTC
    Can't locate Path/Tiny.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at abc.pl line 4.