iterate the A B C

I

ilany

Hi All,

I am trying to find an English letter to do a net use command.
Since most of the letters are already taken, I need to loop over the A
B C and if one letter is free, I will do net use to it.

Do you have an inteligent way to iterate over abc in perl (and not
create an array of all abcdefgh...) ?

Thanks

Ilan
 
A

anno4000

ilany said:
Hi All,

I am trying to find an English letter to do a net use command.
Since most of the letters are already taken, I need to loop over the A
B C and if one letter is free, I will do net use to it.

Do you have an inteligent way to iterate over abc in perl (and not
create an array of all abcdefgh...) ?

What's wrong with creating a list of the alphabet? It isn't long,
not if it begins with a, b, c... . Here is how I would do it
(untested):

use List::Util qw( first);
my $letter = first { ! is_taken( $_) } 'A' .. 'Z';
die "Can't find a free letter" unless $letter;
# go ahead

You would have to provide the function is_taken(), I have no idea
what "net use" is and how to know if it has "taken" a letter.

Anno
 
D

Dr.Ruud

ilany schreef:
I am trying to find an English letter to do a net use command.
Since most of the letters are already taken, I need to loop over the A
B C and if one letter is free, I will do net use to it.

Do you have an inteligent way to iterate over abc in perl (and not
create an array of all abcdefgh...) ?

C:\> perl -le "print for q{A} .. q{Z}"

See perlop.
 
I

ilany

No need for further assistance.
I got it:

print "All Letters\n";
for $list(C..Z) {
print "$list\n";
}
 
A

anno4000

First, please do not top-post.
No need for further assistance.

Oh yes, there is.
I got it:

print "All Letters\n";
for $list(C..Z) {
print "$list\n";
}

You're running without strict and warnings. The variable $list should
be declared lexical. C and Z shouldn't be barewords. Code in blocks
should be indented.

Anno
 
A

a

First, please do not top-post.


Oh yes, there is.


You're running without strict and warnings. The variable $list should
be declared lexical. C and Z shouldn't be barewords. Code in blocks
should be indented.

Anno

Hi
I would like to iterate multiple set of characters. That is,
a..z, A..Z, 0..9
so how can I do the following?
for $list(A..Z and a..z and 0..9){
print "$list\n";
}
Thanks
 
B

Ben Morrow

Quoth "ilany said:
Hi All,

I am trying to find an English letter to do a net use command.

[For future reference, some mention of 'Windows' or 'Windows drive
mapping' would have been useful here, for context. A lot of people here
have never heard of 'net use'.]

Note that you can get a list of currently allocated driver letters with
Win32API::File::getLogicalDrives, and you can map a network share to a
system-assigned letter by calling Win32::NetResource::AddConnection with
$Connection (which should really be called $Flags) set to
CONNECT_REDIRECT but no LocalName member in %NETRESOURCE. See also
http://windowssdk.msdn.microsoft.com/en-us/library/ms739056.aspx
which is the function that implements AddConnection.

Ben
 
B

Ben Morrow

Quoth Ben Morrow said:
Note that you can get a list of currently allocated driver letters with
Win32API::File::getLogicalDrives,

Apologies for replying to myself, but on rereading I've realised that
this reply is completely unsuited to the OP's skill level... :(

For example, you can get the list you want with

use Win32API::File qw/getLogicalDrives/;

my %assigned = map { s/:\\$//; ($_, 1) } getLogicalDrives;
my @free = grep !$assigned{$_}, A..Z;

# or for just the first free letter

use List::Util qw/first/;

my $free = first { !$assigned{$_} } A..Z;

This is a standard Perl technique for finding set difference. You could
also use e.g. Set::Scalar from CPAN.

Ben
 

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

Forum statistics

Threads
474,200
Messages
2,571,046
Members
47,646
Latest member
xayaci5906

Latest Threads

Top