syntax error near unexpected token `='

Hi all,
This is a script which converts hex to bin. However am finding an error while executing

syntax error near unexpected token `='

`($hexfile, $binfile) = @ARGV;'

I am running using ./fil.pl <hexfile> <binfile>

###################################################
#
#  this script takes hex representation and generates binary file
#
#  Syntax:  DP_HextoBin.pl <hex file> <bin file>


($hexfile, $binfile) = @ARGV;
open f1, "<$hexfile" or die $!;
open f2, ">$binfile" or die $!;
binmode f2;
$binOut = "";

while (<f1>)  {
   chop;
    
   if ($s =~ m/^0x[0-9a-f]{6}((\s[0-9a-f]{2}){1,16})/i)
   {
         $ss = $1;
          $ss =~ s/^\s+//;
          @arr = split(/\s+/, $ss);
          
          @arr1 = map pack("H2", $_), @arr;
          
          for my $hexv (@arr1) {
              print f2 $hexv;
          }
   } else {
          print "no matched";
   }
   
}

close(f1);
close(f2);

By just running ./fil.pl the script is not run by the Perl interpreter, but by the shell, which doesn't understand that syntax. You'll have to explicitly declare the interpreter in that case by adding a shebang line at the top:

#!/usr/bin/perl

(or wherever your Perl interpreter resides)

Thanks. It worked. However some problems in the regex, i believe. The above script converts hex value to bin. However I see "no matched " always. Could anyone please look in the above code.

I am attaching a sample input file.

The reason is simple. Your script expects the offset (0x...) and the data to be on the same line, which they aren't. You'll have to search for the offset value, then read the next line, and apply a second regex to it for the data contained.

BTW, it's advisable to chomp instead of chop.