From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,f92fbb4a0420dd57 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,f92fbb4a0420dd57 X-Google-Attributes: gid103376,public From: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) Subject: Re: Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Date: 1996/03/31 Message-ID: <4jmjb3$rbv@mulga.cs.mu.OZ.AU>#1/1 X-Deja-AN: 145102292 references: <4jlmn5$h1k@Nntp1.mcs.net> organization: Comp Sci, University of Melbourne newsgroups: comp.lang.ada,comp.lang.c++ Date: 1996-03-31T00:00:00+00:00 List-Id: mikey@mcs.com (Mike Young) writes: >eachus@spectre.mitre.org> says... >>The choice was between Ada and a shell script...I chose Ada: >> >>generic >> with procedure To_Do(File: in String); >>procedure Iterate_Files(Pattern: in String := "*"; >> Directory: in String := ""); >>-- This generic iterates over all files in a directory matching Pattern and >>-- calls To_Do once for each such directory entry. If a file has several >>-- links in the directory To_Do will be called once for each. > >========= >I don't know about that, Robert. The equivalent shell script would be: > >#---- iterateFiles >fileop=$1;shift >for file in $*; do $fileop $file; done No, that shell script, like the vast majority of shell scripts around, is buggy. Writing correct, portable shell scripts is actually pretty tricky. Here's a better version: fileop="$1"; shift case $# in 0) ;; *) for file in "$@"; do $fileop "$file"; done ;; esac Now just be careful with the quoting when you invoke it... > You are not restricted to procedures in that same program, all system > utilities are directly available, you don't need to rebuild to add new > features, and you need not have bothered with your 50 lines of code. > All are big wins, IMO. Oh, certainly shell scripts are extremely useful. But it helps to be aware of their drawbacks as well as their advantages. -- Fergus Henderson | "I have always known that the pursuit WWW: | of excellence is a lethal habit" PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.