K
Klaus
According to "perldoc perlpacktut", I could use unpack to extract
fixed length fields:
from "perldoc perlpacktut":
+++++++++++++++++++++++++++++++++++++
++ [...] we can see that the date column stretches from
++ column 1 to column 10 - ten characters wide. The
++ pack-ese for "character" is A, and ten of them are
++ A10. So if we just wanted to extract the dates, we
++ could say this:
++
++ my($date) = unpack("A10", $_);
+++++++++++++++++++++++++++++++++++++
So I have created a test case with 3 A's then 7 spaces, followed by 3
B's:
use strict;
use warnings;
$_ = 'AAA BBB';
my $result = unpack("A10", $_);
print "result = '$result'\n";
This is the output:
result = 'AAA'
It basically works, but unpack seems to remove trailing spaces.
To my understanding of "perldoc perlpacktut", the output should show
as result a field of 10 characters (3 A's followed by 7 spaces), but
actually it only shows 3 A's.
Where have the 7 spaces gone ?
I can easily fill up the missing spaces with an sprintf("%-10s"), but
can somebody point me to the documentation where it says that
unpack("A10") removes trailing spaces ?
btw, I am using perl 5.10 under Win XP
fixed length fields:
from "perldoc perlpacktut":
+++++++++++++++++++++++++++++++++++++
++ [...] we can see that the date column stretches from
++ column 1 to column 10 - ten characters wide. The
++ pack-ese for "character" is A, and ten of them are
++ A10. So if we just wanted to extract the dates, we
++ could say this:
++
++ my($date) = unpack("A10", $_);
+++++++++++++++++++++++++++++++++++++
So I have created a test case with 3 A's then 7 spaces, followed by 3
B's:
use strict;
use warnings;
$_ = 'AAA BBB';
my $result = unpack("A10", $_);
print "result = '$result'\n";
This is the output:
result = 'AAA'
It basically works, but unpack seems to remove trailing spaces.
To my understanding of "perldoc perlpacktut", the output should show
as result a field of 10 characters (3 A's followed by 7 spaces), but
actually it only shows 3 A's.
Where have the 7 spaces gone ?
I can easily fill up the missing spaces with an sprintf("%-10s"), but
can somebody point me to the documentation where it says that
unpack("A10") removes trailing spaces ?
btw, I am using perl 5.10 under Win XP