http://qs321.pair.com?node_id=839384

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

I have a project in which i have to download a few files using a perl script and then mail it. For Emailing the File i am using Email::Send and Email::MIME. The script is more or less ready, but i have a small problem.

The URLs are specified in a text file.

The problem is that every time i download a file, i have to specify the name by which it is to be saved along with the URL. What I want to do is that whenever a file is to be downloaded, the name should be extracted from the URL only.

e.g. if URL is www.abcd.com/search or www.efgh.in#found

The file should be saved by the name of (www.abcd.com.ppt) or (www.efgh.in.doc)

The code is posted below. Please help me out.

#!/usr/bin/perl use warnings; use LWP::Simple; use Tie::File; my $testfolder = "/Users/Apurv/Desktop/"; tie @file, 'Tie::File', $testfolder . "file1.txt" or die; foreach $URL (@file) { my $name = substr $URL, 29, 13; my $add = substr $URL, 0, 29; my $file = $testfolder . "$name"; my $status = mirror($add,$file); die "Cannot retrieve $add" unless is_success($status); . . . {Mailing Part code} }

Here I was manually specifying the Name along with the text file.

I found out that I can use Split. But being a newbie to perl programming, could not understand it properly.