paola82 has asked for the wisdom of the Perl Monks concerning the following question:

I was trying to download a file from a web site http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/pdbsum/GetPage.pl?pdbcode=$pdb"

where $pdb is my var....and then I want to download a file postscript from a link...but when you try manually it ask if you want to save or see the file, so I cannot use wget command of linux...but using LWP::Simple and the mirror function it runs and below I give my code

use LWP::Simple; print "write the name of the folder where you wanna save your file: "; my $Dir= <STDIN>; chomp ($Dir); if(!-e $Dir) { system "mkdir $Dir"; } if(!-w $Dir or !-d $Dir) { die "ERROR: Cannot access directory: '$Dir'. Exiting\n"; } print "write name of the path of that directory: "; my $path= <STDIN>; chomp ($path); my $pdb = <STDIN>; #if you wanna try use 1xmj... chomp ($pdb); my @files = (["http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/pdb +sum/RunLigplot.pl?pdb=1xmj&amp;file=ligplot01_01", "/$path/$Dir/name_ +file.pl"]); for my $duplet (@files) { mirror($duplet->[0], $duplet->[1]); }

Replies are listed 'Best First'.
Re: download a file from a web
by ig (Vicar) on Apr 17, 2009 at 11:11 UTC

    What happens when you run your scripts? Do you get any error messages? It would be easier to help you if you posted any error messges produced and a description of what happens when you run your scripts.

    update: I ran your script that uses LWP::Simple mirror method, only changing the destination file name to suite my system (linux) and it ran successfully, downloading the postscript file. So, again, what happens on your system when you run this script?

      nothing happens....I run it and I expect It will save my file on the desktop...but no...nothing happens..i really don't know why.. thanks for reading and help me, dear friend Paola
        thanks .....I've got it...only a sythax....thanks thanks thanks :-)
Re: download a file from a web
by apl (Monsignor) on Apr 17, 2009 at 12:01 UTC

    You should consider changing your system statements from

    system "mkdir $Dir";

    to

    system "mkdir $Dir" or die "mkdir of '$Dir' failed: $?";

    Anything could be the cause: permission restrictions, ill-constructed director names...

    Have you stepped through your program in the debugger?

    Which of your print statements get executed?

      Since system returns false on success, better to test ... == 0 or die...

      You shouldn't run a shell at all to create a directory, Perl has a portable buildin mkdir() function for that, including reliable return values.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Quite so, but there were several system calls. If one is going to use it, it's a good idea to check its' success or failure. (Though one should take pains to do so correctly,)