Re:With the Rise of DevOps, Perl Shows Its Muscle
by SteveNuts on Sunday January 08, 2017 @12:13AM
(#13348392)
I feel the same way with Bash.
It's great for one liners, but it breaks down when doing simple things like checking if a variable is a string or integer.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by brobinson on Sunday January 08, 2017 @12:50AM
(#13348513)
Ugh. If I have to write Bash, I try to enforce some level of basic sanity with:
set -euo pipefail
I've seen way too many scripts catastrophically fail because of unbound variables or one side of a pipe failing and the script continuing anyways, etc.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by DCoder on Sunday January 08, 2017 @03:29AM
(#13348898)
I use the verbose version for readability:
set -o errexit
set -o nounset
set -o pipefail
Some commands need custom error handling, which means turning off -e: set +o errexit
ansible-playbook ...
if [[ "$?" != "0" ]]; then
echo -e "\e[1;31m""Error when executing ansible!""\e[0m"
exit 1
fi
set -o errexit
And if you use -e , you will probably need the default value helper to validate input arguments: # the :- operator means "use the right side value if the left side ($1) is not set"
env=${1:-}
inventoryFile="${baseDir}/env/${env}/inventory"
if [[ -f "${inventoryFile}" ]]; then
echo -e "\e[1;31m""Invalid environment specified!""\e[0m"
exit 1
fi
Re:With the Rise of DevOps, Perl Shows Its Muscle
by Ded7xSEoPKYNsDd on Sunday January 08, 2017 @07:20AM
(#13349411)
I feel your first example is better written like this:
if ! ansible-playbook ... ; then
echo -e "\e[1;31m""Error when executing ansible!""\e[0m"
exit 1
fi
But generally when I need to work around errexit, I tend to add something like " || true" or " || xyz_failed=true" to the end of the command line instead of turning it off and on again.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by paulddraper on Sunday January 08, 2017 @01:18AM
(#13348581)
+1 to this.
-e Abort at the first failed line
-u Abort when undefined variable is used
-o pipefail Piped commands return the status of the last failed command, rather than the status of the last command
Re:With the Rise of DevOps, Perl Shows Its Muscle
by iamdave on Sunday January 08, 2017 @01:53AM
(#13348670)
You are a wonderful person for doing this. As an ops guy, I tip my hat.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by user5994461 on Sunday January 08, 2017 @01:15PM
(#13351058)
I'm mostly using ansible instead of bash noawadays.
Does all the same with more commands and better error handling.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by SteveNuts on Sunday January 08, 2017 @08:20PM
(#13353293)
Same here, but Ansible forces a basic knowledge of Python if you want to use it really well.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by babo on Sunday January 08, 2017 @07:21AM
(#13349412)
There are limits for sure, but actually it's quite possible to write bash code at scale, but it requires some discipline and practice. It's hard to avoid it.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by xkxx on Sunday January 08, 2017 @01:07AM
(#13348556)
One reason I still use perl for is its better regexes. In particular, I tend to use `perl -pe 's/regex/replacement/g'` instead of `sed 's/regex/replacement/g'` when I need to replace something. sed's regexes are just not good enough for some tasks.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by jldugger on Sunday January 08, 2017 @02:02AM
(#13348694)
So like, Puppet & Chef are pretty big Ruby devops communities. And Ruby is fairly obviously inspired by Perl.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by ZenoArrow on Sunday January 08, 2017 @04:07AM
(#13348988)
Ruby's name was inspired by Perl, but I'm curious to know which language structures you think were inspired by Perl.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by joseph on Sunday January 08, 2017 @04:29AM
(#13349034)
The regular expression syntax; sigils on (some) variables; shortcuts like `bar if foo`; optional parenthesis on function calls; `chomp()` and `chop()`; those are just a few things that come to mind.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by coldtea on Sunday January 08, 2017 @02:08PM
(#13351323)
Ruby has since forever been described as a cross between Perl and Smalltalk (and some other languages), including by its creator (Matz).
Re:With the Rise of DevOps, Perl Shows Its Muscle
by cutler on Sunday January 08, 2017 @12:01PM
(#13350635)
Read up on Matz's account of how he developed Ruby and what were his influences. Larry Wall was top his list.
Re:With the Rise of DevOps, Perl Shows Its Muscle
by throwaway2016a on Sunday January 08, 2017 @07:58PM
(#13353202)
> I have barely seen anyone use anything but Python (Golang maybe...) for this
Odd. I see almost entirely Ruby. Especially with tools like Chef.
Now, I have barely seen anyone use anything but Python (Golang maybe...) for this. Bottom line - readability matters! people have moved on and perl has outlived its purpose.