Ask Your Question

Add an elemnt to an array

asked 2015-12-22 06:51:15 -0600

erdmaennchen gravatar image

I to add an element to an array, but it fails.
Here my code:
$foo = [test','testa', 'testb']
if ${osmajrelease} < 8 {
$foo + 'testc'
But the fails with:
Syntax error at '}'
But why, reading the documentation about array say the + will work?
Thanks for any help.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-12-22 13:18:05 -0600

erdmaennchen gravatar image

updated 2015-12-26 05:23:31 -0600

this will result in the same error.
Also the version:
$foo << "testc"

The problem was:
if ${osmajorrelease} < 8 {
change to:
$facts['os']['release']['major'] and it works.

edit flag offensive delete link more

answered 2015-12-22 12:26:11 -0600

lavaman gravatar image

You are adding a string to an array, not two arrays.

Try $foo + ['testc']

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-12-22 06:51:15 -0600

Seen: 392 times

Last updated: Dec 26 '15