From: Tad McClellan on
Don Pich <dpich(a)polartel.com> wrote:

> open( INFILE, "< $infile" ) or die "Can't open $infile : $!";


Using the 3-arg form of open() is much safer.

Using lexical filehandles is also a good idea.

Putting some delimiters around the filename in the die message
will be helpful if whitespace should ever sneak into the filename.

So that should be:

open( my $INFILE, '<', $infile ) or die "Can't open '$infile' $!";


> while ($line = <INFILE>){


while ($line = <$INFILE>) {


> my $IP = '';
> my $Address = '';
> my $Name = '';
> my $mac = '';
> my $type = '';
> my $J6 = '';
> my $J7 = '';
> my $J8 = '';
> my $J9 = '';
> my $J10 = '';
> my $J11 = '';
> my $J12 = '';
> my $J13 = '';
> my $J14 = '';
> my $J15 = '';
> my $J16 = '';
> ($IP,$Address,$Name,$mac,$type,$J6,$J7,$J8,$J9,$J10,$J11,$J12,$J13,
> $J14,$J15,$J16) = split '\t',$line;


Replace those 17 lines of code with 1 line of code:

my($IP) = split /\t/, $line;

since you never make use of the other 15 variables.


> Here is the input file 'Pannaway.txt':


You should use the __DATA__ filehandle when posting file
contents to newsgroups.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
From: Don Pich on
Alright,

Here is my shortened script:

#!/usr/bin/perl
use strict;
use warnings;
my $infile = 'Pannaway.txt';
my $outfile = 'BASIP.list';
my $line = '';
open( my $INFILE, '<', $infile ) or die "Can't open '$infile' $!";
open( OUTFILE, "> $outfile" ) or die "Can't open $outfile : $!\n";
while ($line = <$INFILE>) {
my($IP) = split /\t/, $line;
foreach my $val (@value) {
$val = sprintf("%02x", $val);
printf OUTFILE $val;
}
}
close (INFILE); close (OUTFILE);

But it doesn't run because of:

Global symbol "@value" requires explicit package name at ./convertX.pl
line 12.
Execution of ./convertX.pl aborted due to compilation errors.
From: John Bokma on
Tad McClellan <tadmc(a)seesig.invalid> writes:

> Don Pich <dpich(a)polartel.com> wrote:
>
>> open( INFILE, "< $infile" ) or die "Can't open $infile : $!";
>
>
> Using the 3-arg form of open() is much safer.
>
> Using lexical filehandles is also a good idea.
>
> Putting some delimiters around the filename in the die message
> will be helpful if whitespace should ever sneak into the filename.

I also prefer to add what I tried to do (for reading):

.... or die "Can't open '$infile' for reading: $!";

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
From: Don Pich on
Tad,

Current Script:

#!/usr/bin/perl
use strict;
use warnings;
my $infile = 'Pannaway.txt';
my $outfile = 'BASIP.list';
my $line = '';
open( my $INFILE, '<', $infile ) or die "Can't open '$infile' $!";
open( OUTFILE, "> $outfile" ) or die "Can't open $outfile : $!\n";
while ($line = <$INFILE>) {
my(@IP) = split /\t/, $line;
foreach my $val (@IP) {
$val = sprintf("%02x", $val);
printf OUTFILE $val;
}
}
close (INFILE); close (OUTFILE);

Source File (snippet):
10.20.150.252 STTM.12.01 BAS-ADSL16R 00:0A:9F:40:71:D3
3.2.1.28
10.20.150.250 STTM.13.01 BAS-ADSL16R 00:0A:9F:40:71:DF
3.2.1.28
10.20.151.252 STTM.14.01 BAS-ADSL16R 00:0A:9F:40:71:CD
3.2.1.28
10.20.151.250 STTM.15.01 BAS-ADSL48R 00:0A:9F:40:67:05
3.2.1.28
10.20.151.248 STTM.16.01 BAS-ADSL48R 00:0A:9F:40:6D:19
3.2.1.28
10.20.145.252 STTM.41.01 CO BAS-ADSL48R 00:0A:9F:40:67:15
3.2.1.28
10.20.145.250 STTM.41.02 CO BAS-ADSL48R 00:0A:9F:00:E5:72
3.2.1.28
10.20.128.29 STTM.BAR.01 BAR-GE12 00:0A:9F:50:0D:38
02.02.00.22
10.20.128.22 STTM.BAR.02 BAR-GE12 00:0A:9F:50:5E:E9
02.02.00.22 :

Desired output:

convert the IP into a quad hex form.

I ran the application by inputing "perl file.pl"
From: sln on
On Thu, 04 Mar 2010 10:17:04 -0600, Don Pich <dpich(a)polartel.com> wrote:

>Here is my script:
>
>** Notice the extra line after 0a1491fa
>
>I realize that after the field "IP" is converted to hex, it gets out of
>the "foreach" loop and then prints the carriage return to start the next
>line in the file. Can I redo this script to not have it create that last
>carriage return? Can I place it in another spot so that it doesn't
>create the extra blank line?

What makes you think there is an extra line after 0a1491fa ??
Newline is the same character appended to each ip string, its part of
the IP string isin't it?

Without it, you don't know where a valid end of the IP string is.

-sln