in reply to •Re^2: Sort Large Files
in thread Sort Large Files
You cannot always replace
withcat $file | prog
A few cases on which it fails:prog < $file
file="" file="data1 data2" file="-s squeeze-my-blanks"
In this particular pipeline, $file could have been placed after the perl command (if you can assume $file doesn't have a switch for cat). However, that would place the data to act on somewhere in the middle of the pipeline. Which I find harder to understand. Flow should go from right to left, left to right, top to bottom, or bottom to top. But not middle, left, right. cat is short, just three letters, which places the data nearly at the beginning. Placing the entire pipeline in parens, and putting < $file at the end places the data at the end, but you can't do that because of the reasons listed earlier.
That's two reasons why the use of cat wasn't useless.
So, I wonder why the original poster went out of their way to try to say it wasn't?
Because this is Perlmonks, and this is where dr. Pavlov would have a field day if he was still alive. The original poster had hoped that by saying the use of cat wasn't useless people would stop and think before reacting reflexly - but I guess the cerebral cortex was once again victorious over the brains.
Also, those backslashes at the end of lines give me the willies. The shells that I use don't need them.
Good for you. My preferred shells don't use them either, but I wasn't going to spend time figuring out which shells need them and which ones don't (as I don't know which shells the readers are usgin) so I just used a syntax that should work regardless whether the shell needs them or not. A bit of portability at the cost of three keystrokes, not bad, is it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re^4: Sort Large Files
by merlyn (Sage) on Jan 06, 2005 at 14:17 UTC | |
by Anonymous Monk on Jan 06, 2005 at 14:40 UTC | |
by merlyn (Sage) on Jan 06, 2005 at 14:48 UTC | |
by Anonymous Monk on Jan 06, 2005 at 15:38 UTC | |
by tye (Sage) on Jan 06, 2005 at 16:22 UTC | |
by Anonymous Monk on Jan 07, 2005 at 09:32 UTC | |
by csh (Novice) on Jan 14, 2005 at 21:49 UTC | |
by jdporter (Paladin) on Mar 21, 2005 at 04:19 UTC |