Re: Looping through from A to Z

From: John-Paul Stewart (jpstewart_at_binaryfoundry.ca)
Date: 09/27/05


Date: Tue, 27 Sep 2005 11:26:35 -0400

Paul Colquhoun wrote:
> On 26 Sep 2005 06:33:46 -0700, fritz-bayer@web.de <fritz-bayer@web.de> wrote:
> | Hi,
> |
> | does somebody know, which bash construct will allow me to loop through
> | the letters from a to z.
> |
> | for i in [A-Z]*; do echo $i ; done ;
> |
> | Did not work, because it will work on files. I basically nedd a list of
> | characters , which contains all the characters from a to z.
>
>
> for i in $( perl -e 'print join( " ", ( "a" .. "z" ) );' )

I find this suggestion somehow amusing. The $(...) expression is 49
characters to type and requires calling perl (significant execution
overhead). Compare that with:

for i in a b c d e f g h i j k l m n o p q r s t u v w x y z

(Variants on that have already been suggested by both Michael Heiming
and Chris F.A. Johnson.) That's 51 characters to type (26 letters of
the alphabet plus 25 spaces) and doesn't have the overhead of calling
perl.

I suppose the perl solution is more general but I think there's
something to be said for the efficiency of the task-specific solution.



Relevant Pages

  • Re: convert f77 code from mixed case to lower case
    ... value between lowercase and uppercase letters. ... Language using US/UK versions of the ascii table. ... have thier lower case and upper case ... PS Perl has 'uc' and 'lc' functions for case switching, ...
    (comp.lang.fortran)
  • Re: how to make a perl tk like thing
    ... >> How can I design my own graphical tookit like perl tk. ... You have too many letters in that word. ... Tad McClellan ...
    (comp.lang.perl.misc)
  • Re: perl should be improved and perl6
    ... not the same as a Perl hacker. ... When we speak, we cannot ... distinguish between capital letters and small letters. ...
    (comp.lang.perl.misc)
  • Simple string search
    ... I am very new to perl and i am having a problem ... search for a substring in a file. ... ") with 12 letters in the middle. ...
    (comp.lang.perl.misc)