in reply to Print array, splitting into 2 strings
my @array = qw[ binary_app=/usr/bin/true config_file=/etc/inetd.conf MOD_NAME="ABC" ];; print qq[<input type=text name="$_->[0]" value="$_->[1]">\n] for map{ [ split '=' ] } @array;; <input type=text name="binary_app" value="/usr/bin/true"> <input type=text name="config_file" value="/etc/inetd.conf"> <input type=text name="MOD_NAME" value=""ABC"">
Though browsers probably won't like the doubled, doublequote value in the last line. If pre-quoted values are a part of the data, you might need something like:
(Updated to correct C&P error).
print qq[<input type=text name="$_->[0]" value="$_->[1]">\n] for map{ [ m[^([^=]+)=["']?(.*?)["']?$] ] } @array;; <input type=text name="binary_app" value="/usr/bin/true"> <input type=text name="config_file" value="/etc/inetd.conf"> <input type=text name="MOD_NAME" value="ABC">
Of course, if the values can contain quotes of either form, or you need to retain the quotes around the values, then you might get away with something like
print qq[<input type=text name="$_->[0]" value="$_->[1]">\n] for map{ [ map{ tr["][']; $_ } split '=' ] } @array;; <input type=text name="binary_app" value="/usr/bin/true"> <input type=text name="config_file" value="/etc/inetd.conf"> <input type=text name="MOD_NAME" value="'ABC'">
Or you might have to get more sophisticated, or use an HTML or templating module.
|
|---|