in reply to Populating the array, what am I doing wrong.

Your code has lots of problems. For starters, the line

@fields=~'/opt/apache/1.3.27/cgi-bin/cspireutils/ldapsearch -h 172.30 +.58.243 -p 389 -D $dirsrv -w 'passwd' -b ou=subscribers,ou=users,ou=p +rague,ou=domains,ou=cz,ou=domains,o=chello cn=$sid dn jrMailBoxId jrM +ailboxAliasStore jrPWPUID jrPWPUserPrefs jrUserFriendlyID';
is completely bogus Perl. What in the world did you mean to be doing there?

A few lines further down, it looks like you're reading from stdin with

while (<>) {
What data are you expecting to read from stdin? I.e. are you expecting to pipe the input from another program's output?

This kind of touches on another bug, which is that you have declared %thisrecord inside that while loop, but you try to use it later in the program. This doesn't make sense, and merely moving the %thisrecord declaration outside the loop probably won't result in a correct program.

And that relates to another bug: You try to use a field from the hash in a string, as "%thisrecord{'jrPWPUID'}... but that is incorrect; it should be "$thisrecord{'jrPWPUID'}... (Note the $, vice %.)

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^2: Populating the array, what am I doing wrong.
by trelane (Initiate) on Apr 25, 2008 at 14:30 UTC
    What in the world did you mean to be doing there? Well
    I was trying to populate the @fields with the selected objects from the ldapsearch

    The ldapsearch, if you do it outside of the script, returns with:
    cn=t43311,ou=subscribers,ou=users,ou=country,ou=domains,ou=cz,ou=chell +o jrMailBoxId=poohbear@woods.com jrMailboxAliasStore=5485113511 jrPWPUID=poohbear jrPWPUserPrefs=poohbear jrUserFriendlyID=poohbear

    but all that seems to get populated in the array is dn jrMailBoxId jrMailboxAliasStore jrPWPUID jrPWPUsersPrefs jrUserFriendlyID

      Ok, well you're going about that all wrong. To execute an external program and get its output into an array of lines, use qx():

      @fields = qx( /opt/apache/1.3.27/cgi-bin/cspireutils/ldapsearch -h 172 +.30.58.243 -p 389 -D $dirsrv -w 'passwd' -b ou=subscribers,ou=users,o +u=prague,ou=domains,ou=cz,ou=domains,o=chello cn=$sid dn jrMailBoxId +jrMailboxAliasStore jrPWPUID jrPWPUserPrefs jrUserFriendlyID );
      then you can easily iterate over the lines with foreach.

      Alternatively, you could use the while(<>) construct to read from a pipe connected to the output of an external program:

      open P, $command # as above or die "can't run $command - $!"; while (<P>)
      but note specially the use of an explicit filehandle inside the angle brackets. Omit that, and you'd be reading from stdin.

      If you assign to @fields as above, you'll be overwriting the array of values you orginally assigned to it. Is that what you intended?

      A word spoken in Mind will reach its own level, in the objective world, by its own weight