Hi,
I've messed up my file names on NT when tar'd them from Solaris. I packed them on NT, then I unpacked the tar file back on Solaris, all the files are lower-cased. I have writen each of my file name at the begening of the file, take an example for vincrement.java, as you can see, it should be named as VIncrement.java, instead:
/* VIncrement.java */
package com.dot.ext.math;
import com.dot.lex.objects.*;
import com.dot.project.*;
import com.dot.lex.engine.*;
import com.dot.utils.*;
/**
* The increment verb increments a number object by one.
*/
public class VIncrement extends VVerb implements VerbI
{
// ...
}
Now I want to do the reverse engineering for my whole file structures with Perl. I'd like the perl program will read only the first line of each file, and rename the current file to the correct one. Can I use find() like this?
Many thanks,
Michael
#!/usr/bin/perl
use File::Find;
sub change {
if( -f && /\.java$/ ) {
my $in = $_;
#How Can I Get only the first line and filt out the /* */?
my $out = ???;
open( IN, $in ) or die;
open( OUT, ">$out" ) or die;
close IN;
close OUT;
rename( $out, $in );
}
}
my @dirs = qw(.);
if ($#ARGV+1 == 2) {
find ( \&change, @dirs );
}else {
print "Usage: !";
exit;
}
I've messed up my file names on NT when tar'd them from Solaris. I packed them on NT, then I unpacked the tar file back on Solaris, all the files are lower-cased. I have writen each of my file name at the begening of the file, take an example for vincrement.java, as you can see, it should be named as VIncrement.java, instead:
/* VIncrement.java */
package com.dot.ext.math;
import com.dot.lex.objects.*;
import com.dot.project.*;
import com.dot.lex.engine.*;
import com.dot.utils.*;
/**
* The increment verb increments a number object by one.
*/
public class VIncrement extends VVerb implements VerbI
{
// ...
}
Now I want to do the reverse engineering for my whole file structures with Perl. I'd like the perl program will read only the first line of each file, and rename the current file to the correct one. Can I use find() like this?
Many thanks,
Michael
#!/usr/bin/perl
use File::Find;
sub change {
if( -f && /\.java$/ ) {
my $in = $_;
#How Can I Get only the first line and filt out the /* */?
my $out = ???;
open( IN, $in ) or die;
open( OUT, ">$out" ) or die;
close IN;
close OUT;
rename( $out, $in );
}
}
my @dirs = qw(.);
if ($#ARGV+1 == 2) {
find ( \&change, @dirs );
}else {
print "Usage: !";
exit;
}