After all of the talk about final newlines, and a problem just hit me in the head. I did not take into consideration blank lines in files. What if a file has a blank line or two in the middle? If there is a blank line it currently, the before and after still get put on the list without any other value.
test.txt (file)
red
orange
yellow
spring
green
teal
cyan
azure
blue
violet
magenta
pink
white
black
gray
Code
perl -E '
use lib "mods/lib";
use Fancy::Open qw(fancy_open);
my @array=fancy_open("test.txt", { before => "solid ", after => " bead
+" });
say $_ for @array;
'
Result
solid red bead
solid orange bead
solid yellow bead
solid spring bead
solid green bead
solid teal bead
solid cyan bead
solid azure bead
solid bead
solid blue bead
solid violet bead
solid magenta bead
solid pink bead
solid white bead
solid black bead
solid gray bead
So, I am now three steps back from being ready to package this module. *sighs*
I didn't feel like fighting with splice right now to add an empty line in the test script.
My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena
-
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.
|