Reputation: 341
I am working through Intermediate Perl by brian d foy (2nd ed). I'm on the section dealing with references to hashes. I have run one of the scripts in Strawberry Perl and I'm not sure I'm getting the intended results. the script is:
my %gilligan_info = (
name => 'Gilligan',
hat => 'White',
shirt => 'Red',
position => 'First Mate',
);
my %skipper_info = (
name => 'Skipper',
hat => 'Black',
shirt => 'Blue',
position => 'Captain',
);
my @crew = (\%gilligan_info, \%skipper_info);
my $format = "%−15s %−7s %−7s %−15s\n";
printf $format, qw(Name Shirt Hat Position);
for my $crewmember (@crew) {
printf $format, @$crewmember{qw(name shirt hat position)};
}
The output I am seeing is
I thought this example was going to show actual values, but I am just seeing memory addresses (I think)..
Can somebody please advise thanks John
Upvotes: 1
Views: 87
Reputation: 1
I used NotePad++ to paste and save. The code worked as-is for me with no changes.
If you take the current code and paste it into MS Word, it will look normal. Save it and open in Notepad++. You'll see that
my $format = "%-15s %-7s %-7s %-15s\n";
is changed to
my $format = "%?15s %?7s %?7s %?15s\n";
Upvotes: 0
Reputation: 4013
Are you using word as your editor? I say this because it looks like your format is using n-dash or m-dash instead of - and word will do this automatically. Get hold of notpad++ and use that as your editor.
Upvotes: 4