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

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:,MolecularWeight,TPSA/CSV/<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 = ''; + my $finalurl = get "$url$smiles/property/MolecularFormula,MolecularWei +ght,TPSA/CSV/"; print $finalurl;
and warning was: Use of uninitialized value $finalurl in print at 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.

    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::( my $finalurl = get "$url$smiles/property +/MolecularFormula,MolecularWeight,TPSA/CSV/"; DB<4> n main::( 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1083655]
Approved by kevbot
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
Find Nodes?
    Voting Booth?
    I am most likely to install a new module from CPAN if:

    Results (105 votes). Check out past polls.

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