Thread HTTP::Request::Params ? WO ???? (17 answers)
Opened by Verzweifelter at 2015-03-20 16:29

GwenDragon
 2015-03-21 08:10
#180272 #180272
User since
2005-01-17
14542 Artikel
Admin1
[Homepage]
user image
https://metacpan.org/pod/release/CWEST/HTTP-Request-Params-1.01/lib/HTTP/Request/Params.pm#params
my $params = $parser->params;

Returns a hash reference containing all the parameters. The keys in this hash are the names of the parameters. Values are the values associated with those parameters in the incoming query. For parameters with multiple values, the value in this hash will be a list reference. This is the same behaviour as the CGI module's Vars() function.


Das ist dann so möglich:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
my $params = $Anfrage_Parameter-> params; # $params ist eine Hashreferenz
my %parameter = %{$params};               # %parameter ist der Hash

for my $key (keys %parameter) {           # zu jeden einzelnen Schlüssel
  my @values;
  if (ref $parameter{$key} ) {            # falls mehrere Werte, dann ist es eine Arrayreferenz
     @values = @{$parameter{$key}};       # Werte aus Referenz holen
  }
  else {                                  # einzelner Wert 
     @values = $parameter{$key};          
  }
  say $key, "=> ", join ", ",@values;    # die Werte ausgeben
}


Das Holen der Werte aus dem Hash (Zeile 5-11) ist auch kürzer so möglich:
my @values = ref($parameter{$key}) ? @{$parameter{$key}} : $parameter{$key};
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread HTTP::Request::Params ? WO ????