Hello Perl300,

personally i (ab)use a lot the __DATA__ token. It's useful because can be used as other (even if bareword) filehandles.

It's free because magically appears to be valid as it is encountered in the file.

I use it when data is small or when I need to test some data exceptions so I put there worst cases mixed to some sane data and eventually some invalid row.

When I'm happy I just add a line opening an external file and I put the new (now lexical!) filehandle into the loop.

Also I hate Excel. More than the program in itself I hate the fact many people look at you bad if you do not declare to be an Excel wizard. So when some Excel task is given to me I export to comma separeted plain file and I put that blob under __DATA__ token. Then I excel..

In such, rare cases, i stick with the data into the file because both have no sense without the other.

But generally yes seems a good principle to have data separted from logic.

For default i use sometimes:$ARGV[0]//='input.txt' or $file=$ARGV[0]//='input.txt' for programs where only one argument is admitted. If more I use always Getopt::Long

For small hacks i (ab)use oneliners perl -lane ... does a lot of useful work for you in nothing. For example it auto chomp lines, thing you forgot to do in your above example ;=)

PS another useful thing for data are heredocs: sometimes I use one or more of them to test some XML parser logic extracted from a huge unreadable file.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: What is better: Static input data in separate file or embedding static input data in code. by Discipulus
in thread What is better: Static input data in separate file or embedding static input data in code. by Perl300

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.