in reply to no output

I'm curious about something.

First, you slurp in the XML document:

{ local $/ = undef; $xml = <XML>; };

then later, you do a search/replace globally on the entire stringified file:

$xml =~ s/hostname/$hostname/g; $xml =~ s/interface/$interface/g;

What that does on first pass, is replace *all* instances of 'hostname' and 'interface' with the first instance of $hostname and $interface. Without seeing the XML template, it's hard to guess if this is what you want.

Why don't you explain what you're trying to achieve here? It's really not all that clear from what you've provided... are you trying to print out a new file *per host*? That would make the above make sense.

Replies are listed 'Best First'.
Re^2: no output
by DieringerC (Initiate) on Apr 06, 2016 at 20:46 UTC

    First thanks for the quick responses; I have a csv file with hosts in on column and their IP address in the second. CSV format:

    FTC-R17N6340-C04-1;10.1.70.1 FTC-R17N6340-C04-2,10.1.70.2 FTC-R17N6340-C04-3,10.1.70.3
    My XML template has two instances of hostname that need to be replaced with the first collumn and one instance of ILO being replaced by the IP address. XML:
    <host> <host>hostname</host> <name>hostname</name> <description/> <proxy/> <status>0</status> <ipmi_authtype>-1</ipmi_authtype> <ipmi_privilege>2</ipmi_privilege> <ipmi_username/> <ipmi_password/> <tls_connect>1</tls_connect> <tls_accept>1</tls_accept> <tls_issuer/> <tls_subject/> <tls_psk_identity/> <tls_psk/> <templates/> <groups> <group> <name>C7000 Chassis</name> </group> </groups> <interfaces> <interface> <default>1</default> <type>1</type> <useip>1</useip> <ip>ILO</ip> <dns/> <port>10050</port>
    After the text is replaced I want the template with the new host information appended to the XML file but leaving the template intact ready for the second line.

      So you are using a template file to render an output file. Use HTML::Template. Despite the name it's a general purpose templating system that does well and consistently what you are trying to do.

      Premature optimization is the root of all job security