User Control Panel
Advertisements

HELP US, HELP YOU!

Complex Keys

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Thu Jan 01, 2004 7:14 am    Post subject: Reply with quote

How would you list like the first level of multilevel keys in a hash?

Okay, here's the bit where it creates a hash based off of files in a folder.
Code:
# Begin loading up the bots.<br />print ":: Loading bot files... ";<br /><br />my %bots;<br /><br />opendir(DIR, "./bots");<br />   foreach $file (sort(grep(!/^\./, readdir(DIR)))) {<br />  #$file =~ s/\.(.*)//g;<br /><br />  open (BOT, "./bots/$file");<br />  my @bot_data = <BOT>;<br />  close (BOT);<br /><br />  foreach $line (@bot_data) {<br />     chomp $line;<br />     $line =~ s/: /:/g;<br />     my ($what,$is) = split(/:/, $line);<br /><br />     $what =~ s/ //g;<br />     $what = lc($what);<br /><br />     if ($what eq "screenname") {<br />    # We have a screenname.<br />    my $screenname = $is;<br />     }<br />     elsif ($what eq "password") {<br />    # Time to set the password.<br />    $bots{$screenname}->{"pw"} = $is;<br />     }<br />     elsif ($what eq "listener") {<br />    # The client it connects to.<br />    $bots{$screenname}->{"listener"} = $is;<br />     }<br />     else {<br />    $bots{$screenname}->{$what} = $is;<br />     }<br />  #}<br />   }<br />}<br />closedir(DIR);<br />print "Done.\n";


And the text file looks something like this:
Code:
ScreenName: ChaosTesting<br />Password: secret<br />Client: AIM<br />Profile: ./data/aim/profiles/ChaosTesting.html<br />Buddies: ./data/aim/buddies/ChaosTesting.txt


And I've tested printing the hash values and by the time it's done with the above file the hash looks like this:
Code:
%bots = (<br />     ChaosTesting [<br />          Password => secret,<br />          Client => AIM,<br />          Profile => ./data/aim/profiles/ChaosTesting.html,<br />          Buddies => ./data/aim/buddies/ChaosTesting.txt,<br />     ]<br />);


And it would be kind of like that, so each first level is a bot's screenname or handle, and the second level are the details on it. How would I do a foreach keys loop to get the first level?

I tried this:
Code:
foreach $item (keys %bots) {<br />     print "$item\n";<br />}


Didn't get anything. And then I tried this:

Code:
@screennames = $bots;<br />foreach $item (@screennames) {<br />   print "$item\n";<br />}


And that didn't get anything either.

Anyway, the purpose is so that you can have any amount of bots in your "bots" folder and it will run them all simultaneously using their do_one_loop commands.
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Thu Jan 01, 2004 10:29 am    Post subject: Reply with quote

Code:
<br />use Data::Dumper;<br />print Dumper(%bots);<br />


And see what you get. Then you can be sure that its reading the file and filling in the hash correctly.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group