Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Perl Issue - File downloaded in windows has a Control M character in it??

by bart (Canon)
on Oct 24, 2012 at 20:15 UTC ( #1000706=note: print w/ replies, xml ) Need Help??


in reply to Perl Issue - File downloaded in windows has a Control M character in it??

I can't help wondering why you are using WWW::Mechanize where probably LWP::Simple with getstore would likely do. After all you seem to be only fetching a file from an URL... No login, no navigating towards a download page.

I am guessing WWW::Mechanize assumes HTML, thus, text contents, and treats it that way. getstore, on the other hand, saves (all) files as binary by default.

update From the WWW::Mechanize docs:

$mech->save_content( $filename )

Dumps the contents of $mech->content into $filename. $filename will be overwritten. Dies if there are any errors.

If the content type does not begin with "text/", then the content is saved in binary mode.

And no way to override it. Nice.


Comment on Re: Perl Issue - File downloaded in windows has a Control M character in it??
Download Code
Re^2: Perl Issue - File downloaded in windows has a Control M character in it??
by venky144 (Initiate) on Oct 24, 2012 at 20:49 UTC
    thanks...your solution worked well... LWP Simple worked... here is the modified code and it worked well..perl seems interesting
    use Storable; use LWP::Simple; #--------------------------------------------------------------------- +--------- # Define Variables for this process #--------------------------------------------------------------------- +--------- # File Down load path is used as a varible: $DownloadFilePath=<Path na +me> $DownloadFilePath="D:\\LIPAPSM\\DSSourcefiles\\"; #===================================================================== +========= # START OF PROGRAM #===================================================================== +========= $one_day = 60*60*24 ; my($day, $month, $year) = (localtime time+$one_day)[3,4,5]; $month = sprintf '%02d', $month+1; $day = sprintf '%02d', $day; $Datetotal=($year+1900).$month.$day; $filedate=join "", $Datetotal."damlbmp_zone.csv"; $url = join "",'http://mis.nyiso.com/public/csv/damlbmp/'.$filedat +e; $filename=join "",$DownloadFilePath.$filedate; mirror($url, $filename)
      Now lets cleanup that messy filedate code.
      use POSIX qw(strftime); my $filedate = strftime("%Y%m%d", localtime(time() + 86400));
        can you please update my complete code with the filedate.. what is the mess that's filedate creates...
        i didnt understand this one...my script is working fine..why do i need to add this again??

      And these lines are odd - you join strings with 'join' and '.':

      $filedate=join "", $Datetotal."damlbmp_zone.csv"; $url = join "",'http://mis.nyiso.com/public/csv/damlbmp/'.$filedate; $filename=join "",$DownloadFilePath.$filedate;

      You can simply quote them as one:

      $filedate = "${Datetotal}damlbmp_zone.csv"; $url = "http://mis.nyiso.com/public/csv/damlbmp/$filedate"; $filename = "${DownloadFilePath}$filedate";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2014-10-21 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (104 votes), past polls