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.



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:

  #!/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.  I'd  wonder  why  you
would even bother with awk from a perl script.

Why not just assign the output of `/sbin/ifconfig | grep Bcast` to  a
perl  array,  and  do  the  rest of the job in perl?  You'll save two
processes, and get a lot more control of  the  results.   And  if  it
doesn't  work, you'll have an interactive debugger to help figure out
what went wrong.  (This latter point has long been one of  the  chief
arguments in favor of perl.)





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