Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

need help for Getopt::Long;
Hi, I have problem to match array defined in Getopt::Long and transfer to
new file:
If I do:
try.pl --InputData sample.txt --Trait=_BMI --covars=age, _DBP, _SBP
--Race=Others
with this file:
GFAMID  GDADID  GMOMID  ID  SEX
HYT3  _SBP  _DBP  _BMI  RACE  AGE	 _HTMED  antiht

How can I get it to new file like this:

A	HYT3
C	_SBP
C	_DBP
T	_BMI
S	RACE
C	AGE
S	_HTMED
S	antiht

Thanks!!!

SW

 ########################################
####################################
###

#!/usr/local/bin/perl
# try.pl
use warnings;
use strict;
use Getopt::Long;
my $inputData =' ';
my $trait= ' ';
my $race;
my @covars;
my $result = GetOptions("InputData=s" => \$inputData,
"Trait=s" => \$trait,
"Race=s" => \$race,
"Covars=s" => \@covars
);
my @covarlist = split(/[\s|,]/, @covars);
if(!$inputData){
exit();
}
#die "you must specify all parameters\n\t--Trait --Race --Covars\n"
unless(define $trait || define $race || define @covars);
my $oriname = (split/\./, $inputData)[0];
my $outname;
if ($race){
$outname = "$oriname\_$race";
} else{
$outname = "$oriname";
}


open (outDat, ">$outname.dat") or die $!;
open (inPed, "$inputData") or die $!;

my $header = <inPed>;
chomp $header;
my @headline = split/\t/, $header;

my @ped_n_trait = @headline[0, 3, 1, 2, 4..12];
my %vartype;
foreach my $i (@ped_n_trait[5..12]){
if ($i eq 'HYT3'){
$vartype{$i} = 'A';
}elsif ($i eq "$trait"){
$vartype{$i} = 'T';
}else{
$vartype{$i} = 'S';
for(@covarlist){
if($_ eq "$i"){
$vartype{$_} = 'C';
}
}

}
}
for (@ped_n_trait[5..12]){
print outDat "$vartype{$_}\t$_\n";
}

close outDat;

close inPed;




Report this thread to moderator Post Follow-up to this message
Old Post
Shiping Wang
03-25-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:53 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.