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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.