Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Named-parameters/Perl/named-parameters-1.pl
Normal file
12
Task/Named-parameters/Perl/named-parameters-1.pl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
sub funkshun {
|
||||
my %h = @_;
|
||||
# Print every argument and its value.
|
||||
print qq(Argument "$_" has value "$h{$_}".\n)
|
||||
foreach sort keys %h;
|
||||
# If a 'verbosity' argument was passed in, print its value
|
||||
# whatever that value may be.
|
||||
print "Verbosity specified as $h{verbosity}.\n" if exists $h{verbosity};
|
||||
# Say that safe mode is on if 'safe' is set to a true value.
|
||||
# Otherwise, say that it's off.
|
||||
print "Safe mode ", ($h{safe} ? 'on' : 'off'), ".\n";
|
||||
}
|
||||
7
Task/Named-parameters/Perl/named-parameters-2.pl
Normal file
7
Task/Named-parameters/Perl/named-parameters-2.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
funkshun(
|
||||
verbosity => 3,
|
||||
password => 'foobie blech',
|
||||
extra_lives => 3,
|
||||
'42' => 'answer',
|
||||
password => 'joshua'
|
||||
);
|
||||
37
Task/Named-parameters/Perl/named-parameters-3.pl
Normal file
37
Task/Named-parameters/Perl/named-parameters-3.pl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
sub event
|
||||
{
|
||||
my ($params_ref, $name) = @_;
|
||||
my %params = %$params_ref;
|
||||
my @known_params = qw(attendees event food time);
|
||||
|
||||
printf "%s called event() with the following named parameters:\n",
|
||||
$name // 'Anonymous';
|
||||
|
||||
say sort map {
|
||||
sprintf "%s: %s\n",
|
||||
ucfirst $_,
|
||||
ref $params{$_} eq ref []
|
||||
? join ', ', @{ $params{$_} }
|
||||
: $params{$_};
|
||||
} grep exists $params{$_}, @known_params;
|
||||
delete $params{$_} foreach @known_params;
|
||||
|
||||
say "But I didn't recognize these ones:";
|
||||
while (my ($key, $val) = each %params)
|
||||
{
|
||||
say "$key: $val";
|
||||
}
|
||||
}
|
||||
|
||||
event(
|
||||
{ # Curly braces with no label (e.g. 'sub' before it)
|
||||
# create a reference to an anonymous hash
|
||||
attendees => ['Bob', 'Betty', 'George', 'Bertha'],
|
||||
event => 'birthday',
|
||||
foo => 'bar',
|
||||
food => 'cake',
|
||||
frogblast => 'vent core',
|
||||
time => 3,
|
||||
},
|
||||
"Joe Schmoe"
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue