Dear Perl Monks, I have an array of filenames.i want to write this array of filenames into a file based on some pattern in the file names (in this case bakery or fruitjunction).
/home/units/bakery/cake.pl /home/units/bakery/pie.pl /home/units/bakery/plumcake.pl /home/units/fruitjunction/juice.pl /home/units/fruitjunction/icecream.pl /home/units/bakery/choclate.pl
what i would like
1. it should maitain the same order as listed. 2. based on the pattern (bakery|fruitjunction) it should add some patt +ern
it would be something like in the file i am writing...
# BAKERY /home/units/bakery/cake.pl /home/units/bakery/pie.pl /home/units/bakery/plumcake.pl # END BAKERY # FRUITJUNCTION /home/units/fruitjunction/juice.pl /home/units/fruitjunction/icecream.pl # END FRUITJUNCTION # BAKERY /home/units/bakery/choclate.pl # END BAKERY
currently my code is
my @bakery; my @fruitjunction; foreach my $file ( @filenames) { push (@bakery,$file) if($file =~ /bakery/) ; push (@fruitjunction,$file) ($file =~ /fruitjunction/); } if(scalar(@bakery)) { print WRITE "# BAKERY \n"; print WRITE @bakery; print WRITE "# END BAKERY \n"; } if(scalar(@fruitjunction)) { print WRITE "# FRUITJUNCTION \n"; print WRITE @fruitjunction; print WRITE "# END FRUITJUNCTION \n"; }
but i am unable to maintain the order of the files . similiar type is required for one of the modules in my project and hence i have changed the name of the files .... Thanks,

In reply to insert lines based on some pattern 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.