In addition to the excellent suggestions you have already received, I thought you might like to see what the errors in your own script are and how to correct them.

First I used Perl::Tidy to reformat your script, making it a bit easier to ready. Then I began adding print statements so I could see what it was doing and fixing the errors.

Here is the modified script, which downloads and saves two postscript files which, I hope, is what you want it to be doing.

use strict; use warnings; use LWP::Simple; my $url3 = "http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/pdbsum/GetPage.pl +?pdbcode=2j6p&template=ligands.html&l=1.1"; my $content = get($url3) or die "$url3: get failed"; use HTML::TreeBuilder; my $p = HTML::TreeBuilder->new; $p->parse_content($content); my @href; my $href; my @anchors = $p->look_down( _tag => q{a} ); for my $anchor (@anchors) { my $txt = $anchor->as_text; if ( $txt =~ /EPE\s/ ) { print $txt, qq{\n}; $href = $anchor->attr(q{href}); print $href, qq{\n}; chomp($href); push @href, $href; #now I need to go to the link where there are my EPE ligand and then p +arse and extract the link of the RunLigplot.pl that is the output of +a program LigPlot, written in perl, is a postcript, and I need that f +ile as a script to extract info....I need to repeat these parsing for + every link,for every EPE.... } } $p->delete; for my $param (@href) { print "processing param: \"$param\"\n"; my $url = "http://www.ebi.ac.uk$param"; my $content = get($url) or die "$url: get failed"; process_content($content); # << This is missing from your code +!!! } sub process_content { my $content = shift; $p = HTML::TreeBuilder->new; $p->parse_content($content); my @href0; my @anchors0 = $p->look_down( _tag => q{a} ); for my $anchor0 (@anchors0) { print "anchor: " . $anchor0->as_HTML() . "\n"; my $href0 = $anchor0->attr(q{href}); next unless($href0); print "found href: $href0\n"; if ( $href0 =~ /(ligplot\d\d_\d\d)/ ) { my $id = $1; print $href0, qq{\n}; push @href0, $href0; for my $param0 (@href0) { my $url = "http://www.ebi.ac.uk$param0"; print "getting $url\n"; $content = get($url) or die "$url: get failed"; # my $content = shift; # print my $param0; #I need to download files from every link $param0... my $pdb = 'testpdb'; my @files = ( [ "http://www.ebi.ac.uk$param0", "$pdb.$id.ps" ], +); for my $duplet (@files) { print "mirror $duplet->[0] to $duplet->[1]\n"; mirror( $duplet->[0], $duplet->[1] ); } } $p->delete; } } }

And here are the changes, other than the reformatting done by Perl::Tidy.

< my $content = get($url3); --- > my $content = get($url3) or die "$url3: get failed"; 32c32,34 < my $content = get("http://www.ebi.ac.uk$param"); --- > print "processing param: \"$param\"\n"; > my $url = "http://www.ebi.ac.uk$param"; > my $content = get($url) or die "$url: get failed"; 42a45 > print "anchor: " . $anchor0->as_HTML() . "\n"; 43a47,48 > next unless($href0); > print "found href: $href0\n"; 45c50,51 < if ( $href0 =~ /ligplot\d\d_\d\d'/ ) { --- > if ( $href0 =~ /(ligplot\d\d_\d\d)/ ) { > my $id = $1; 49,51c55,59 < $content = get("http://www.ebi.ac.uk$param0"); < my $content = shift; < print my $param0; --- > my $url = "http://www.ebi.ac.uk$param0"; > print "getting $url\n"; > $content = get($url) or die "$url: get failed"; > # my $content = shift; > # print my $param0; 53a62 > my $pdb = 'testpdb'; 55c64 < ( [ "http://www.ebi.ac.uk$param0", "$pdb.$param0.p +l" ], ); --- > ( [ "http://www.ebi.ac.uk$param0", "$pdb.$id.ps" ] +, ); 56a66 > print "mirror $duplet->[0] to $duplet->[1]\n";

In reply to Re: to repeat action for a cicle of files by ig
in thread to repeat action for a cicle of files by paola82

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.