CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Unpack - bad result (from file)

 



waltz
Novice

Oct 5, 2011, 5:53 AM

Post #1 of 2 (741 views)
Unpack - bad result (from file) Can't Post

Hi,

what is wrong on code bellow ? ...on output i except three number - no only one :( can youi help me ?


Code
open I, ">d:\\a.bin"; 
binmode I;
print I pack('i3', 444, 555, 666); # three integers
close I;

# read
open O, "d:\\a.bin";
binmode I;

while (read(O, $b, 12) != 0) { # one integer has 4 bytes (4*3 as one block of three integers)
print unpack('i3', $b) . "\n"; # ???
}

close O;


Thank you


BillKSmith
Veteran

Oct 5, 2011, 8:39 AM

Post #2 of 2 (719 views)
Re: [waltz] Unpack - bad result (from file) [In reply to] Can't Post

The concatenation operator "." in your print statement forces unpack into scalar context. In scalar context, unpack returns only the first item. Change the "." to "," to fix this problem.

Use split or $, to separate the print fields.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives