how to do a simple check

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default how to do a simple check

    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.

    JS Guest

  2. Similar Questions and Discussions

    1. Need Simple Answer to Simple Contribute/Firefox question
      Hello all; I've tried the Adobe help in CS3, tech support, phone support, this forum, other forums, Mozilla, and nowhere can I get a straight...
    2. Spell Check and Grammer Check
      Hello, Does anybody know about some good spell checker/grammer checker for html/asp pages? Thank you, Regards, Raj.
    3. Turning off Check in / Check out feature
      How can I turn off the check in / check out feature? Can't seem to find it in the Contribute HELP. Thanks!
    4. Check to see if Check Boxes are Checked
      How do I check to see if a checked box is check on the following page? This is what I have. What am I doing wrong? <%If...
    5. A simple problem with a really simple form
      Hi there, I'm having a problem with designing a very small form in Dreamweaver. Its just a login form with username and password textfields - the...
  3. #2

    Default Re: how to do a simple check

    JS wrote:
    > 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

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


    perldoc perlvar

    ..


    --
    Cheers,
    Bernard
    --
    echo 42|perl -pe '$#="Just another Perl hacker,"'

    Bernard El-Hagin Guest

  4. #3

    Default Re: how to do a simple check

    Bernard El-Hagin wrote:
    > JS wrote:
    >> 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?
    >
    > 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])

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]

    Gunnar Hjalmarsson Guest

  5. #4

    Default Re: how to do a simple check

    Gunnar Hjalmarsson wrote:
    > Bernard El-Hagin wrote:
    >
    >> JS wrote:
    >>
    >>> 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?
    >>
    >>
    >> 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])
    >
    Thanks for your help,

    This worked:

    usage() if ! $ARGV[0] ;

    JS Guest

  6. #5

    Default Re: how to do a simple check

    JS wrote:


    [...]

    > Thanks for your help,
    >
    > This worked:
    >
    > usage() if ! $ARGV[0] ;

    Or


    usage() unless @ARGV;


    which seems a bit easier on the eye.


    --
    Cheers,
    Bernard
    --
    echo 42|perl -pe '$#="Just another Perl hacker,"'

    Bernard El-Hagin Guest

  7. #6

    Default Re: how to do a simple check

    On Mon, 08 Sep 2003 12:41:04 +0100, JS wrote:
    > 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 <tore@extend.no>

    "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
    Tore Aursand Guest

  8. #7

    Default Re: how to do a simple check

    On Mon, 8 Sep 2003 12:03:21 +0000 (UTC), "Bernard El-Hagin"
    <bernard.el-hagin@DODGE_THISlido-tech.net> wrote:

    >> Thanks for your help,
    >> This worked:
    >> usage() if ! $ARGV[0] ;
    >
    >Or
    >
    > usage() unless @ARGV;
    >
    >which seems a bit easier on the eye.
    I use:

    die $usage if not @ARGV;

    but in the end it's a matter of taste.

    Helgi Briem Guest

  9. #8

    Default Re: how to do a simple check

    JS wrote:
    > Gunnar Hjalmarsson wrote:
    >>
    >> if (-e $ARGV[0])
    >
    > Thanks for your help,
    >
    > This worked:
    >
    > usage() if ! $ARGV[0] ;
    Okay. Note that my suggestion includes a check of the file path. Only
    you know if such a check would be useful.

    --
    Gunnar Hjalmarsson
    Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]

    Gunnar Hjalmarsson Guest

  10. #9

    Default Re: how to do a simple check

    JS <vervoom@hotmail.com> wrote:
    > 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?

    die "USAGE: deptstats <files...>\n" unless @ARGV;

    > 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).


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  11. #10

    Default Re: how to do a simple check

    JS wrote:
    > This worked:
    > usage() if ! $ARGV[0] ;
    only if the file isn't called "0"
    =)

    regards, tina
    --
    [url]http://www.tinita.de/[/url] \ enter__| |__the___ _ _ ___
    [url]http://Movies.tinita.de/[/url] \ / _` / _ \/ _ \ '_(_-< of
    [url]http://www.perlquotes.de/[/url] \ \ _,_\ __/\ __/_| /__/ perception
    - the above mail address expires end of december 2003 -
    Tina Mueller Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139