For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2005 > what kind of structure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author what kind of structure
Ianfp

2005-03-24, 8:56 am

i want to know how kind of structure this code generates .... and how can i print it..

@toks = grep { $_->[0] !~ /^(and|with|has|wants|options|here)$/i } @toks;
local ($poll, $user, $i);
for($i=0; $i<@toks; $i++) {
local $t = $toks[$i];

# Server options
if ($t->[0] eq 'poll' || $t->[0] eq 'server' ||
$t->[0] eq 'skip' || $t->[0] eq 'defaults') {
# Start of a new poll
$poll = { 'line' => $t->[1],
'file' => $_[0],
'index' => scalar(@rv),
'skip' => ($t->[0] eq 'skip'),
'defaults' => ($t->[0] eq 'defaults') };
$poll->{'poll'} = $toks[++$i]->[0] if (!$poll->{'defaults'});
undef($user);
push(@rv, $poll);
}
elsif ($t->[0] eq 'proto' || $t->[0] eq 'protocol') {
$poll->{'proto'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'via') {
$poll->{'via'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'port') {
$poll->{'port'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'timeout') {
$poll->{'timeout'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'interface') {
$poll->{'interface'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'monitor') {
$poll->{'monitor'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'auth' || $t->[0] eq 'authenticate') {
$poll->{'auth'} = $toks[++$i]->[0];
}
# User options
elsif ($t->[0] eq 'user' || $t->[0] eq 'username') {
$user = { 'user' => $toks[++$i]->[0] };
push(@{$poll->{'users'}}, $user);
}
elsif ($t->[0] eq 'pass' || $t->[0] eq 'password') {
$user->{'pass'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'is' || $t->[0] eq 'to') {
$i++;
while($i < @toks &&
$toks[$i]->[1] == $t->[1]) {
push(@{$user->{'is'}}, $toks[$i]->[0]);
$i++;
}
$i--;
}
elsif ($t->[0] eq 'folder') {
$user->{'folder'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'keep') { $user->{'keep'} = 1; }
elsif ($t->[0] eq 'nokeep') { $user->{'keep'} = 0; }
elsif ($t->[0] eq 'no' && $toks[$i+1]->[0] eq 'keep') {
$user->{'keep'} = 0;
$i++;
}
elsif ($t->[0] eq 'fetchall') { $user->{'fetchall'} = 1; }
elsif ($t->[0] eq 'nofetchall') { $user->{'fetchall'} = 0; }
elsif ($t->[0] eq 'no' && $toks[$i+1]->[0] eq 'fetchall') {
$user->{'fetchall'} = 0;
$i++;
}
elsif ($t->[0] eq 'ssl') { $user->{'ssl'} = 1; }
elsif ($t->[0] eq 'nossl') { $user->{'ssl'} = 0; }
elsif ($t->[0] eq 'no' && $toks[$i+1]->[0] eq 'ssl') {
$user->{'ssl'} = 0;
$i++;
}
elsif ($t->[0] eq 'preconnect') {
$user->{'preconnect'} = $toks[++$i]->[0];
}
elsif ($t->[0] eq 'postconnect') {
$user->{'postconnect'} = $toks[++$i]->[0];
}

else {
# Found an unknown option!
if ($user) {
push(@{$user->{'unknown'}}, $t->[0]);
}
elsif ($poll) {
push(@{$poll->{'unknown'}}, $t->[0]);
}
}

if ($poll) {
if ($i<@toks) {
$poll->{'eline'} = $toks[$i]->[1];
}
else {
$poll->{'eline'} = $toks[$#toks]->[1];
}
}
}







thanks..

Offer Kaye

2005-03-24, 8:56 am

On Thu, 24 Mar 2005 05:36:36 -0300, ianfp wrote:
> i want to know how kind of structure this code generates .... and how can i print it..
>
> @toks = grep { $_->[0] !~ /^(and|with|has|wants|options|here)$/i } @toks;
> local ($poll, $user, $i);


Use the Data::Dumper module. Add this at the end of the code:
use Data::Dumper;
print Dumper(\@toks, $poll, $user, $i); # looking at a whole bunch of vars

Remove the lines when you finish debugging your code. Read "perldoc
Data::Dumper" for more details.

Hope this helps,
--
Offer Kaye
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com