Ask Your Question
0

Add an elemnt to an array

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

erdmaennchen gravatar image

Hello,
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
0

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

erdmaennchen gravatar image

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

Hm,
this will result in the same error.
Also the version:
$foo << "testc"
or
$foo<<['testc']

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

edit flag offensive delete link more
-1

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

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

Stats

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

Seen: 222 times

Last updated: Dec 26 '15