codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  help in perl script  mhadidi2002 at 02:26 on Wednesday, June 10, 2009
 


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 :)

  Re: help in perl script  kiruthika at 09:39 on Tuesday, March 16, 2010
 

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










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Need some help with javascript code in Unity!
•  Re: Perl - Read and Write output file
•  Re: Math.ceil depending on the number of decimal places
•  Re: drag from panel to panel..
•  Re: date of birth validation using java script-very urgent
•  Re: help me how to execute a linux shell script file(.sh file ) in perl
•  Save up to 80% on SSL Certificates, RapidSSL Certificate @ $ 11.00/yr.
•  help me
•  Re: substitute of goto in java???


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010