Hello friends,
I am having a awk script which does my goal , but I want to learn perl , after learning the basics in perl now I am trying to convert my nawk script to perl .
Please help me to do some task in perl that I ve already did in nawk.
Like I am facing some problem in perl with $_, I think it is similar to $0 in nawk.
part of my perl code as follows
open(IN, $file)|| die("Could not open file");
while(<IN>) {
if($_ !~ /^"/){
if($_ =~ /^\*/){
}
else{
@fld = split(/,/, $_);
if( $fld[3] == 1 ){
print $_;
$binary1 = HexToBinary(substr($fld[0],0,2));
print $_;
}
}
}
}
sub HexToBinary{
my(%h)=( '0'=>'0000'
,'1'=>'0001'
,'2'=>'0010'
,'3'=>'0011'
,'4'=>'0100'
,'5'=>'0101'
,'6'=>'0110'
,'7'=>'0111'
,'8'=>'1000'
,'9'=>'1001'
,'A'=>'1010'
,'B'=>'1011'
,'C'=>'1100'
,'D'=>'1101'
,'E'=>'1110'
,'F'=>'1111'
);
$_=uc $_[0];
s/([0-9A-F])/$h{$1}/g;
return $_;
};
Although both the print statement seems to be same but gives me a different result. If i am not wrong incase of nawk we can print the current line anywhere with just typing
print $0
Regards,
user_prady