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*
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |