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= '';
$id= 'seq.txt';
$line= $_;
($tax_id,$geneID,$genesymbol,$gene_des,$proteinacc_ver,$mrna_acc,$length,$nucleotide_gi,$start_gene,$end_gene,$strand) = split('\t');
$arr_size = $#protacc_arr;
$content = get('$protacc_arr[$i]');
$store = $content;
print OUTFILE"$store\n";
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 I really need to automate it..can sumbosy help..
I would be really grateful.


Recommended Answers

All 5 Replies

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/);

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 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.


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:


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


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.