in reply to Unpack unexpectedly trimming trailing spaces
From perldoc -f pack: "When unpacking, A strips trailing whitespace and nulls, Z strips everything after the first null, and a returns data with no stripping at all."
For this purpose, you can use either a or Z. Because you're reading in ASCII text, a makes more sense visually as [Aa] is for ASCII text, and Z is used for null terminated ASCII (which you don't have here):
perl -E '@foo=unpack("a6a4", "Hello Joe "); say ">$_<" for @foo' >Hello < >Joe <
perl -E '@foo=unpack("Z6Z4", "Hello Joe "); say ">$_<" for @foo' >Hello < >Joe <
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unpack unexpectedly trimming trailing spaces
by talexb (Chancellor) on Nov 20, 2015 at 14:24 UTC | |
by AnomalousMonk (Archbishop) on Nov 20, 2015 at 17:36 UTC | |
by stevieb (Canon) on Nov 20, 2015 at 22:14 UTC | |
by AnomalousMonk (Archbishop) on Nov 21, 2015 at 17:09 UTC |