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

another variation:
my @array = qw(01 42 62 00 01); print pack 'H2' x @array, @array;

Replies are listed 'Best First'.
Re^3: hex escape Question
by mfawbush (Initiate) on Jul 28, 2015 at 18:31 UTC

    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";
      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" }

      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"));