|
Posted by Ben Morrow on March 4, 2008, 11:15 am
Please log in for more thread options
>
> OK, thanks, but the script does not seem to rename the files.
> I added some troubleshooting code, most of which I commented out. I
> also moved a copy of the personalinjury folder and all its files
> inside the C:\Perl directory so it can access it directly.
Don't do that. You can set the working directory from within your Perl
script using the chdir function. In any case, the working directory may
not be what you expect under Win32.
> See below for my additional comments.
>
> #!/bin/perl
Perl is *never* installed as /bin/perl.
> #sleep 2;
> print "here I am! \n";
Diagnostics like this are better given with warn, which will .a. print
them to STDERR, where they ought to be and .b. tell you where you are in
the script.
> #sleep 2;
> my $counter =1;
>
> foreach my $file ( glob 'personalinjury/*.htm' ) {
>
> # print "here I am A \n";
> # sleep 1;
>
> open my $PI, '<', $file or die "could not open '$file' $!";
>
> # print "here I am! B \n";
> # sleep 1;
>
> print $counter;
> print "\n";
> while ( <$PI> ) {
> # print "\n inside whileloop";
>
> I AM getting to this point here.
>
> next unless /Citation: [\d-]+.*([\d.]+)/;
>
> but I never get to this point here--apparently the regex never sees a
> match for the "Citation:" etc string.
>
> Here is a screen shot of the typical file, with a red arrow pointing
> to the string in this particular file that I want to match.
> I do not know why the regex does not see a match, because it looks
> like it matches it???
>
> See here:
> http://img225.imageshack.us/img225/91/citationue2.jpg
*DON'T* do that. Had you done the right thing, and copy-pasted a small
section of the relevant file into your message, you would have found
that the file doesn't in fact contain the string 'Citation: whatever' at
all. It's an HTML file, so there is markup in there as well, and the
string may well be spread across several lines. Get into the habit of
looking at files in a text editor before you try parsing them with Perl.
> my $newfile = $1;
> rename $file, "$newfile.htm" or die "could not mv '$file' $!";
> print "\n renamed a file";
> sleep 1;
> last;
> }#end while
If you had used proper indentation, you would be able to see that
comments like this are completely useless.
Ben
|