# YAML anchor and alias problem

**URL:** <https://www.ruby-forum.com/t/yaml-anchor-and-alias-problem/154967>\
**Category:** Ruby\
**Created:** [December 5, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/yaml-anchor-and-alias-problem/154967 "2008-12-05T17:37:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 5, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/yaml-anchor-and-alias-problem/154967/1 "2008-12-05T17:37:30Z")

</div>

Hi,  
I’m trying to use YAML to load and store a whole bunch of data (with a  
lot of repetition). Anchors and aliases seem to be the way froward,  
but I am runing into a few problems.

## Suppose I have the following YAML document:

anchor: &id001

- sample1 :  
name: s1  
freq: 0.27
- sample2 :  
name: s2  
freq: 0.27  
alias: \*id001

held in a string (str). I then load it

x=YAML.load(str)  
=\> {“anchor”=\>[{“name”=\>“s1”, “freq”=\>0.27, “sample1”=\>nil},  
{“name”=\>“s2”, “freq”=\>0.27, “sample2”=\>nil}], “alias”=\>nil}

Why does my alias always come out as nil. Where do I need to put the  
anchor in order that the alias picks up the entire list. This is the  
output I desire  
=\> {“anchor”=\>[{“name”=\>“s1”, “freq”=\>0.27, “sample1”=\>nil},  
{“name”=\>“s2”, “freq”=\>0.27, “sample2”=\>nil}], “alias”=\>  
[{“name”=\>“s1”, “freq”=\>0.27, “sample1”=\>nil}, {“name”=\>“s2”,  
“freq”=\>0.27, “sample2”=\>nil}]}

Thanks

Steve

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 5, 2008, 6:00pm UTC](https://www.ruby-forum.com/t/yaml-anchor-and-alias-problem/154967/2 "2008-12-05T18:00:58Z")

</div>

On Dec 5, 4:30 pm, removed\_email\_address@domain.invalid wrote:

> freq: 0.27
> 
> Steve  
> Belay that - problem found - I didn’t have the indenting right

Steve
