Rename Tool (UNIX To DOS)
Rename Tool (UNIX To DOS)
- @ARGV is an array
- each argument passed should be a filename
- Since a local scoped variable not declared, $_ is used by default
- $_ is assigned to $currentname to preserve original filename
- The substitution process modifies special variable $_
- Notice we take up to the first eight characters that isn’t a period and assign that to special positional parameter \1
- $_ becomes the value of \1 with the .txt suffix appended.
#!/usr/local/bin/perl
foreach ( @ARGV )
{
$currentname=$_;
s/([^.]{1,8})(.*)$/\1.txt/;
rename ($currentname, $_);
}
pattern_match
for \1
new_string
\2