CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
hash K/V slice not operating per docs.


New User

Feb 7, 2017, 6:47 PM

Post #1 of 3 (1679 views)
hash K/V slice not operating per docs. Can't Post

I'm having problems with using a hash key/value slice, as per the perldata manual.

I have taken the example directly from the manual and it won't compile:

# Example from perldata:

%h = (blonk => 2, foo => 3, squink => 5, bar => 8);
%subset = %h{'foo', 'bar'}; # key/value hash slice
# %subset is now (foo => 3, bar => 8)

root@devsm1-per:/Structerre/sm/lib-TestSuite# perl
syntax error at line 3, near "%h{"
Execution of aborted due to compilation errors.

root@devsm1-per:/Structerre/sm/lib-TestSuite# perl -v

This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux-gnu-thread-multi

I have tried other examples of this form of slice & see the same issue.

The manual states that this syntax is supported as of Perl-5.20

I can quite easily create a slice using map and other tools, however this syntax is cleaner & more readable when I'm passing selected parameters between calls:

sub foo {
my($obj, %pars)= @_;
$frotz= $obj->bar(%pars{qw/DB table key tansid pivot/});


Feb 7, 2017, 8:53 PM

Post #2 of 3 (1674 views)
Re: [bc3-au] hash K/V slice not operating per docs. [In reply to] Can't Post

You need a newer version of perl. Let me rephrase what the manual says: "This syntax is not supported in versions of perl older than v5.20."

I recommend that you read perl documentation with the utility perldoc. This ensures that you are reading the documents that came with your installation of perl. You can get instructions by typing at your command line:

perldoc perldoc

Good Luck,

New User

Feb 7, 2017, 11:26 PM

Post #3 of 3 (1667 views)
Re: [BillKSmith] hash K/V slice not operating per docs. [In reply to] Can't Post

Thanks Bill, that was the issue: it's an interesting way the docs state compatibility.

I assume this is an issue with how the various distributions manage and number their packages.

This system is old enough that I'm finding problems with various CPAN modules also. unfortunately upgrading isn't an option at this point.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives