This post now contains the actual code not previously provided at the bottom.

I have not yet been able to work with the script for those files specifically (that one is next). However, I am trying to apply the interpolation method to a similar script (in scratchpad) that I've already built (using the same gid URL). Please note that I am unable to 'use strict' as it is presenting too many conflicts with the time::local module I'm using in another part of the code.

This 3-parameter open works very well as you suggested but isn't the desired result: open(FILEHANDLE, ">","$outputdir/players.xml")

This does not work: open(FILEHANDLE, ">","$outputdir/$game._players.xml")

I'm trying to open as a filename such as $outputdir/$game_players.xml where $game="gid...." The only difference from the last problem is that '110246' is now 'players'. I've tried my best to adapt the code but I keep hitting roadblocks. The important part of the code is now in my scratchpad. Note that I am using LWP to pull data from the web.

Thanks as always. Edit: The warning that I am getting is the 'could not open' one at the bottom of the code. I also read a little bit about the File::Spec module which has something to do with directories and filenames but I was unable to find anything on it past the brief descriptions in the Perl manual. Could be irrelevant.

my $sourceurl = "http://gd2.mlb.com/components/game/aaa"; my $outputdir = "./aaa_players"; my $dayurl = "$sourceurl/year_$year/month_$mon/day_$mday/"; my $response = $browser->get($dayurl); die "Couldn't get $dayurl: ", $response->status_line, "\n" unless $response->is_success; my $html = $response->content; my @games = @_; while($html =~ m/<a href=\"(gid_\w+\/)\"/g ){ push @games, $1;} # the loop that downloads data foreach $game (@games) { my $gameurl = "$dayurl/$game"; $response = $browser->get($gameurl); die "Couldn't get $gameurl: ", $response->status_line, "\n" unless $response->is_success; $gamehtml = $response->content; if($gamehtml =~ m/<a href=\"players\.xml\"/ ) { $plyrurl = "$dayurl/$game/players.xml"; $response = $browser->get($plyrurl); die "Couldn't get $plyrurl: ", $response->status_line, "\n" unless $response->is_success; $plyrhtml = $response->content; print "\t\tfetching game: $game\n"; open(FILEHANDLE, ">","$outputdir/players.xml") or die "could not open file $game/players.xml: $|\n"; print FILEHANDLE "$game\n"; close FILEHANDLE; } else { print "warning: no player list for $game\n"; }

In reply to Re^4: How to Save Fetched Web Files as "path/$string.xml" by nase
in thread How to Save Fetched Web Files as "path/$string.xml" by nase

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.