nani.nareshbabu:
OK, you have a specification. Now you just need to convert it to code and make it work.
- Take Hex file as an input.
So you want a file. That's going to mean you'll need to figure out the name of the file, and you'll have to open it (in read mode, based on your next step). So read perldoc -f open for information on how to open a file. I don't know how you want to determine the filename, so you'll have to do that, yourself. (You can hardcode the name into a variable, read it from an environment variable, the command line, another file, etc.)
- Read particular location in the file.
Since you're specifying "a hex file", I'm assuming that you mean a binary data file. So you'll also want to read perldoc -f binmode to make sure that the file isn't treated as a text file, perldoc -f seek and perldoc -f read to figure out how to read the location.
- Print the value present in that location.
I assume that you have a handle on this much, at least.
- Compare the value present in the location with the expected value. If both are marching print the pass result.
I assume you don't have a problem with this step.
- If value are not marching go range operation and find out the value is within +/- 10 rage of expected. If present print pass and print the value.
This is also a pretty trivial step, so again I'll assume you can do this on your own.
- Jump to other location in the file and perform the same operation.
OK, "perform the same operation" generally means that the same operation should be a subroutine. You'll need to tell the subroutine some basic information to do its job. Since it's doing something nearly the same, you need to figure out what the difference is, and figure out how to tell the subroutine what the differences are. You'll also need to figure out what the subroutine is going to do: Will it just pass back a result to the caller? Will it do a task and return nothing? Or with it do a combination of the two?
Normally, you give information to a subroutine by passing the information as arguments. I'd suggest passing the open file handle to the subroutine, along with other information you want. So read perlsub for information on how to create subroutines and pass parameters.
Since your specification is reasonable, you should be able to turn each of the steps into the appropriate code. Give it a whirl, and if you have any trouble, reply to this post with the code you've tried, and let us know what problem you had. If there's anything I glossed over too much, feel free to request some clarifications...
Note also that I've ignored error checking entirely. So when you read up on the various functions, be aware that they can fail. Then write code to detect and appropriately report any failures, so the rest of your program doesn't assume that all went well and cause problems later on in your program.
...roboticus