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