I instantiate the module without naming the file, then call get_lines with the file name. It doesn't need to be passed as an argument to get_filehandle because it's already there.
Yes, you're right, because you call get_filehandle inside of get_lines, it actually could make sense to pass the filename to the get_lines call. However, I think it could potentially still be confusing because with the code you showed, if all the user uses is get_lines, it'll only ever open one file - say I call my $x = $obj->get_lines("foo.txt"), and then my $y = $obj->get_lines("bar.txt"), now $y contains the second line of foo.txt. So that's why it might be better to separate the two actions - opening the file and reading from it - into two methods.
Update: The reason I questioned whether it makes sense to pass a filename to get_filehandle is that I was imagining $self->{file} to be an object property that might deserve its own setter, but that's not as important. BTW, you might want to consider renaming get_filehandle to something like open_file to make it more clear what the method is doing.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|