At 07:09 13.07.2001 -0400, Busse, Rich wrote:
>In C, I can do something like this:
>
>         char ch ;
>         char sz [] = "?:\\dir\\myfile.ini" ;
>         for ( ch = 'c' ; ch <= 'z' ; ch++ )
>         {
>                 sz[0] = ch ;
>                 . . .
>
>to spin thru all the possible drives on a Windows NT box. But Perl complains
>about trying to compare/increment a non-numeric. Any way around this?

use strict;

my $drive = "a";
my $path = ":\\path\\to\\file.xxx";
foreach (0..25)
         {
         print "$drive$path\n";
         $drive++;
         }

since incrementing a string in perl is possible.  Forget about looking at 
strings like an array :)
Also, Perl style likes foreach() over for() usually.

If you want to do it in a really perly way:

print $drive++."$path\n" foreach (0..25);

>Also, to look at each character in a string, I can do:
>
>         int i ;
>         char sz [] = "A string" ;
>         for ( i = 0 ; i < strlen (sz) ; i++ )
>         {
>                 ch = sz [i] ;
>                 . . .
>
>How do I access each character in a string with Perl? TIA...

check out perldoc perlfunc -- there's a whole section on built in string 
functions

to get the length of a string use length (surprised?)

my $sString = "foo bar";
print length($sString)."\n";



Aaron Craig
Programming
iSoftitler.com

Reply via email to