http://qs321.pair.com?node_id=1126529


in reply to Re^2: regex statement to call variable value is not working??
in thread regex statement to call variable value is not working??

Hi Corion..

The code is working fine, but not does my intention function...i modified the code for my need based on your comments as followed...

use strict; use warnings; open (IN1, "<design_modify1.vhd") or die; open (OUT, ">output_file.vhd") or die; open (IN2, "<nets.txt") or die; open (IN3, "<enabled_nets.txt") or die; my @nets = <IN2>; my @enabled_nets = <IN3>; chomp @nets; chomp @enabled_nets; while (<IN1>) { print OUT; foreach my $i (0..$#nets){ print OUT if (s/\=\>\s+$nets[$i]\,/\=\> $enabled_nets[$i]\,/); #} } close (IN1); close (OUT); close (IN2); close (IN3);

I want the output file as follows.. (shown only the modifiable lines)

VCC_i : VCC port map(Y => \VCC\); sum_1_SUM0_0 : XOR3 port map(A => b_e, B => a_e, C => c_e, Y => su +m_c); carry_pad : OUTBUF port map(D => N_5, PAD => carry); a_pad : INBUF port map(PAD => a, Y => a_c);

but it is printing as follows.. I understood the mistake in the code that since i wrote the print statement inside for loop, it gets only one element of array at a time.. So, do you have any suggestions for this???

VCC_i : VCC port map(Y => \VCC\); sum_1_SUM0_0 : XOR3 port map(A => b_c, B => a_c, C => c_c, Y => su +m_c); sum_1_SUM0_0 : XOR3 port map(A => b_c, B => a_e, C => c_c, Y => su +m_c); sum_1_SUM0_0 : XOR3 port map(A => b_e, B => a_e, C => c_c, Y => su +m_c); sum_1_SUM0_0 : XOR3 port map(A => b_e, B => a_e, C => c_e, Y => su +m_c); carry_pad : OUTBUF port map(D => N_5, PAD => carry); a_pad : INBUF port map(PAD => a, Y => a_c);

Replies are listed 'Best First'.
Re^4: regex statement to call variable value is not working??
by Corion (Pope) on May 13, 2015 at 09:02 UTC

    Maybe you want to remember in your loop if you already printed a line?

    You could also modify your regular expression so it matches for all elements at once instead of doing a loop over it.