[PLUG] Perl question

David Fleck david.fleck at mchsi.com
Sun Dec 28 16:12:02 UTC 2003


On Sun, 28 Dec 2003, Russell Evans wrote:
> This is the first time I have done anything in perl so what some feed
> back. I know I want to test @ARGV for format but haven't gotten that
> far. My real reason for asking is I wanted to do
>
> foreach $IP (@ARGV) {
>  print "$IP\t";

What are you trying to do in the next two lines?

>  $IP =~ s/./,/g;
>  printf ("%02X%02X%02X%02X\n",$IP);
> }
>
> but that has issues. So is there a better, more correct, way to do this?
> be considered a better form if this is a good way to do it?

Well, like perl people say, there's more than one way to do it... Your
final example seems fine,  the only changes that spring to mind would be
something like this:

#!/usr/bin/perl -w
#
use strict;
while (my $IP = shift) {
  print "$IP\t";
  printf ("%02X%02X%02X%02X\n",split(/\./, $IP));
}


--
David Fleck
david.fleck at mchsi.com





More information about the PLUG mailing list