|
Dear all,
I am a beginner using perl; scripting, so i wish you cna help me...
I have a file containing a data like this:
>CHA 2
#419150.000000
[4639567,4639674] [4825157,4825264] 7196
[4639511,4639565] [4825101,4825155] 8416
#1346.000000
[4612526,4612558] [859583,859615] 1843
[4612489,4612510] [859547,859568] 17296
#1263.000000
[4612623,4612644] [3296095,3296116] 18439
[4612483,4612515] [3296057,3296089] 4517
this data is transfered to an array, so each line in 1 element of this array (@data)
I want a code that extract the first no. in the first square bracket in each line in @arr1(4639567,4639511,... for example).
Thank you in advance :)
|
|
|
Try the following code.
use strict;
use warnings;
use Data::Dumper;
open FH,"data" or die $!;
my @lines=<FH>;
my $i=0;
my $j=0;
my @numbers;
while($i++ < $#lines)
{
if($lines[$i]=~/^\[(.*?),(.*?)\](.*)/)
{
$numbers[$j++]=$1;
}
}
print Dumper \@numbers;
|
|
Here 'data' is a file which contains the following data.
data
-----
#419150.000000
[4639567,4639674] [4825157,4825264] 7196
[4639511,4639565] [4825101,4825155] 8416
#1346.000000
[4612526,4612558] [859583,859615] 1843
[4612489,4612510] [859547,859568] 17296
#1263.000000
[4612623,4612644] [3296095,3296116] 18439
[4612483,4612515] [3296057,3296089] 4517
|
|
|
|
|
|
|
|