Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. sub PrintAA
  2. {
  3. my $test = shift;
  4. my %aa = shift;
  5. print $test . "n";
  6. foreach (keys %aa)
  7. {
  8. print $_ . " : " . $aa{$_} . "n";
  9. $aa{$_} = $aa{$_} . "+";
  10. }
  11. }
  12.  
  13. PrintAA("abc", %fooHash);
  14.  
  15. sub PrintAA
  16. {
  17. my $test = shift;
  18. my $aaRef = shift;
  19.  
  20. print $test, "n";
  21. foreach (keys %{$aaRef})
  22. {
  23. print $_, " : ", $aaRef->{$_}, "n";
  24. }
  25. }
  26.  
  27. #!/bin/perl -w
  28.  
  29. use strict;
  30.  
  31. sub PrintAA
  32. {
  33. my($test, %aa) = @_;
  34. print $test . "n";
  35. foreach (keys %aa)
  36. {
  37. print $_ . " : " . $aa{$_} . "n";
  38. }
  39. }
  40.  
  41. my(%hash) = ( 'aaa' => 1, 'bbb' => 'balls', 'ccc' => &PrintAA );
  42.  
  43. PrintAA("test", %hash);
  44.  
  45. my $test = shift;
  46. my(%aa) = @_;
  47.  
  48. Reference found where even-sized list expected at xx.pl line 18.
  49. ...
  50. Use of uninitialized value in concatenation (.) or string at xx.pl line 13.
  51.  
  52. sub PrintAA
  53. {
  54. my $test = shift;
  55. my %aa = @_;
  56. print $test . "n";
  57. foreach (keys %aa)
  58. {
  59. print $_ . " : " . $aa{$_} . "n";
  60. $aa{$_} = $aa{$_} . "+";
  61. }
  62. }
  63.  
  64. sub PrintAA
  65. {
  66. my $test = shift;
  67. my $aa = shift;
  68. if (ref($aa) != "HASH") { die "bad arg!" }
  69. ....
  70. }
  71.  
  72. PrintAA($foo, %bar);
  73.  
  74. my %aa = shift;
  75.  
  76. my $scalar = 5;
  77. my %hash = (a => 1, b => 2, c => 3);
  78.  
  79. func($scalar, %hash)
  80.  
  81. sub func {
  82. my $scalar_var = shift;
  83. my %hash_var = @_;
  84.  
  85. ... Do something ...
  86. }
  87.  
  88. sub PrintAA ($%)
  89. {
  90. my $test = shift;
  91. my %aa = ${shift()};
  92. print "$testn";
  93. foreach (keys %aa)
  94. {
  95. print "$_ : $aa{$_}n";
  96. $aa{$_} = "$aa{$_}+";
  97. }
  98. }
  99.  
  100. PrintAA("test", %hash);
  101.  
  102. PrintAA("test", %$ref_to_hash);
  103.  
  104. my %myhash = ( key1 => "val1", key2 => "val2" );
  105.  
  106. my $href = %myhash
  107.  
  108. %$href
  109.  
  110. my $myhref = shift;
  111.  
  112. keys %$myhref;
  113.  
  114. sub get_args { ref( $_[0] ) ? shift() : ( @_ % 2 ) ? {} : {@_}; }
  115. sub PrintAA
  116. {
  117. my $test = shift;
  118. my $aa = get_args(@_);;
  119. #then
  120. $aa->{somearg} #do something
  121. $aa->{anotherearg} #do something
  122.  
  123. }
  124.  
  125. printAA($firstarg,somearg=>1, anotherarg=>2)
  126.  
  127. printAA($firstarg,{somearg=>1, anotherarg=>2})
  128.  
  129. my(%hash) = ( 'aaa' => 1, 'bbb' => 'balls', 'ccc' => PrintAA );
  130.  
  131. PrintAA("test", %hash);
Add Comment
Please, Sign In to add comment