http://www.perlmonks.org?node_id=584778


in reply to quick way to add a line to a file, if it's not already present (automating tweaking of /etc/ld.so.conf for installing Image::Magick)

on my system (CentOS), I do this:
echo "/usr/local/lib" > /etc/ld.so.conf.d/ImageMagick.conf ldconfig
As that goes in its own file, there's no need for trickery.

Oh, and of course my /etc/ld.so.conf is just this:

include ld.so.conf.d/*.conf