Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How to repeat a line thrice by adding a digit into it

by suvendra123
on Mar 07, 2021 at 02:43 UTC ( #11129234=perlquestion: print w/replies, xml ) Need Help??

suvendra123 has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: How to repeat a line thrice by adding a digit into it
by haukex (Bishop) on Mar 07, 2021 at 05:23 UTC

    As the others have said, please use <code> tags to format your code and data. See How do I post a question effectively?, I know what I mean. Why don't you?, and Short, Self-Contained, Correct Example.

    However, even looking at the code as far as it as is readable at the moment, it seems like your code doesn't match the data you've provided: /-number_of_SP_mem_supp\s(\d+)/g won't match any of the provided data. And the task you are describing sounds pretty straightforward, a read of perlintro (and perhaps perlrequick/perlretut) should give you all the information you need. But if you run into trouble, please feel free to ask here, making sure to follow the advice given in the above links.

    use warnings; use strict; while ( my $line = <DATA> ) { if ( $line =~ /^foo/ ) { for my $x (1..3) { print "foo$x\n"; } } else { print $line; } } __DATA__ hello world foo_ bar
Re: How to repeat a line thrice by adding a digit into it
by Fletch (Chancellor) on Mar 07, 2021 at 03:47 UTC

    Your question is illegible as posted. Please peruse Markup in the Monastery and add some <c> markers.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: How to repeat a line thrice by adding a digit into it
by AnomalousMonk (Bishop) on Mar 07, 2021 at 07:06 UTC

    A variation on haukex's approach (assuming that guess about what you want is right):

    >perl use warnings; use strict; # use following statement (or similar) in real program: # open my $fh, '<', 'actual_file_name' or die "opening: $!"; open my $fh, '<', \<<'EOD' or die "opening: $!"; # for demo only hello world foo_ bar foo foox baz foo_ foo_xyzzy boff EOD LINE: while (my $line = <$fh>) { if (my ($intro) = $line =~ m{ \A (foo) _ }xms) { print "$intro$_\n" for 1..3; next LINE; } print $line; } ^Z hello world foo1 foo2 foo3 bar foo foox baz foo_ foo1 foo2 foo3 boff


    Give a man a fish:  <%-{-{-{-<

Re: How to repeat a line thrice by adding a digit into it
by AnomalousMonk (Bishop) on Mar 07, 2021 at 04:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11129234]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-06-21 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (97 votes). Check out past polls.

    Notices?