Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I *like* it!

A fellow Monk and I recently wrote a tool like this ourselves, but the in-memory eval() isn't a capability of our implementation. Anyway, I have a slight improvement to offer on your script. It concerns the mundane issue of where to save a file on disk. Your default /tmp would be fine on a single-user workstation but I thought about a multi-user system where security / privacy might be a greater concern, and one would want to confine one's activities to one's ~USER/ ($HOME) dir.

This small patch makes sure that such a directory exists before allowing the script to continue if writing to disk is going to be needed.

Here's the germane portion of what this change entails:

use File::Glob qw(:glob); use File::Spec qw(file_name_is_absolute catfile); # Configure this to an existing dir in your $HOME: my $home_space = ''; # /end user config. my ($HOME, $directory); if ($opt_m or $opt_M or $opt_f or $opt_F) { my $filename = $opt_f || $opt_F; die "Don't pass an absolute path!\n" if ($filename and File::Spec->file_name_is_absolute($filename)); $HOME = (bsd_glob('~'.$ENV{LOGNAME} , GLOB_TILDE | GLOB_MARK))[0]; $HOME = ($HOME =~s%/\Z%%) ? $HOME : ''; # Be kind to some Win32 users, comment this out: # die "No HOME found, no place to stash the code!\n" if not $HOME; # Directory to save fetched code in: $directory = $home_space ? File::Spec->catfile($HOME, $home_space) : $HOME; die "$directory does not exists.\n" if not -e $directory; }

Fun.

    Soren/Intrepid

-- 
Try my n.y.p.m.blue Perl Monks CSS Theme
(edit "On-Site CSS Markup" in your User Settings)

In reply to Re: Run and/or download code directly from perlmonk nodes. by Intrepid
in thread Run and/or download code directly from perlmonk nodes. by Dog and Pony

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (17)
    As of 2014-08-27 17:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (247 votes), past polls