in reply to Edit values in XML and Save?

...Or of course, if you're *just* reading in the file, adding 10, then writing out again...
use File::Slurp; my $s = read_file("test.xml"); $s =~ s/(<number>)(\d+)(</number>)/$1.($2 + 10).$3/eg; write_file("test.xml",$s);
I know it avoids all the fun and overhead of a *real* XML parser, but isn't that part of the point of making XML human-readable - for quick Perl-hack purposes? <g> Thanks mirod...<g>

Replies are listed 'Best First'.
Re: Re: Edit values in XML and Save?
by Cody Pendant (Prior) on Mar 06, 2003 at 00:27 UTC
    Thanks all of you.

    benn, trust me, that's the way I always want to do it. I'm forcing myself to do it the Proper Way. But, you might need to tweak the regex to take into account optional whitespace, right?
    --

    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D