I do agree ;) the latest version ksh93s has just been released and offers quite a lot of new goodies (regex extensions and lots of utf8 fixes). The extension mechanism that has been there since the beginnings of ksh93 in 93 ;) is quite. By the way as cat is a builtin of modern ksh (and the last command of the pipeline in ksh is executed by main()) the efficiency of 'cat...| cmd' is (usually) hardly a problem. From the command line, and I often use a cat like this, in case I need to edit later to put 'cat -evnt' o even to sandwich some extra "line" like this

 { echo; cat ...; echo; } | whatever

But... there is an exception actually 'cmd | while read' is probably one of "worst" constructs in terms of efficiency as the shell needs to read one byte at a time in case another command in the body of the while could compete for stdin. If it is *not* the case, a trick like this (for modern enough shells) is nice:

use 'cmd | while read -u9 ...; done 9<&0-'
desc 0 is duped on desc 9 and then closed

# an example of healthy competition for stdin while read header do dd ... done

Note that you need a true move-close and not 9>&0 0<&- as by the time the dup is done, the close doesn't know about it and does not set a share flag. ksh88 does not have the logic needed for example. If your system pipes are dumb (no peek ahead) the trick does not work either.

I finish with some hack. the 'while < file' idiom does that move-close magic under the hood (and does a 'set' on each line read) and is quite efficient. "under cover select" is what you get if you stack them 'while <file1 <file2 ...' ;)

% stephan@labaule (/home/stephan) % % $0 --version; cat -n hi1 version sh (AT&T Labs Research) 1993-12-28 r 1 just 2 another 3 ksh 4 hacker % stephan@labaule (/home/stephan) % % while < hi1; do print -n $1' '; done; echo just another ksh hacker

David Korn's own words on this (thread of ast-users mailing list on july 2006) are interesting from a un*x perspective: https://mailman.research.att.com/pipermail/ast-users/2006q3/001084.html

enjoy --stephan

In reply to Re^2: Comandline arguements when perl code is getting executed from command line by sgt
in thread Comandline arguements when perl code is getting executed from command line by jesuashok

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.