in reply to Re^2: How to Save Fetched Web Files as "path/$string.xml"
in thread How to Save Fetched Web Files as "path/$string.xml"
The following sample may help clear up the interpolation issue. Don't worry too much about the first few lines. The key stuff is inside the for loop. The regex pulls the two parts out of the URL that you want to munge together and the double quoted string does the munging by interpolating the contents of the variables into the string. Note the use of the {} to let the Perl interpreter know that the trailing _ is not part of the variable name.
use warnings; use strict; my $root = 'http://gd2.mlb.com/components/game/aaa/year_2007/month_08/ +day_06/gid_2007_08_06_quiaaa_yucaaa_1/batters/'; my @batters = map {"$root$_"} qw(112039.xml 120107.xml); for my $url (@batters) { my ($prefix, $file) = $url =~ m!/(gid\w*)/batters/(.*)!; print "${prefix}_$file\n"; }
Prints:
gid_2007_08_06_quiaaa_yucaaa_1_112039.xml gid_2007_08_06_quiaaa_yucaaa_1_120107.xml
The double quoted string following the print can drop into your open, but remove the \n at the end and remember to use the three parameter version and to check the result.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to Save Fetched Web Files as "path/$string.xml"
by nase (Novice) on Aug 19, 2007 at 07:17 UTC | |
by GrandFather (Saint) on Aug 19, 2007 at 10:31 UTC | |
by nase (Novice) on Aug 23, 2007 at 06:53 UTC |