Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
what i would like/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
it would be something like in the file i am writing...1. it should maitain the same order as listed. 2. based on the pattern (bakery|fruitjunction) it should add some patt +ern
currently my code is# 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
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,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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: insert lines based on some pattern
by bobf (Monsignor) on Feb 16, 2007 at 06:52 UTC | |
|
Re: insert lines based on some pattern
by ikegami (Patriarch) on Feb 16, 2007 at 06:32 UTC | |
|
Re: insert lines based on some pattern
by Mandrake (Chaplain) on Feb 16, 2007 at 07:03 UTC | |
by CountZero (Bishop) on Feb 16, 2007 at 10:12 UTC |