Dear people
I have been trying to fetch some data from the web. For this I am using the
LWP:: Simple module.
The problem is that I have been trying to pass a value to the URL in get function.

here is my code:
use LWP:: Simple;
$iq= 'all_proteins.data';
$id= 'seq.txt';
open(INFILE,"$iq");
while(<INFILE>)
{
$line= $_;
$line=~tr/\n//d;
($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = split('\t');
push(@protacc_arr,"$proteinacc_ver");
}
$arr_size = $#protacc_arr;
open(OUTFILE,">>$id");
for($i=0;$i<=$arr_size;$i++)
{
$content = get('http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?db=protein&sendto=t&dopt=fasta&list_uids=$protacc_arr[$i]');
$store = $content;
print OUTFILE"$store\n";
}
close(INFILE);
close(OUTFILE);
exit;
--------------------------------------------------------------------------
ok So the main problem that I am facing over here is that the value which is a ID ($protacc_arr[$i]) acquires some ids from my earlier code.
but I think when i am trying to pass it in the get function ..i am not able to.

I want to ask:
can we pass a value in a URL.
If yes , how do we do it...if not what is an alternative to do that in perl.

I am confused how to do it, as the code works fine i write a value such as NP_332.1 instead of passing it using an array.. but the problem is that I haver to do it for more than lakhs of ids ..so I really need to automate it..can sumbosy help..
I would be really grateful.

Thanks
Aj

This line also needs to be changed:

$nucleotide_gi,$start_gene,$end_gene,$strand) = split('\t');

\t in single-quotes is a literal string, not a tab, so use forward slashes for the split() delimter:

$nucleotide_gi,$start_gene,$end_gene,$strand) = split(/\t/);

hey
Thanks a lot for your suggestion ..the code is working perfectly now ..
Though I would like to pose one more question as you know there are certain variables which i am not using to print any values but just to split my data..
thus ..as I run my code there are certain warnings that comes at the starting ..
for e.g:
Name::main $tax_id not used more than once ..

what I mean is that it is not creating any problem but can I do something to avoid those warnings.

Thanks
Aj
.

Yes there is something you can do. There are a few things actually. But I think this is the best suggestion. Instead of returning a list of scalars with some that you don't use, return a list slice consisting only of the ones you want to use. Look at this line:

($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = split("\t");

It returns a list of 11 scalars. They are numbered 0 thru 10, so your line above is the same as this:

($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = (split("\t"))[0..10];

Now what you can do is take just the elements of the list you want by including only those ones in the index list, say you only want $geneId (#1) and $nucleotide_gi (#7):

my ($geneID,$nucleotide_gi) = (split("\t"))[1,7];

Note the extra set of parenthisis on the right side of the assignment operator, that is important. Note I added "my" in the above line also. You need to start using "strict" and "warnings" with your script (not the -w switch) and declaring the varaibles within their intended scope of use with "my" (lexical) or "our" (global). You can look them all up in the perl documentation:

strict
warnings
my
our

Hey thanks a lot for your excellent suggestions .. the code looks extremely perfect now.

Cheers
Ajay

This question has already been answered. Start a new discussion instead.