if you undef $/; then you can say my @array = split /\n+/, <DATA>; and this will ignore all the empty lines.
Update
Sorry about the minimalist post - didn't have any time earlier. The reason this works is that $/ (newline by default) is used as the end-of-line character when reading from a filehandle. If you undefine it then no end of line is seen and the whole file is "slurped" in, in one go. "split"ting this on one (or more) newlines does the "chomp"ing for you while also returning a list. hope this makes it a bit clearer.
"Argument is futile - you will be ignorralated!"
-
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.
|