TheDizzyDevil wrote:
> Hello everyone,
>
> I am new to Perl and I am just feeling my way around. I was hoping if
> someone could help me. I am trying to write a code that will search a
> document and return a suffix, specified by the user, and have that
> suffix in itallics. Below is the code I have thus far, but it does not
> seem to work with out numerous line errors. Can some please help?
>
Always get as much help as you can from perl - add
use strict;
use warnings;
Once you have done that , you will need to declare all your variables
using 'my'
When I did thjat and compiled I got
C:\develop\NiallPerlScripts>clpm13.pl
Substitution replacement not terminated at
C:\develop\NiallPerlScripts\clpm13.pl
line 15.
since this line
> $word=~ s/(.+?)$trag/$1<i>$trag<\/i>;
is missing a terminating slash - presumably you meant
$word=~ s/(.+?)$trag/$1<i>$trag<\/i>/;
I now have the following code
use strict;
use warnings;
my $b = 1;
print "What is your input file name:\n";
chomp(my $infile=<STDIN>);
open IN, $infile or die "No file, no fun!";
print "What is your output file name:\n";
chomp(my $outfile=<STDIN>);
print "What are you looking for:\n";
chomp(my $trag=<STDIN>);
open OUT, ">$outfile" or die "No file, no fun!";
while (<IN>) {
if (/$trag [?!'";: -]/) {
my $word=$_;
$word=~ s/.+ (.+?$trag)[?!'";: -]/$1/gi;
$word=~ s/.+? ([n] +?$trag)[?!'";: -]/$1/gi;
$word=~ s/(.+?)$trag/$1<i>$trag<\/i>;
print OUT "$outfile $word: $_";
}
$b++;
}
which compiles which your original version did not.
I can't really help you any further since I don't know what your sample
input looks like so I cannot tell whether this does what you want it to
do or not , but it does at least produce some output for me in this
format.
I gave it 'print' as the thing I was looking for , and a small perl
script as the input ansd I ended up with an output file containing the
following
C:\develop\NiallPerlScripts>more xxxxxxx
xxxxxxx <i>print</i> "\n1st = [$1]";
: print "\n1st = [$1]";
xxxxxxx <i>print</i> "\n2nd = [$2]\n";
: print "\n2nd = [$2]\n";
xxxxxxx <i>print</i> "\nNo match\n";
: print "\nNo match\n";
Hope this helps
|