perl - Cleaner way to write the following -
what efficient way write following code in perl:
my $index = 0; foreach ( @spec ) { if ( $module =~ m/$_/ ) { splice(@spec, $index, 0, $module); last; } $index++; } this works fine. seems little wordy. idea find match $module in array add entry. want keep array in order , sorted.
i.e. if array [a,b,c,d] , $module 'c', want result array [a,b,c,c,d].
you want "more efficient wordiness"??? presume you're not asking golfing, more readable code.
@spec = map { $_ eq $module ? ($_, $_) : $_ } @spec;
Comments
Post a Comment