Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Need some help with Hashes and formatting

by farang (Chaplain)
on Jun 25, 2014 at 03:01 UTC ( #1091120=note: print w/replies, xml ) Need Help??

in reply to Need some help with Hashes and formatting

This statement
printf "%10s\t=>%10s\n" x @ky, @ky, @vals;
is first outputting all keys, then all values. Here's an alternative without the intermediate arrays, using the defined or operator // to avoid a warning on an undef value.

#!/usr/bin/env perl use strict; use warnings; my %hash = ("fred" => "flintstone", "dino" => undef, "barney" => "rubble", "betty" => "rubble", ); printf "%10s\t=>%10s\n", "keys", "values"; for ( keys %hash ) { printf "%10s\t=>%10s\n", $_, $hash{$_} // ''; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1091120]
[robby_dobby]: guess I have to take a look at it off-work. I don't understand what those words mean, honestly :-)
[Corion]: Oooh. Tinc really looks good. It seems that it could even be used to link up (a segment of) my home network with (a segment of) a friends network, to create a private network over the internet
[marto]: fun times :)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2018-01-17 14:56 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (201 votes). Check out past polls.