We don't bite newbies here... much | |
PerlMonks |
Using s/// Inlineby Jason Hutchinson (Acolyte) |
on Nov 16, 2009 at 16:04 UTC ( [id://807498]=perlquestion: print w/replies, xml ) | Need Help?? |
Jason Hutchinson has asked for the wisdom of the Perl Monks concerning the following question: I'm currently doing work on a Perl SDK for an HTTP API, and have hit a bit of a stumbling block with s///. The API takes XML for input, and when adding or updating fields it will accept either the numeric field identifier or a formatted version of the field label/field name. For the formatting, the field name would be "Field Name" and the reformatted version would be "field_name". Because it's an API I'd like to do that reformatting transparently, so the end user just has to type in the field name they want to use. I'm using the s/// regexp to do the formatting, but I'm in a situation where I'd like to use it inline but it only returns the number of substitutions performed. Is there any way to use the s/// inline and return the substitution's results? Here's the code I'm using:
And here's how it would be used: add_record({"Field Name"=>"Field Value"})
Back to
Seekers of Perl Wisdom
|
|