http://www.perlmonks.org?node_id=987838


in reply to Re: arrays and foreach
in thread arrays and foreach

I forgot about Dumper. Thanks for reminding me. It seems my was trying to get too tricky with my original code. I fixed the error by doing the following when I "pushed" data into the array:

my $id1=$user->getID(); my $eID=$user->getExternalID(); my $epID=$user->getExternalParentID(); my $sid1=$user->getSid(); my $idD=$user->getDomain(); my $idL=$user->getLockedTimes(); push(@userData, "$id1;$eID;$ipID;$sid1;$idD;$idL");

It all works as expected now.

Replies are listed 'Best First'.
Re^3: arrays and foreach
by MidLifeXis (Monsignor) on Aug 16, 2012 at 18:04 UTC

    Instead of push(@userData, "$id1;$eID;$epID;$sid1;$idD;$idL");, may I recommend

    push(@userData, join(";", $id1, $eID, $ipID, $sid1, $idD, $idL), );
    or
    push(@userData, [ $id1, $eID, $epID, $sid1, $idD, $idL ], );
    or
    push(@userData, { id => $id1, externalId => $eID, externalParentId => $epID, sid => $sid1, domain => $idD, lockedTimes => $idL, }, );

    The first alternative makes it easier to change the delimiter, not repeat yourself, etc. The second allows you to avoid the split later on in your code. The third documents (for some definition of documentation) the structure that you are using.

    Depending on your needs, one of these may be more appropriate.

    --MidLifeXis