John H. Robinson, IV wrote:
> I should have gone to bed hours ago.

No, really, I should have. Now that the cat has left my lap, I may be
able to. Yay!

> perl -e'print qx(/sbin/ifconfig eth0)=~/t addr:([^ ]*)/?"$1\n":"No match.\n"'

Looks like we all get caught up in our habits. I kept using qx() when I
could have used `` and saved two characters. Let's assue that there will
be no IPV6 address if there is no IPV4 one, and reduce the RE while we
are at it. Looking closer at the ifconfig manpage, we don't need any
options!

perl -e'print"$1\n"if`/sbin/ifconfig`=~/r:([^ ]*)/'

Three when we count the space we no longer need after the if. Closing up
the spaces around the "$1\n" saves us two more spaces, and reduces
readability even more!

If we are trying to remove all spaces, we can change the RE to the
following but it makes it longer. I hate it when that happens.

perl -e'print"$1\n"if`/sbin/ifconfig`=~/r:([\d.]*)/'

If only we could assume that /sbin was in our $PATH . . .

-john

PS: ip is the new way of doing things, and ifconfig is considered
deprecated, at least as far as Linux is concerned.

perl -e'print"$1\n"if`/sbin/ip addr show eth0`=~/inet ([\d.]*)/'

If you hate spaces as much as I do:

perl -e'@a=("/sbin/ip",addr,show,eth0);print"$1\n"[EMAIL PROTECTED]/inet 
([\d.]*)/'

Too many ways of doing things in perl. Perhaps we should ask ourselves
``what would Guido van Rossum do?''

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to