At 07:11 -0800 05/02/2011, zavierz wrote:

Here's code which was suggested to me, but when I execute it I'm
returned to the command line and nothing happens:

#!/usr/bin/perl
s/^(Article\s+[0-9]+\s+\N*\S)/\\subsection*{$1}/gm

I called this script "Article" and saved it as article.pl


The usage then was $perl article.pl oldfile.tex newfile.tex


What was "suggested to you" is simply a substitution; it can't do anything unless it has something to do it to.

Your command gives two arguments (@ARGV, or, if you like, $ARGV[0], $ARGV[1]) to your script but the script itself makes no reference to these arguments and they are completely ignored.

You need to open your in-file (oldfile.tex = $ARGV[0] => $fin) for reading and open/create your out-file for writing (newfile.tex = $ARGV[1] => $fout). Each line you read from $fin in the while loop becomes $_ and you do the substitutions before writing it to $fout.


#!/usr/bin/perl
use strict;
my ($fin, $fout) = @ARGV;
open FIN, $fin;
open FOUT, ">$fout";
while (<FIN>) {
  s/^( Article \s+ [0-9]+ .* \S )
  /\\subsection*{$1}/gmx;
  print FOUT;
   #  + if you want to see what you've written
   # displayed in terminal/console:
  print STDOUT;
}

# JD

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to