This gives an error at print join '*', @info{@columns}; And it prints all the matchings into one single line. How is it possible to print them out as would be in the following structure:#!/usr/bin/perl use strict; use warnings; my %info; # here we collect all information my @columns = qw(gi version cds); # The name and order of the columns +we want to print my $data = '/PRBB/Practice.gb'; # GenBank file is located at C:\PRBB open INFILE, '<', $data or die "Please insert a new coin!\n"; while (<INFILE>) { if (m!GI:(\d+)!) { if ($info{cds}) { # we are in a CDS block $info{gi} = $1; }; } elsif (m!^\s+CDS\s+(.*)!) { # a new gene information has started flush_info(); # now remember the CDS $info{cds} = $1 } elsif (m!^VERSION.*\w:(\d+)! ) { $info{ version } = $1; #} else {warn "Ignoring unknown line [$_]\n";}; };} # Output any leftover information: flush_info(); sub flush_info { # print out all information: print join '*', @info{@columns}; # and forget the collected information %info = (); };
Thanks for sparing time!if ( defined $cds && defined $gi && defined $version ) { # Print only +when all variables are defined print "$gi\t$version\t$cds\n"; $gi = $cds = undef; # Get ready for the next loop }
In reply to Re^10: Read, match string and print
by sophix
in thread Read, match string and print
by sophix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |