Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regarding file extraction

Status
Not open for further replies.

baig01

Programmer
Jun 23, 2011
1
US
#!/usr/local/bin/perl
use warnings;
use strict;

my $inputfile = "file1.txt"; # assign the contents of netlist to a scalar
open FH,$inputfile; # dump the contents of scalar to a file handler
my @results = <FH>; # use an array called results, a vector to store the items present in file handler
close FH; # close the file handler
print "\n---------type n--------------\n" ;
foreach my $line (@results) {
if($line =~ m/(^Mgn\d\.qna.*)/i) # get all the lines that start with Mg*.qna ignore the rest of the lines
{
print "$1\n"; # print the lines found
}
}
print "\n---------type p--------------\n" ;
foreach my $line (@results) {
if($line =~ m/(^Mgp\d\.qpa.*)/i) # get the lines that start with Mg*.qpa and ignore the rest
{
print "$1\n"; # print the lines that start with Mg*.qpa
}
}

This file extracts all lines that start with Mg1.q.....

what Im lookin for is for every line printed it should assign an alphabet for each line as a,b,c......
 
You can take advantage of the special way perl treats autoincrement ++ when dealing with strings

Code:
my $l = 'a';
$l++
print $l;

=prints
b
=cut

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top