hey--
I am working on my first project using OO perl, and have a quick question. I have several different files (some of which are very large) that are simple word lists-- words separated by a comma and a space. The idea is that I want to load all of the words from a file into an array via a method. The following code seems to do what I want:

sub words_from_file { my $self = shift; my $file_path = shift; my @word_list; open WORD_FILE, "< $file_path" or die "Could not open $file_path: $!\n"; while (<WORD_FILE>) { chomp; push @word_list, split ", "; } \@word_list; }

However, I am not at all sure that this is the best way to implement the functionality I want. In terms of security and speed, do you all have any suggestions? Are there file tests I should be making before the open? Should I do something involving tie to the filehandle to speed things up? (I know nothing about tie so I'm not even sure if that last question made sense :) Is there any benefit to using return \@word_list instead of what I've done in the last line?

just looking for any feedback before I get too much further into this,
--au


In reply to a method to get words from a file into an array by aufrank

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.