Jack Gates wrote:
These first four lines are how every Perl script I write starts.

#!/usr/bin/perl -T
use strict;
use warnings;
use diagnostics -verbose;

my ($oldfile) = $ARGV[0] =~ /^([-a-zA-Z0-9._\/]+)$/;
die "bad old filename" unless $oldfile;

my ($newfile) = $ARGV[1] =~ /^([-a-zA-Z0-9._\/]+)$/;
die "bad new filename" unless $newfile;

open my $OF, "<", $oldfile or die "$oldfile: $!";
open my $NF, ">", $newfile or die "$newfile: $!";

my $letter = $& =~ /(?<=\<h1><)[a-z]{1,1}/;

while (my $line = <$OF>) {
my $navold = '<a href="../man0p_a">Man(0p) a';
my $navnew1 = '<a href="../man0p_';
my $navnew2 = '">Man(0p) ';
my $navnew3 = $navnew1 . $letter . $navnew2 . $letter;
    $line =~ s/$navold/$navnew3/g; # replace string
    print $NF $line;
}

close($OF);
close($NF);


I have read perlsyn, perldata, perlsub, perlop, perlfunc, perlvar, perlre, perlreref and perlref several times.

I am sure I have read exactly what I need to but I just don't seem to be able to see it or understand it.

I have messed around with this line several different ways

my $letter = $& =~ /(?<=\<h1><)[a-z]{1,1}/;

Perl does not complain but it does not do anything
I could use help understanding how to do this so it will work

In the example above that line is equivalent to:

my $letter = substr( $ARGV[1], $-[0], $+[0] - $-[0] ) =~ /(?<=\<h1><)[a-z]/;

Or simply:

my $letter = $ARGV[1] =~ /(?<=\<h1><)[a-z]/;


In scalar context the match operator returns either 'true' or 'false' so $letter will be assigned either '1' or ''.




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to