Hi Monks,

I have to read lines from a log file which begins with // with some white spaces before and put them in a array so below is the code what i could write and this works. But i want to know if i can remove the spaces before pushing into array instead of using s/^\s+//g; in foreach loop while printing and also i want to ignore the lines with -// which is getting included.

open (FH,"$file") || die ("could not openfile"); my @arr; while (<FH>) { chomp; push @arr , $_ unless $_ !~ /\s+\/\// ; } foreach (@arr){ s/^\s+//g; s/^-\/\/.+//g; print $_."\n"; } Thanks in advance.

In reply to Help in reading log file by Anonymous Monk

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.