how to do a simple check

J

JS

I have a program called depstats.pl

which takes some files as input so I run it like:

../deptstats file1 file2 file3

and then loop through all those files using the construct:

while(<>)

How do I check if any files were supplied? Because if I just do :

../depstats.pl

the programs never ends until I CTRL-C it.

Thanks for the help.

JS.
 
G

Gunnar Hjalmarsson

Bernard said:
All of the script's arguments are stored in the special array
@ARGV, so you can simply make sure it's not empty.

Or maybe:

if (-e $ARGV[0])
 
T

Tore Aursand

This worked:

usage() if ! $ARGV[0] ;

There's always more than one way to do it, but please write

usage() unless ( $ARGV[0] );

instead. That 'if !' is ugly, IMO.


--
Tore Aursand <[email protected]>

"Whenever I see an old lady slip and fall on a wet sidewalk, my first
instinct is to laugh. But then I think, what if I was an ant, and she
fell on me. Then it wouldn't seem quite so funny." -- Jack Handey
 
T

Tad McClellan

JS said:
I have a program called depstats.pl

which takes some files as input so I run it like:

./deptstats file1 file2 file3

and then loop through all those files using the construct:

while(<>)

How do I check if any files were supplied?


Because if I just do :

./depstats.pl

the programs never ends until I CTRL-C it.


That is what <> is _supposed_ to do.

It is waiting for you to provide the input via the keyboard (STDIN).

Try typing some input, then mark the end of input with
a CTRL-D (CTRL-Z on Windows).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,795
Members
47,342
Latest member
eixataze

Latest Threads

Top