When I tried your script (making up my own "data.txt" file with just the one "input" value you mentioned -- "2CU3"), I got two output files:

One, called "2CU3.html", contained the output of Data::Dumper, as expected; this was a fairly big file, and probably not the one that you really intend to use with any sort of text editor.

The other, whose file name was this long url string:

downloadFile.do?fileFormat=FASTA&compression=NO&structureId=2CU3
was pretty small (188 bytes), containing just the following four lines of plain text:
>2CU3:B|PDBID|CHAIN|SEQUENCE MVWLNGEPRPLEGKTLKEVLEEMGVELKGVAVLLNEEAFLGLEVPDRPLRDGDVVEVVALMQGG >2CU3:A|PDBID|CHAIN|SEQUENCE MVWLNGEPRPLEGKTLKEVLEEMGVELKGVAVLLNEEAFLGLEVPDRPLRDGDVVEVVALMQGG
This latter file was perfectly legible with TextEdit on my mac (osx 10.6.4) -- that is, when I just cat the file content out in a Terminal window (which is where the above lines were copy/pasted from), it looks the same as when I open it in TextEdit.

I've never used TextWrangler (don't have it installed), so I don't know if it would look any different there. But I don't see a need to try, since TextEdit seems to be showing me the exact content of the FASTA file, without any trouble.

So, what do you mean, exactly, when you say "it's just junk in textedit"?

BTW, I would suggest that you change your method of coming up with an output file name for the FASTA files. Having question marks and ampersands in file names can be a real drag if you ever end up doing command-line shell operations on them. It might be sufficient just to add one line of code:

$filename =~ s[^.+/][]; # you have this one already $filename =~ tr/?&/_/; # just add this one (turns all ? and & int +o _)
If any of the urls ever contain a space, asterisk, semi-colon, exclamation mark, vertical-bar (|), parens, brackets, or single or double quotes, you'll want to add those to ? and & in the tr/// statement, as well.

One last point -- I don't know for sure, but maybe if you added a ".txt" extension to the output FASTA file name, your TextEdit might behave better? (When I used TextEdit, it opened the file just fine as-is, but I could imagine the possibility of "user preferences" having some unexpected side-effect...)


In reply to Re: using WWW::Mechanize to download a link, opened fine in TextWrangler but as junk in TextEdit by graff
in thread using WWW::Mechanize to download a link, opened fine in TextWrangler but as junk in TextEdit by nurulnad

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.