This post was moved from Categorized Questions and Answers
Please do not vote for this node. It will affect the wrong user.
Thank you -- Q&AEditors
I wish to populate an array from a text file.
Each line of text should be a list item.
Here's what I've come up with, but results in "Use of uninitialized value at line 11" error.
What am I missing?
1 #!/usr/bin/perl -w
2 use strict;
3
4 $file = "/path/file";
5 open (<FH>, "< $file") or die "Can't open $file for read: $!";
6 while (<FH>) {
7 push (@lines, $line);
8 }
9 close FH or die "Cannot close $file: $!";
10
11 print join(',', @lines); # see if it worked
-
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.
|