Friends,
I am trying to write a simple script that I could use while editting files with vi. One of the things I like about vi is that you can do things like :1,$ ! program. Here's a demostration of what I want to be able to do ...
bash-2.05b$ vi junk
NOTES
doc
backup
notes
scripts
cpio_out
bashrc
~
~
~
:1,$ !sort
backup
bashrc
cpio_out
doc
notes
NOTES
scripts
:wq
In the above example I used sort to modify my file. I want to be able to do this with this script ...
bash-2.05b$ cat twc
#!/usr/bin/perl -w
use strict;
my $file = shift;
if ( !defined( $file ) ) {
print "usage: $0 <dir|file>\n";
exit 0;
}
if ( ! -e $file ) {
print "#$file\n";
} else {
print "$file\n";
}
... but when I do something like this ...
bash-2.05b$ vi junk
backup
bashrc
cpio_out
doc
notes
NOTES
scripts
~
~
~
:1,$ !./twc
... I get this ...
usage: ./twc <dir|file>
How should I be handling the input in my Perl script?
Plankton: 1% Evil, 99% Hot Gas. |
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|