Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: arrays and foreach

by fritz1968 (Sexton)
on Aug 16, 2012 at 17:29 UTC ( #987838=note: print w/replies, xml ) Need Help??

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), );
    push(@userData, [ $id1, $eID, $epID, $sid1, $idD, $idL ], );
    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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987838]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-11-17 15:14 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (204 votes). Check out past polls.