GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Hash::Union(3) User Contributed Perl Documentation Hash::Union(3)

Hash::Union - smart hashes merging

Version 0.03

  use Hash::Union 'union';
  use Data::Dumper;                # for debug only

  my $config_base = {              # default application config
      'database' => 'production',  # production database
      'html_dirs' => [             # search paths for html documents
          '/docs/html/main',
          '/docs/html/default'
      ],
      'text_dirs' => [             # search paths fo text documents
          '/docs/text/main',
          '/docs/text/default'
      ]
  };

  my $config_local = {             # locally customized config
      'database' => 'stageing',    # devel database
      'prepend: html_dirs' => [    # local html pages preferred
          '/local/html/main',
          '/local/html/default'
      ],
      'append: text_dirs' => [     # fallback for nonexistent text
          '/local/text/main',
          '/local/text/default'
      ]
  };

  # now merge default with local
  my $config = union( [ $config_base, $config_local ] );

  print Dumper $config;

  ========

  $VAR1 = {
      'database' => 'stageing',
      'html_dirs' => [
          '/local/html/main',
          '/local/html/default',
          '/docs/html/main',
          '/docs/html/default'
      ],
      'text_dirs' => [
          '/docs/text/main',
          '/docs/text/default',
          '/local/text/main',
          '/local/text/default'
      ]
  };

Supported options:
  • reverse

    Merge all hash references in reverse order.

  • simple

    Don't apply complex merging logic (ignore keys special meaning).

Setting new value unconditionally:
Key syntax: '=KEY', '= KEY', 'set:KEY', 'set: KEY'

Previous value of KEY will be lost and new value will be set unconditionally. This kind of merging logic applies to any 'plain' keys by default. Passed option 'simple' forces this method for 'complex' keys too.

Setting new value only if no true value still exists:
Key syntax: '?=KEY', '?= KEY' , 'ifnone:KEY', 'ifnone: KEY'

If "true" (from perl point of view) value for this key exists just skip new value assignment. Otherwise assign new value (possible even "false").

Prepending new value to existing:
Key syntax: '+=KEY', '+= KEY', 'prepend:KEY', 'prepend: KEY'

Prepend new value to any existing value of key. Raise an exception on an incompatible value types. Scalars will be concatenated, arrays unshifted, hashes traversed deeply in proper order.

Appending new value to existing:
Key syntax: '=+KEY', '=+ KEY', 'append:KEY', 'append: KEY'

Append new value to any existing value of key. Raise an exception on an incompatible value types. Scalars will be concatenated, arrays pushed, hashes traversed deeply in proper order.

NOTE: In all syntax forms spaces between operation and key are optional.

Oleg A. Mamontov, "<oleg at mamontov.net>"

Please report any bugs or feature requests to "bug-hash-union at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hash-Union>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

You can find documentation for this module with the perldoc command.

    perldoc Hash::Union

You can also look for information at:

  • RT: CPAN's request tracker

    <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Hash-Union>

  • AnnoCPAN: Annotated CPAN documentation

    <http://annocpan.org/dist/Hash-Union>

  • CPAN Ratings

    <http://cpanratings.perl.org/d/Hash-Union>

  • Search CPAN

    <http://search.cpan.org/dist/Hash-Union/>

Copyright 2009 Oleg A. Mamontov, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2009-02-11 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.