Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Match text from txt to html

by talexb (Canon)
on Sep 04, 2019 at 13:41 UTC ( #11105592=note: print w/replies, xml ) Need Help??


in reply to Match text from txt to html

Lots of ideas! But first, tell us what you've tried in Perl.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Replies are listed 'Best First'.
Re^2: Match text from txt to html
by corfuitl (Sexton) on Sep 04, 2019 at 13:48 UTC

    Hi,

    Thank you for your reply.

    To be honest, I have no idea... I know Perl but I don't know where to start.

    What I did, was to read the TXT and store it in an array, then I read line by line the HTML and match the sentences without tags.

      Great! And is the code working correctly? (Quietly loads the confetti cannon.)

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

        this is my code as of now.

        #!/usr/bin/perl use warnings; my $html = shift; my $htmlvar; open(my $fh, '<', $html) or die "cannot open file $html"; { chomp; local $/; $htmlvar = <$fh>; } close($fh); my $line = 1; while (<STDIN>){ chomp; if ($htmlvar =~ /$_/ && $htmlvar !~ /<sentence id\"[0-9]*\">$_<\/ +sentence>/){ $htmlvar =~ s/($_)/<sentence id\"$line\">$1<\/sentence>/; $line++ } } print "$htmlvar\n";

        Thanks! I am opening the html this way as I don't know the nodes of the files. the created automatically, so this is why I am reading them as text.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11105592]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2021-01-25 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?