in reply to Re: hiccoughing here documents
in thread hiccoughing here documents
Something like this works:
sub IFACE { my $pattern = shift @_; my $result; foreach $iface (@_) { $result .= (eval "\"$pattern\"") . "\n"; } chomp $result; return $result; } &utter( <<"EOF" ); iptables -t nat -N outbound-DMZ @{[ &IFACE( "iptables -t nat -A outbound-DMZ -s $lanCidr -o \$iface -j SNAT --to +-source $dmzIp", (keys %ipAddress)) ]} iptables -t nat -A outbound-DMZ -j RETURN EOF
I know it's unconventional but I've capitalised the function name to emphasise its relationship to the name of the variable being interpolated, I felt that trying to pass that name as a parameter would be pushing my luck. It's (obviously) very sensitive to the double-quotes being correct, both in the function and in the heredoc itself. The one thing I wasn't able to get working was ~ to enable indents (5.20.2 on Debian Jessie armhf), but that's a fairly detail since the nearer the heredoc is to the actual stuff going into the tables the better.
Many thanks to everybody, especially NetWallah.
Pax vobiscum, MarkMLl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: hiccoughing here documents
by AnomalousMonk (Archbishop) on Aug 14, 2017 at 18:48 UTC |