Skip to content

Instantly share code, notes, and snippets.

@Keith-S-Thompson
Created February 22, 2012 21:01
Show Gist options
  • Save Keith-S-Thompson/1887241 to your computer and use it in GitHub Desktop.
Save Keith-S-Thompson/1887241 to your computer and use it in GitHub Desktop.
Hash slice problem
#!/usr/bin/perl
use strict;
use warnings;
foreach my $var (qw(REQUEST_METHOD PATH_INFO CONTENT_LENGTH CONTENT_TYPE)) {
$ENV{$var} = $var;
}
# my ($req_method,$path_info,$content_length,$content_type)
# = @{ %ENV }{qw|REQUEST_METHOD PATH_INFO CONTENT_LENGTH
# CONTENT_TYPE|};
my ($req_method,$path_info,$content_length,$content_type)
= @ENV{qw|REQUEST_METHOD PATH_INFO CONTENT_LENGTH CONTENT_TYPE|};
print "req_method = $req_method\n";
print "path_info = $path_info\n";
print "content_length = $content_length\n";
print "content_type = $content_type\n";
#!/usr/bin/perl
use strict;
use warnings;
foreach my $var (qw(REQUEST_METHOD PATH_INFO CONTENT_LENGTH CONTENT_TYPE)) {
$ENV{$var} = $var;
}
my ($req_method,$path_info,$content_length,$content_type)
= @{ %ENV }{qw|REQUEST_METHOD PATH_INFO CONTENT_LENGTH
CONTENT_TYPE|};
print "req_method = $req_method\n";
print "path_info = $path_info\n";
print "content_length = $content_length\n";
print "content_type = $content_type\n";
# Can't use string ("61/128") as a HASH ref while "strict refs" in use at ./foo.pl line 11.
$ /usr/local/apps/perl-5.12.4/bin/perl --version | sed -n 2p
This is perl 5, version 12, subversion 4 (v5.12.4) built for i686-linux
$ /usr/local/apps/perl-5.12.4/bin/perl hash_slice.pl
req_method = REQUEST_METHOD
path_info = PATH_INFO
content_length = CONTENT_LENGTH
content_type = CONTENT_TYPE
$ /usr/local/apps/perl-5.12.4/bin/perl hash_slice_bad.pl
Can't use string ("61/128") as a HASH ref while "strict refs" in use at hash_slice_bad.pl line 11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment