in reply to How to rename the files its directory structure using perl?

Run this

sub runDir($$) { my $prefix = shift @_; print '*'.$prefix,"\n"; my $dir = shift @_; print "**$dir*","\n"; opendir(DIR, $dir) or die $!; my @entries = readdir(DIR); # print @entries,"\n"; close(DIR); foreach my $file (@entries) { next if ($file =~ /^\.+$/); if ( -d $dir . '/' . $file) { print "***down runDir($prefix . $file . '_', $dir . '/' . +$file)\n"; runDir($prefix . $file . '_', $dir . '/' . $file); print "***up runDir($prefix . $file . '_', $dir . '/' . +$file)\n"; } elsif ( ( -f $dir . '/' . $file ) && ( $file =~ /\.config$/ +) && ($file !~ /^$prefix/)) { my $suffix = $file; $suffix =~ s/^(\S+)-.+\.config$/$1.config/; print "****rename $dir . '/' . $file, $dir . '/' . $prefix + . $suffix"."\n"; # rename $dir . '/' . $file, $dir . '/' . $prefix . $suffi +x ; } } }
and i bet it will become clear

Replies are listed 'Best First'.
Re^2: How to rename the files its directory structure using perl?
by finddata (Sexton) on Mar 15, 2017 at 06:12 UTC
    following error: main::runDir() called too early to check prototype at ./generate.pl line 296.

      kill the prototypes!!!!!!!!!!! change this

      sub runDir($$); sub runDir($$) {
      to this
      sub runDir {
      you dont know what they are doing anyway

      ok changed my mind too run this

      sub runDir { my $prefix = shift @_; print '*'.$prefix,"\n"; my $dir = shift @_; print "**$dir*","\n"; opendir(DIR, $dir) or die $!; my @entries = readdir(DIR); # print @entries,"\n"; close(DIR); foreach my $file (@entries) { next if ($file =~ /^\.+$/); if ( -d $dir . '/' . $file) { print '***down runDir -- '.$prefix . $file . '_'.','. $dir + . '/' . $file."\n"; runDir($prefix . $file . '_', $dir . '/' . $file); print '***up runDir -- '.$prefix . $file . '_'.','. $dir +. '/' . $file."\n"; } elsif ( ( -f $dir . '/' . $file ) && ( $file =~ /\.config$/ +) && ($file !~ /^$prefix/)) { my $suffix = $file; $suffix =~ s/^(\S+)-.+\.config$/$1.config/; print '****rename '.$dir . '/' . $file.','. $dir . '/' . $ +prefix . $suffix ."\n"; # rename $dir . '/' . $file, $dir . '/' . $prefix . $suffi +x ; } } }
      dayum i hate double quotes a lot.

        But the above code change we cant get the expected output.you just remove the prototype .I couldnt see any other changes which you have done.