migrateini.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #
  2. #
  3. #
  4. $verbose = 1;
  5. $listfile = $ARGV[0];
  6. die "no listfile specified" if ($listfile eq '');
  7. # parse listfile
  8. print "reading $listfile...\n" if ($verbose);
  9. open(INFILE, $listfile) || die "cannot open $listfile";
  10. @fnames = ();
  11. while (<INFILE>) {
  12. chomp;
  13. s/\r$//; # cygwin/mingw perl does not do CR/LF translation
  14. push(@fnames,$_);
  15. }
  16. #print join(' ', @fnames);
  17. %replacements = (
  18. # parameters
  19. "local_port" => "localPort",
  20. "dest_port" => "destPort",
  21. "message_length" => "messageLength",
  22. "message_freq" => "messageFreq",
  23. "dest_addresses" => "destAddresses",
  24. );
  25. foreach $fname (@fnames)
  26. {
  27. print "reading $fname...\n" if ($verbose);
  28. $txt = readfile($fname);
  29. # process $txt:
  30. foreach my $from (keys(%replacements)) {
  31. my $to = $replacements{$from};
  32. $txt =~ s/\b$from\b/$to/sg;
  33. }
  34. writefile($fname, $txt);
  35. #writefile("$fname.new", $txt);
  36. }
  37. sub readfile ()
  38. {
  39. my $fname = shift;
  40. my $content;
  41. open FILE, "$fname" || die "cannot open $fname";
  42. read(FILE, $content, 1000000);
  43. close FILE;
  44. $content;
  45. }
  46. sub writefile ()
  47. {
  48. my $fname = shift;
  49. my $content = shift;
  50. open FILE, ">$fname" || die "cannot open $fname for write";
  51. print FILE $content;
  52. close FILE;
  53. }