Assigning range to an array in Perl -
i have mini problem. how can assign range array, one:
input file: clktest.spf
* .global vcc! vss! * .subckt eclk_l_25h brg2eclk<1> brg2eclk<0> brg_cs_sel brg_out brg_stop cdivx<1> + eclkout1<24> eclkout1<23> eclkout1<22> eclkout1<21> eclkout1<20> eclkout1<19> + mc1_brg_dyn mc1_brg_outen mc1_brg_stop mc1_div2<1> mc1_div2<0> mc1_div3p5<1> + mc1_div3p5<0> mc1_div_mux<3> mc1_div_mux<2> mc1_div_mux<1> mc1_div_mux<0> + mc1_gsrn_dis<0> pclkt6_0 pclkt6_1 pclkt7_0 pclkt7_1 slip<1> slip<0> + ulc_pclkgpll0<1> ulc_pclkgpll0<0> ulq_eclkcib<1> ulq_eclkcib<0> * *net section * *|ground_net 0 * *|net eclkout3<48> 2.79056e-16 *|p (eclkout3<48> x 0 54.8100 -985.6950) *|i (rxr0<16>#neg rxr0<16> neg x 0 54.2255 -985.6950) c1 rxr0<16>#neg 0 5.03477e-17 c2 eclkout3<48> 0 2.28708e-16 rk_6_1 eclkout3<48> rxr0<16>#neg 0.110947
output (this should saved value in array)
.subckt eclk_l_25h brg2eclk<1> brg2eclk<0> brg_cs_sel brg_out brg_stop cdivx<1> + eclkout1<24> eclkout1<23> eclkout1<22> eclkout1<21> eclkout1<20> eclkout1<19> + mc1_brg_dyn mc1_brg_outen mc1_brg_stop mc1_div2<1> mc1_div2<0> mc1_div3p5<1> + mc1_div3p5<0> mc1_div_mux<3> mc1_div_mux<2> mc1_div_mux<1> mc1_div_mux<0> + mc1_gsrn_dis<0> pclkt6_0 pclkt6_1 pclkt7_0 pclkt7_1 slip<1> slip<0> + ulc_pclkgpll0<1> ulc_pclkgpll0<0> ulq_eclkcib<1> ulq_eclkcib<0> * *net section
my simple code:
#!/usr/bin/perl use strict; use warnings; $input = "clktest.spf"; open infile, $input or die "can't open $input" ; @allports; while (<infile>){ @allports = /\.subckt/ ... /\*net section/ ; print @allports; }
i doing correct job of assigning selected range array? if not how can modify code?
thanks advance.
the while
loop gives 1 line @ time can't assign of lines want @ once. use push
instead grow array line line.
also, should using lexical file handles $in_fh
(rather global ones infile
) three-parameter form of open
, , should include $!
variable in die
string know why open failed.
this how program should look
#!/usr/bin/perl use strict; use warnings; $input = 'clktest.spf'; open $in_fh, '<', $input or die "can't open $input: $!" ; @allports; while ( <$in_fh> ) { push @allports, $_ if /\.subckt/ ... /\*net section/; } print @allports;
note that, if want print selected lines file, can forget array , replace push @allports, $_
print
Comments
Post a Comment