I am trying to open a file inside a subroutine to basically substitute some lines in the file. But since, it was not working, I tried a simpler way of printing a line instead of substitute, for debug purposes. Following is the subroutine code.

sub replace { while(<INPUT_FILE>){ my $cell=$_[0]; our $rpl; if ($_=~ /^TASK\|VALUE = (.*)/ ){ my $task=$1; chomp $task; $rpl= $cell.'_'.$task.'_bunch_rpl' +; print "000: $rpl\n"; } elsif ($_=~ /^(.*)\|VALUE = (.*)/ ){ my $line= $_; chomp $line; my $ip_var= $1; my $ip_val=$2; chomp $ip_var; chomp $ip_val; my $look= $ip_var."|VALUE"; open(REPLAY_FILE, "+<$rpl") | +| die "\ncannot open $rpl\n"; while (my $rpl_sub = <REPLAY_F +ILE>){ if ($rpl_s +ub =~ /^$line/) { print +"\n 111: $ip_val"; } + } close REPLAY_F +ILE; } elsif ($_=~ /^\s*$/){ print "\n"; return ; } } }

The code prints the following as of now.

000: lfr_task62_bunch_rpl 111: 2.0.9.0 111: INLINE 111: POWER 000: aaa_task14_bunch_rpl

Expected output is:

000: lfr_task62_bunch_rpl 111: 2.0.9.0 111: INLINE 111: POWER 000: aaa_task14_bunch_rpl 111: 0.45 111: NO

The input sample is :

TASK_CELL_NAME|VALUE = lfr TASK|VALUE = task62 TASK_VERSION|VALUE = 2.0.9.0 CHIP_PKG_TYPE|VALUE = INLINE JUNK_LINE = JUNK JUNK_LINE = JUNK FULL_ESD|VALUE = POWER TASK_CELL_NAME|VALUE = aaa TASK|VALUE = task14 CUSTOM_CELL_DENSITY|VALUE = 0.45 CUSTOM_CELL_SS|VALUE = NO

Can someone tell me the mistake I am doing here?


In reply to Trying to read print in a loop inside a subroutine by kaushik9918

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.