in reply to Re: Adding only searched values to array ref
in thread Adding only searched values to array ref
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Adding only searched values to array ref
by AnomalousMonk (Archbishop) on Sep 20, 2021 at 19:59 UTC | |
There are a few ways to add (actually append in this case) one array to another, even if they are array references. A couple: Both methods produce the same results. I prefer the method using push: it's more familiar and readable IMHO, possibly a bit faster. In both cases, a shallow copy of the appended array is done. Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
|
Re^3: Adding only searched values to array ref
by Marshall (Canon) on Sep 22, 2021 at 09:07 UTC | |
Update: As ++AnomalousMonk points out, my "solution" had the wrong sense on the compare! It should be ne instead of == just as he suggested. I put the my original code into readmore brackets. The new code with one line of code + comments changed is below. Note this brings up the issue of whether or not a duplication can occur of a record already in the $all array? see below. Update2: Well, ok. I will show how to get rid of the dupes. Because this code illustrates another aspect of Perl. It is perfectly ok for the input and the output of a grep to be the same array. Perl will keep it straight so that it doesn't "write over its own input". Of course this can also be formulated using an explicit for loop. All greps "hide" a for loop. It is there even if it doesn't quite look that way. Read more... (2 kB) | [reply] [d/l] [select] |
by AnomalousMonk (Archbishop) on Sep 22, 2021 at 11:03 UTC | |
Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by Marshall (Canon) on Sep 22, 2021 at 22:06 UTC | |
Sorry for the goof! This issue just highlights the importance of showing "desired output" in the Original Post. If such a thing had existed, I would have detected this error myself. I did see this alpha-numeric account number. And thought about things such as how to sort the @$all by account number. And now I see also either preventing or removing duplicate records for @$all might be necessary? However the OP is not asking about that at this time. Let's see what develops along that front, if anything.
| [reply] |