in reply to insert lines based on some pattern
use strict; use warnings; { my @filenames = ...; my $fn_out = ...; open(my $fh_out, '>', $fn_out) or die("Unable to create file \"$fn_out\": $!\n"); my $last; foreach my $file (@filenames) { my ($this) = $file =~ m{/(bakery|fruitjunction)/}; if (!defined($last)) { print $fh_out ("# ", uc($this), "\n"); } elsif ($last ne $this) { print $fh_out ("# END ", uc($last), "\n"); print $fh_out ("# ", uc($this), "\n"); } $last = $this; print $fh_out ($file, "\n"); } if (defined($last)) { print $fh_out ("# END ", uc($last), "\n"); } }
|
|---|