18/09/13
2.9. Data Type map
2.9. Data Type map Chapter 2. YCP Data Types
2.9. Data Type map
AY C P -map is an associative array. It is a list of key-value-pairs w ith the keys being non-ambiguous, i.e. there are no tw o keys being exactly equal. While you can use values of any type for keys and values, you should restrict the keys to be of type string because from experience other types tend to complicate the code. Values of arbitrary type on the other hand make the map a very flexible data container. Maps are denoted w ith $ [k e y _ 0 : v a l u e _ 0 , k e y _ 1 : v a l u e _ 1 ,. . . ] . The empty map is denoted by $ [ ] . Note: A map does not reserve order of its elements w hen iterating over them. Exam ple 2.7. Map constants $ [] $ [" / u s r " :5 6 0 ," / h o m e ":3 2 0 0] $ [" f i r s t " :t r u e ," 2 " :[t r u e ,f a l s e] ," n u m b e r ":8 + 9]
Accessing the map elements is done by means of the index operator as in m y _ m a p [ " o s _ t y p e " ] : " l i n u x " . This returns the value associated w ith the key " o s _ t y p e " . As w ith lists, a default value must be appended (after a colon) that is returned if the given key does not exist. Again it should have the type that is expected for the current access, in this case the string linux. You may have noticed that the syntax for accessing maps kind of resembles that of accessing lists. This is due to the fact that lists are realized as maps internally w ith constant keys 0, 1, 2, and so on. Note: There is also another method for accessing maps, originating from the early days of Y a S T . The command l o o k u p ( m y _ m a p ," o s _ t y p e " ," l i n u x " )also returns the value associated w ith the given key. While this still w orks, it is deprecated by now and may be dropped in the future.
2.8. Data Type list
2.10. Data Type path
doc.opensuse.org/projects/YaST/openSUSE11.3/tdg/id_ycp_data_map.html
1/1