Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-4443

Assign multiple variables from a hash

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Normal
    • Resolution: Done
    • None
    • PUP 4.1.0
    • Compiler
    • None
    • New Feature

    Description

      In PUP-2894, the ability to assign multiple variables from an array was added. When using this to refactor typical code it became apparent that this is useful when there are only a few values to assign, or where there is a simple 1:1 map in a single place. Real world code typically need this feature to assign 10 (typical) but up to as many as 30-50 variables - with very high redundancy.

      As it is difficult to writes arrays that merge, it is of great value to be able to assign multiple variables based on a hash.

      [$a, $b] = {a => 10, b => 20}
      

      The rules are:

      • for each entry in the array, there must be a corresponding key in the hash
      • the hash key must be based on the String variable name(s)
      • if the hash does not have a corresponding key the operation fails
      • there may be additional key/values in the hash
      • if an element in the LHS array is an Array with multiple variables, the corresponding key in the hash must be an Array with the String names in the same order e.g.

        [[$a, $b], $c] = {[a,b] => {a => 10, b => 20 }, c => 30 }
        

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              henrik.lindberg Henrik Lindberg
              Kurt Wall Kurt Wall
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support