Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to store data in 32 bit wide array location in Perl ?

Status
Not open for further replies.

gold_kiss

Full Member level 4
Full Member level 4
Joined
Sep 11, 2002
Messages
211
Helped
7
Reputation
14
Reaction score
4
Trophy points
1,298
Activity points
1,789
Perl script help

Ok I am reading a binary file and storing its content into a variable.
I am doing it in this way

open BIN_FILE (" my.bin")

while (<BIN_FILE>)
{
my_bin .= $_;
}

so my_bin has got entire contents of my.bin file

What I need to do is to store these contents in an 32 bit wide array locations.

Can any one help me with this.

Cheers,
Gold_kiss
 

Re: Perl script help

open BIN_FILE,"<my.bin" or die "Can't find input file";
binmode BIN_FILE; # turn off cr/lf translation (only actually does anything on windows)
undef $/; # make reads slurp the whole file
@dataarray = unpack("i*",<BIN_FILE>); #decode the data; change the i to whatever format you have
$/ = "\n"; # turn slurping off

You'll have to be careful to get the correct pack/unpack format letter; if you're not sure what to use, create the binary file using another perl script and pack() using the same format letter used by unpack()

HTH
barny
 

Re: Perl script help

Hi,
Thanks for your replies, here is a solution that I made use of ..

unless (open (INREAD, "input.dat"))
{
die (" YOU HAVE NOT PROVIDED A BIN FILE\n");
}

read(INREAD, $all, 32, 0);
close INREAD;
$i =0;
foreach (split(//,$all)) {
$array[$i] = ord($_);
printf OUT ("%02x",$array[$j]);
$i++;

}


Thanks,
Gold_kiss
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top