http://qs321.pair.com?node_id=374750

Plankton has asked for the wisdom of the Perl Monks concerning the following question:

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.