stupid perl question.

Frank J.Ramsay fjr at marsdome.myip.org
Sun Nov 11 11:12:20 EST 2001


On Sunday 11 November 2001 10:19, John Chambers wrote:
> Frank J.Ramsay asks:
> | Why doesn't this work?
> | What it's doing up dumping the output to the console and not assigning it
> | to $ipaddy.
> |
> | #!/usr/bin/perl
>
> Are you sure?  I changed it slightly, to:
Yea, I pretty sure I tried it with the print commented out and still got the 
data on the screen.

>   #!/usr/bin/perl
>   my $ipaddy = `/sbin/ifconfig | grep Bcast | sed \'s/:/ /g\' | awk
> \'{print $3}\'`; chomp $ipaddy;
>   print "ipaddy=\"$ipaddy\"\n";
>
> This puts some text around the value of $ipaddy so I can verify  that
> it comes from the perl script.  What I get on my linux box is:
>
> ipaddy="          inet addr 127.0.0.1  Bcast 127.255.255.255  Mask
> 255.0.0.0 inet addr 209.6.184.54  Bcast 255.255.255.255  Mask 255.255.252.0
> inet addr 192.168.1.17  Bcast 192.168.1.255  Mask 255.255.255.0"
>
> This makes it clear that the output of awk is ending up  in  $ipaddy.
> What  puzzles  me is why awk gives the value that it does.  But then,
> awk has always been somewhat of a random tool.  

Yea, that is odd, because on the command line both the way I originally had 
the command, and this way print just the IP address...

> I'd  wonder  why  you
> would even bother with awk from a perl script.

Well it worked from the command line... and I don't use perl often enough to 
do much without a book nearby for reference (and all my perl books are at the 
office.  But it looks like I'll have to remember the syntax for doing it in 
perl.

Thanks.

			-fjr




More information about the Discuss mailing list