in reply to Re^2: hex escape Question
in thread hex escape Question

I was trying to capture it something like this:

my $sfreq=<STDIN>; #014.262.00 my ($Mhz,$Khz,$hz)=split(/\./,$sfreq); my $h1=substr($Mhz,0,2); #h1=pack('H*',$h1); my $h2=substr($Mhz,2,1).substr($Khz,0,1); #$h2=pack('H*',$h2); my $h3=substr($Khz,1,2); #$h3=pack('H*',$h3); my $h4=substr($hz,0,2); my $hfreq="$h1$h2$h3$h4";

Replies are listed 'Best First'.
Re^4: hex escape Question
by Monk::Thomas (Friar) on Jul 29, 2015 at 06:08 UTC
    Recommendation - It is safer to do the initial split like this:
    if ($sfreq =~ /^(\d)[.](\d)[.](\d)$/) { my $MHz = $1; my $KHz = $2; my $hz = $3; # rest of code } else { die "Sorry, invalid input. Please use format '<MHz>.<KHz>.<Hz>'.\n" }
Re^4: hex escape Question
by mfawbush (Initiate) on Jul 29, 2015 at 02:35 UTC

    I must apologize, the problem wasn't with the hex, but on the serial side. Thank you for the help, at least you all cleared up the my confusion on the hex side.

    my $sfreq=<STDIN>; $sfreq=~ s/\.//g; $port->write(pack("H*",$sfreq."01"));