Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to merge the given snippet of code into the below functionality.

by davido (Cardinal)
on Feb 04, 2022 at 04:17 UTC ( [id://11141126]=note: print w/replies, xml ) Need Help??


in reply to How to merge the given snippet of code into the below functionality.

Something like this ought to work, though if it were me I would prefer providing the user with some context if I'm going to prompt them to remove an <alt> tag.

use IO::Prompt::Tiny q(prompt); sub remove_ok { my $prompt = 'Do you want to remove <alt> tags? (y/n)'; my $default = 'n'; my $resp = ''; while ($resp !~ m/^[yn]/i) { $resp = prompt($prompt, $default); } return $resp =~ m/^y/i; } sub RemoveAltTag { my $doc = shift; my $cnt = 0; my $nodes = $doc->getElementsByTagName("image"); for(my $i = 0;$i < $nodes->getLength(); $i++) { my $kids = $nodes->item($i)->getChildNodes(); for(my $k =0; $k < $kids->getLength(); $k++) { if( $kids->item($k)->toString() =~ /<alt>/i && remove_ok() ) { $nodes->item($i)->removeChild($kids->item($k)); print "\n Removed <alt> tag" if $VERBOSE; $cnt++ } } } return $cnt; }

But again, you might want to show some of the surrounding context so that the user can use that information in deciding what to remove.


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-03-28 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found