Some say premature optimization is the root of all programming evils (but then they must not have ever used COBOL). Overly concise code is generally a bad idea in production, too. However, I think that without hurting clarity it's always better to remove code to fix a problem rather than moving it around. This can often be done simply for off-by-one errors.
foreach $line ( @fileData ) { $linenumber++; if ( $line =~ m/^1$/) { print "$linenumber\n"; } }
Then there's the issue of idiomatic usage, which may or may not lead one to use $_, implicit matching against $_, or 'for' instead of 'foreach', depending one their views. This leads to code about as legible as the previous for many Perl coders, but I think it's fair to call it a matter of preference.
for ( @fileData ) { $linenumber++; if ( m/^1$/ ) { print "$linenumber\n"; } }
Which shouldn't be confused at all with golf, which does hinder legibility somewhat.
$l++,/^1$/&&print$l.$/for@f;

In reply to Re^2: Help with regex by mr_mischief
in thread Help with regex by ChuckularOne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.