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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.