Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dblcr2cr.pl

(view source code of dblcr2cr.pl as plain text)

  1. #! perl
  2.  
  3. # Store on screen help text in a variable
  4. $syntax = "\nDblCr2Cr.pl, Version 1.00\n";
  5. $syntax = $syntax."Replace double CR/LF pairs (0D0Ax) by single pairs\n\n";
  6. $syntax = $syntax."Usage:  DBLCR2CR.PL [ infile [ outfile ] ]\n";
  7. $syntax = $syntax."or:     any_command | PERL.EXE DBLCR2CR.PL > outfile\n";
  8. $syntax = $syntax."or:     DBLCR2CR.PL /?\n\n";
  9. $syntax = $syntax."Where:  \"any_command\"  is a command that's standard output is used\n";
  10. $syntax = $syntax."                       instead of \"infile\"\n";
  11. $syntax = $syntax."        \"infile\"       is an ASCII file with double line terminations\n";
  12. $syntax = $syntax."                       (default: standard input)\n";
  13. $syntax = $syntax."        \"outfile\"      is the corrected ASCII file\n";
  14. $syntax = $syntax."                       (default: standard output)\n\n";
  15. $syntax = $syntax."Written by Rob van der Woude\n";
  16. $syntax = $syntax."http://www.robvanderwoude.com\n";
  17.  
  18. # Help required?
  19. if ( @ARGV[0] eq "/?" ) {
  20. 	die $syntax;
  21. }
  22.  
  23. # Use source file as standard input if specified
  24. if ( @ARGV[0] ) {
  25. 	open( STDIN, "< @ARGV[0]" ) || die "Cannot open file @ARGV[0]:\n$!\n\n$syntax";
  26. }
  27.  
  28. # Use target file as standard output if specified
  29. if ( @ARGV[1] ) {
  30. 	open( STDOUT, "> @ARGV[1]" ) || die "Cannot open file @ARGV[1]:\n$!\n\n$syntax";
  31. }
  32.  
  33. # Switch to slurp mode
  34. undef $/;
  35.  
  36. # Search and replace standard input and write to standard output
  37. while ( <STDIN> ) {
  38. 	$line = $_;
  39. 	$line =~ s/\n\n/\n/g;
  40. 	print $line;
  41. }
  42.  
  43. # Close "file" handles
  44. close( STDIN  );
  45. close( STDOUT );
  46.  

page last modified: 2024-04-16; loaded in 0.0060 seconds