http://qs321.pair.com?node_id=337135

winbeing has asked for the wisdom of the Perl Monks concerning the following question:

Hello, All
New to Perl..
Just want to print "userName" and current type of User License.
Please, help. Thanks
igor

Perl v5.6.1 for MSWin32===============================================

(@curusers = ars_GetListUser($ctrl, 2)) || die $ars_errstr; for($i = 0; $i < $#curusers ; $i+=2){ $key = $curusers[$i]; $value = $curusers[$i+1]; print "$i : $key : $value\n";} for $i (0 .. $#curusers){ for $value ( keys %{$curusers[$i]}) { print "$i:$value is $curusers[$i]{$value}\n"; } } ============================================================ 0 : HASH(0x1abf184) = HASH(0x256ba30) 0:userName is eprehn 0:licenseType is ARRAY(0x1ab51a8) 0:defaultNotifyMech is 0 0:connectTime is 1079451285 0:emailAddr is 0:currentLicenseType is ARRAY(0x1ab52e0) 0:lastAccess is 1079451886 0:licenseTag is ARRAY(0x1ab51c0)

20040315 Edit by Corion: Added code tags, added formatting

Replies are listed 'Best First'.
Re: Just want to print "userName"
by Mr. Muskrat (Canon) on Mar 17, 2004 at 01:36 UTC

    You really should read the ARSperl Programmer's Manual! ARSperl is well documented and even has examples that would have been of use to you. ars_GetListUser returns an array of hash references. The licenseType key of the referenced hashes is an array reference.

    Incomplete and totally untested code follows:

    # ... start of code (@curusers = ars_GetListUser($ctrl, 2)) || die $ars_errstr; foreach my $hashref (@curusers) { print "userName: ", $hashref->{userName}, " licenceType: ", @{$hashr +ef->{licenseType}}, "\n"; } # ... rest of the code here

Re: Just want to print "userName"
by matija (Priest) on Mar 16, 2004 at 21:51 UTC
    Nothing simpler: in the second loop, lose the inner (for  $value) loop, and replace it with the simple
    print "$i: userName is $curusers[$i]{$value}\n";
Re: Just want to print "userName"
by iburrell (Chaplain) on Mar 16, 2004 at 21:50 UTC
    Can you reformat your code? It is hard to tell if you have a logic error or if the formatting is messing it up. The important thing is how you are accessinging the array elements. "$curusers$i" is meaningless.
    for $i (0 .. $#curusers) { print "$i: $value: $curusers[$i]{$value}"; }
    Also, is there a reason you are stepping through the @curusers array two elements at a time
      When you see something like $curusers$i, the fact that $i shows as a link indicates that the poster did have brackets but forgot <code> so it was interpreted as a link and the brackets removed.

      You can click on the little tiny "xml" link under the node title to see what was actually entered.

Re: Just want to print "userName"
by tcf22 (Priest) on Mar 16, 2004 at 21:57 UTC
    You don't need to loop through the hash in the second loop. Try this:
    for $i (0 .. $#curusers){ print "$i:userName is $curusers[$i]{userName}\n"; }
    This is one of a few issues I see. Maybe seeing the code for ars_GetListUser() would give us a litte more insite.

    Update:Fixed wrong answer. I'm just not thinking.

    - Tom