$check ="ABCD" # this value will come from an array # ... $var = substr($file_name, 0, 3); # ... if($var eq $check){
I don't think the condition could ever be possibly satisfied. Also, I wouldn't use non-descriptive variable names like $var and $newvar.
Is this approach correct way
More or less so. But your requirements are slightly sloppy and in particular there's a discrepancy between the description of the task and what the code more or less does, but if I understand them correctly, then I'd do something along the lines of:
sub scandir { my $dir=shift; my $test=join '|', map quotemeta, @_; chdir $dir; for (glob '*') { next unless /^($test)(.*)/; my $new="$1D$2"; print "`$_' => `$new'\n"; if (-e $new) { warn "Warning: `$new' exists\n"; # or do something more complex... next; } else { rename $_, $new or die "Can't rename to `$new': $!\n"; } } }
In reply to Re: FileName Change
by blazar
in thread FileName Change
by mantra2006
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |