kaushik9918 has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to read print in a loop inside a subroutine
by hippo (Archbishop) on May 20, 2020 at 11:06 UTC | |
by kaushik9918 (Sexton) on May 20, 2020 at 12:32 UTC | |
|
Re: Trying to read print in a loop inside a subroutine
by haukex (Archbishop) on May 20, 2020 at 10:31 UTC | |
by kaushik9918 (Sexton) on May 20, 2020 at 11:09 UTC | |
|
Re: Trying to read print in a loop inside a subroutine
by clueless newbie (Curate) on May 21, 2020 at 00:34 UTC | |
by kaushik9918 (Sexton) on May 21, 2020 at 06:16 UTC | |
|
Re: Trying to read print in a loop inside a subroutine
by perlfan (Parson) on May 22, 2020 at 03:54 UTC | |
by Anonymous Monk on May 22, 2020 at 04:58 UTC |