in reply to How to read from a file instead from a hard coding list.

Replace
my @words=qw( portion answers printer program );
with
chomp(my @words = `cat /path/to/file`);
and you should be done.

Replies are listed 'Best First'.
Re^2: How to read from a file instead from a hard coding list.
by afoken (Chancellor) on Apr 25, 2012 at 10:33 UTC
    my @words = `cat /path/to/file`

    Are you sure the OP uses some kind of unix? Windows has no cat command out of the box. And by the way: Why spawn a new process to read a file when perl can read the file without assistance? File::Slurp does a nice job.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Windows has no cat command out of the box.
      Does Windows has perl out of the box?
      Why spawn a new process to read a file when perl can read the file without assistance?
      Who cares about a new process? It isn't that we're doing this a billion times in a loop, and considering we're going to read a couple of Mb from disk, I don't think creating a new process is going to form a bottleneck.
      File::Slurp does a nice job.
      And that one comes with Windows out of a box? Really, you need a module to read in a file? What's wrong with
      chomp(my @words = do {local(@ARGV, $/) = "/path/to/file"; <>});
      or some other equivalent lines if you're willing to spend more keystrokes than `cat` is taking? Why is that using a module to do this is ok, but using a program isn't?