Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Match text from txt to html

by corfuitl (Sexton)
on Sep 04, 2019 at 14:42 UTC ( #11105601=note: print w/replies, xml ) Need Help??


in reply to Re^3: Match text from txt to html
in thread Match text from txt to html

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";

Replies are listed 'Best First'.
Re^5: Match text from txt to html
by marto (Archbishop) on Sep 04, 2019 at 14:46 UTC

    When open fails, get it to tell you why:

    open(my $fh, '<', $html) or die "cannot open file $html: $!";

    Trying to parse HTML like this is more often than not a waste of time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-12-14 10:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?