[Canberra-pm] here document perl script

Andrew Pollock andrew-pm at andrew.net.au
Thu Jun 8 20:31:30 PDT 2006


On Fri, Jun 09, 2006 at 01:26:11PM +1000, James Ring wrote:
> 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

Ye gods. At this point, you'd just stop using shell, it's clearly not the
tool for the job...

regards

Andrew


More information about the Canberra-pm mailing list