If you want to split the lines in an input file by using number of '*'.Then,you can use the regular expression to match the lines and push lines into two separate array.You check the following code.In this,I used both substitute as well as split function to do it.

use strict; use warnings; use Data::Dumper; open FH,"<input" or die "can't open:$!"; #opening the input file my(@arr1,@arr2); #declaring the arrays to store those lines while(<FH>) { #reading line from a file one by one if(/\*[^*]+\*/) { #checking whether the line has two *'s in it push @arr1,$_ ; #pushing that line to an array1 } else { push @arr2,$_; #pushing that line to an array2 if it isn't having two +*'s in it } } close FH; #closing the file handle print "Lines with two *'s in it\n"; print @arr1; print "Lines with two *'s in it\n"; print @arr2;

Another Way

open FH,"<input" or die "can't open:$!"; #opening the input file while(<FH>) { #reading line from a file one by one if((split '\*',$_)==3) #splitting the line by using '*' and checking w +hether the split returns three which means three filds in it { push @arr1,$_ ; #pushing that line to an array1 } else { push @arr2,$_; #pushing that line to an array2 if it isn't having thre +e fields in it } } print "Lines with two *'s in it\n"; print @arr1; print "Lines with two *'s in it\n"; print @arr2; close FH; #closing the file handle

In reply to Re: New to Perl by nvivek
in thread New to Perl 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.