Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

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

G'day Rolf,

Update: I posted a solution but later found it didn't work with commands that output multiple lines (e.g. ls, ps, etc.). Here's a new solution that doesn't have that problem. The original also had a portability issue: this one doesn't. (The spoiler below contains the original solution.)

My .perldb contains:

$ cat ~/.perldb for (qw{pwd date ls ps}) { $DB::alias{$_} = 's{^($_.*)$}{chomp(my $out = qx{$1}); print {$DB::OUT} $out} +e'; }

Obviously, substitute qw{pwd date ls ps} with your qw/commands/. See perldebug - Debugger Customization for a description of %DB::alias.

Here's a test run:

$ perl -d -e 1 Loading DB routines from perl5db.pl version 1.33 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 1 DB<1> pwd /Users/ken/tmp DB<2> date Sun 9 Sep 2012 18:12:43 EST DB<3> date "%Y-%m-%d" date: illegal time format usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS +]] ... [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] DB<4> date "+%Y-%m-%d" 2012-09-09 DB<5> ls -l total 30824 ... drwxr-xr-x 7 ken staff 238 14 Jun 20:23 zip_test DB<6> ps -ef UID PID PPID C STIME TTY TIME CMD ... 501 74528 74527 0 23Aug12 ttys007 0:00.04 -bash DB<7> q $

The typo (date "%Y-%m-%d") was accidental but I left it in just to show that the mistake was handled in a reasonable fashion.

-- Ken


In reply to Re: chomping the output of Shell.pm by kcott
in thread chomping the output of Shell.pm by LanX

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 examining the Monastery: (12)
    As of 2014-07-10 11:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (207 votes), past polls