Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stupid perl question.



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





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org