I ran across this while I was trying to locate the spaces
in a row of dashes
in a header line to find the placement of the columns in a
formatted text report. Note that I could not just use a
split in the body of the report because some entries were
missing, and I had to do this for a lot of reports so I
needed the process to be dynamic.
The result shows why it is good to know what /g does in
scalar mode, and why pos() is a nice function to have.
This builds an array of the locations right after the space.
This was perfect for me since I wanted to know where the
next column would begin, but that is not always the ideal
choice.
my @pos;
while ($line =~ / /g) {
push @pos, pos($line);
}
-
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.
|