but then started getting errors (root doesn't know where my personal perl library resides).

let me suggest a different direction to solve that

i have a file in /usr/bin called perlhuck. It is chmod ugo+x. it contains

#!/bin/sh perl -I /home/huck/cvs/perl_site_lib2 "$@"
where /home/huck/cvs/perl_site_lib2 is my personal perl library. Im very old school, for decades when i wanted to run a perl program id say perl <program>.pl, so it is very natural to say perlhuck <program>.pl too. Having this script around allows me to place this line into my cgi-bin programs as the first line.
#!/usr/bin/perlhuck
And they run just fine knowing where my personal libs are. I also place that as the first line of my chmod ugo+x perl programs. If i wanted to i could extend the path and do all sorts of other things in perlhuck too.

Part of my motivation for perlhuck also come from working in production environments where besides a perllib and/or path i need to set other env variables to insure my process ran correctly.

over time i have written dozens of scripts like this, each designed to set up the correct environment before running some production script.

if you had such a script, say perlnysus then you could say sudo perlnysus <program>.pl and everything would still work fine.

So i suggest you create a perlnysus script, and either say sudo perlnysus <program>.pl or place #!/usr/bin/perlnysus into the first line of your executable perl programs and say sudo <program>.pl


In reply to Re: Best way to write to a file owned by root? by huck
in thread Best way to write to a file owned by root? by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.