Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > unpack - strange behaviour

Reply
Thread Tools

unpack - strange behaviour

 
 
ifiaz
Guest
Posts: n/a
 
      10-13-2003
The following program run:

($field1, $field2, $field3, $field4, $field5) = unpack("A4 A1 A3 A1
A*", "this is v strange");

print "|$field1|\n";
print "|$field2|\n";
print "|$field3|\n";
print "|$field4|\n";
print "|$field5|\n";

and the result is this:

|this|
||
|is|
|v|
| strange|

But, I expect a space for $field2 i.e. | |

Why $field4 can print with a single character and
$field2 can't. Am I missing something?
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      10-13-2003
ifiaz <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> The following program run:
>
> ($field1, $field2, $field3, $field4, $field5) = unpack("A4 A1 A3 A1
> A*", "this is v strange");
>
> print "|$field1|\n";
> print "|$field2|\n";
> print "|$field3|\n";
> print "|$field4|\n";
> print "|$field5|\n";
>
> and the result is this:
>
> |this|
> ||
> |is|
> |v|
> | strange|
>
> But, I expect a space for $field2 i.e. | |
>
> Why $field4 can print with a single character and
> $field2 can't. Am I missing something?


Yes. Perldoc -f pack:

as necessary. When unpacking, "A" strips
trailing spaces and nulls, "Z" strips

Use "a" instead.

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
debugger behaviour different to execution behaviour Andy Chambers Java 1 05-14-2007 09:51 AM
a strange behaviour of FF Maurice Firefox 2 03-11-2005 11:53 PM
Strange mouse behaviour with flash in Mozilla 1.3.7 hpoppe Firefox 0 11-07-2004 12:16 PM
Strange taskbar behaviour (notification area) Falcon Wireless Networking 0 08-17-2004 09:03 AM
[mozilla1.6] strange behaviour with newsgroup joost68 Firefox 5 04-03-2004 03:48 AM



Advertisments