Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to use STDIN in between a URL?

by piscean (Acolyte)
on Apr 24, 2014 at 17:45 UTC ( #1083655=perlquestion: print w/replies, xml ) Need Help??
piscean has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I am using PUBCHEM's PUG REST service to download properties of a specific chemical compound. I want to give STDIN input of the chemical compound in the form of a SMILES string (it's a format to represent a chemical compound, like a molecular formula). The PUG REST URL format looks like this:

http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/CCC/property/MolecularFormula,MolecularWeight,TPSA/CSV/

http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/<smiles string>/property/<properties of interest>/<output file format>/

Now, how do I STDIN my smiles string in the above format of URL? I've tried some little tricks like this:

#!/usr/bin/perl use LWP::Simple; my $smiles = <STDIN>; my $url = 'http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/'; + my $finalurl = get "$url$smiles/property/MolecularFormula,MolecularWei +ght,TPSA/CSV/"; print $finalurl;
and warning was: Use of uninitialized value $finalurl in print at test_lwp.pl line 12. Thanks in advance :)

Replies are listed 'Best First'.
Re: How to use STDIN in between a URL?
by ikegami (Pope) on Apr 24, 2014 at 18:10 UTC
    You didn't remove the line terminator.
    chomp($smiles);

    You should at least have printed "$url$smiles/property/MolecularFormula,MolecularWeight,TPSA/CSV/" when trying to find the problem. And it would have found it.

      Oops! Thanks @ikegami :)
Re: How to use STDIN in between a URL?
by InfiniteSilence (Curate) on Apr 24, 2014 at 18:11 UTC

    chomp is your friend.

    DB<1> p $smiles CCC DB<2> chomp $smiles DB<3> p $smiles CCC DB<4> n main::(monks1083655.pl:8): my $finalurl = get "$url$smiles/property +/MolecularFormula,MolecularWeight,TPSA/CSV/"; DB<4> n main::(monks1083655.pl:9): print $finalurl; DB<4> p $finalurl "CID","MolecularFormula","MolecularWeight","TPSA" 6334,"C3H8",44.095620,0.0 DB<5> q

    Celebrate Intellectual Diversity

      Thanks, my friend :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1083655]
Approved by kevbot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2019-04-18 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (105 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!