D
Damien Mattei
i wrote a simple program that read data from STDIN but redirected in a
pipe from a file parse it and wrote output to STDOUT,here is the code:
#!/usr/bin/perl -w
# read the of ethernet vendor codes on STDIN
# and convert it in a 2 columns file
# with Ethernet code and constructor
# separator of output file is tab
use strict; # it's always better to be strict when coding ;-)
# split1line (read split first line)
# read this: 00-00-00 (hex) CORPORATION NAME
# return that: 000000 CORPORATION NAME
sub split1line() {
my @betwtab = split /\t/ , <STDIN>;
my @betwspc = split / / , $betwtab[0];
my @hexaddr = split /-/ , $betwspc[0];
my $vendor = $betwtab[2];
my $ethercode = $hexaddr[0] . $hexaddr[1] . $hexaddr[2] ;
return $ethercode . "\t" . $vendor ;
}
# skip the 6 first lines that do not contain any ethernet code
<STDIN>;
<STDIN>;
<STDIN>;
<STDIN>;
<STDIN>;
<STDIN>;
while (1) {
my $pair = split1line();
print $pair;
my $oneline;
# stop after the next empty line
while (($oneline = <STDIN>) && ($oneline !~ /^\n$/)) {
}
exit(0) if not defined $oneline;
}
it works like that:
cat ../var/oui.txt | ./preformat.pl
but when i try this:
cat ../var/oui.txt | ./preformat.pl > ../var/ieee_ethercodes.dat
Value of <HANDLE> construct can be "0"; test with defined() at
../preformat.pl line 56.
line 56 is this one : while (($oneline = <STDIN>) && ($oneline !~
/^\n$/)) {
the file oui.txt could be downloaded here:
http://standards.ieee.org/regauth/oui/oui.txt
i can, of course, modify the program to write directly the result in a
given file but i want to learn more about this strange error.
any help would be appreciated.
pipe from a file parse it and wrote output to STDOUT,here is the code:
#!/usr/bin/perl -w
# read the of ethernet vendor codes on STDIN
# and convert it in a 2 columns file
# with Ethernet code and constructor
# separator of output file is tab
use strict; # it's always better to be strict when coding ;-)
# split1line (read split first line)
# read this: 00-00-00 (hex) CORPORATION NAME
# return that: 000000 CORPORATION NAME
sub split1line() {
my @betwtab = split /\t/ , <STDIN>;
my @betwspc = split / / , $betwtab[0];
my @hexaddr = split /-/ , $betwspc[0];
my $vendor = $betwtab[2];
my $ethercode = $hexaddr[0] . $hexaddr[1] . $hexaddr[2] ;
return $ethercode . "\t" . $vendor ;
}
# skip the 6 first lines that do not contain any ethernet code
<STDIN>;
<STDIN>;
<STDIN>;
<STDIN>;
<STDIN>;
<STDIN>;
while (1) {
my $pair = split1line();
print $pair;
my $oneline;
# stop after the next empty line
while (($oneline = <STDIN>) && ($oneline !~ /^\n$/)) {
}
exit(0) if not defined $oneline;
}
it works like that:
cat ../var/oui.txt | ./preformat.pl
but when i try this:
cat ../var/oui.txt | ./preformat.pl > ../var/ieee_ethercodes.dat
Value of <HANDLE> construct can be "0"; test with defined() at
../preformat.pl line 56.
line 56 is this one : while (($oneline = <STDIN>) && ($oneline !~
/^\n$/)) {
the file oui.txt could be downloaded here:
http://standards.ieee.org/regauth/oui/oui.txt
i can, of course, modify the program to write directly the result in a
given file but i want to learn more about this strange error.
any help would be appreciated.