My question is regarding extraction of data from a file in Perl. In the attached file there is standard format of net list. After running the program I got the elements into an array @name_gate
but when I tried to print @name_gate[0]
instead of the 1st element, I got the whole first column, similarly for @name_gate[1]
, the second column.
So the problem is I have again got a string in @name_gate[0]
which I want to access element by element.
my @ind;
my $index=0;
my $file = 'netlist.txt';
my $count=0;
my @name_gate;
open my $fh,'<',$file or die "could not open the file '$file' $!";
while (my $line = <$fh>)
{
chomp $line;
@name_gate = split (/ /,$line); #transforming string into arrays
print "@name_gate[0]";
}
The above code prints the whole column 1 2 3 4 up to 14. How can I extract a single element like 1 or 2 or 14 etc. Here is the current output