http://www.perlmonks.org?node_id=1184965


in reply to Re^3: How to remove underscore at the end of the line?
in thread How to remove underscore at the end of the line?

sub ir($$); sub ir($$) { my $prefix = shift @_; $prefix=~ s/_$//; print $prefix,"\n"; my $dir = shift @_; print "&&&$dir&&&","\n"; opendir(DIR, $dir) or die $!; my @entries = readdir(DIR); print "****@entries***"; close(DIR); foreach my $file (@entries) { next if ($file =~ /^\.+$/); if ( -d $dir . '/' . $file) { ir($prefix . $file .'_', $dir . '/' . $file); } elsif ( ( -f $dir . '/' . $file ) && ( $file =~ /\.config$/ +) && ($file !~ /^$prefix/)) { my $suffix = $file; $suffix=~s{\A[^.]*}{}xms; print "^^^$suffix^^^","\n"; # print $suffix,"\n"; rename $dir . '/' . $file, $dir . '/' . $prefix . $suffix +; } } } ir('',$output_dir); here print prefix has underscore at the end of the line