[Canberra-pm] here document perl script

James Ring sjr at jdns.org
Thu Jun 8 20:26:11 PDT 2006


Hi Kim

> Thanks, that works.  Now how do I put the results in an environment var?
>

I now know more about Bash than I ever wanted to... but this should work:

#!/bin/sh

x=$(
/usr/bin/perl - $@ <<'EOP'
use Socket;

my $ip = $ARGV[0];
my $addr = inet_aton($ip);
my $name = gethostbyaddr($addr,AF_INET);
my $ip2 = sprintf "%-20s", "[$ip]";
if ($name eq "") { $name = "not found"; }
my $begin .= $ip2 . $name;
print "$begin\n";
EOP
)

echo $x

The quotes around the here document name cause Bash to not perform
variable substitutions within the document, so pass $@ to Perl. Putting
the whole thing in x=$( ) seems to do the trick! :)

Regards,
James
-- 
James Ring



More information about the Canberra-pm mailing list