Hi,
This is actually more of a design question. I'm using XML::XPath to do some simple XML parsing and writing. I have the following subroutine:
sub createPath { my $path = shift; if ($xp->exists($path)) { print "Path already exists, overwrite element (N/Y): "; my $response = <STDIN>; chomp($response); unless (lc($response) eq 'y') { print "Path creation call will be ignored\n"; return 0; } } print "Creating node..."; $xp->createNode($path) or die "Could not create node: $!"; }
See the obvious problem (that I missed to begin with, somehow)? The 'print "Creating node...";' statement will never be reached. Can anyone think of an elegant way (that actually works :) to rewrite this without having to widen the scope of $response by moving the unless out of the if block? Or would I be best off just to do that?
Also, about the lines my $response = <STDIN>; chomp($response); I'm sure there's a way to write this in one statement, but I've sadly forgotten. Can anyone remind me?
Thanks :)
In reply to XML::XPath path creation problem by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |