For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2007 > Re: Iterating over all elements in a 3D array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Iterating over all elements in a 3D array
Michele Dondi

2007-03-27, 7:05 pm

On Tue, 27 Mar 2007 14:47:54 +0100, nikolas pontikos
<n.pontikos@cs.ucl.ac.uk> wrote:

>Is there cleaner way of writing this:
>
>foreach $send (0...$#sr) {
> foreach $recv (0...$#{$sr[$send]}) {
> foreach $round (0...$#{$sr[$send][$recv]}) { print
>"$sr[$send][$recv][$round]:\n";
> }
> }
>}


local $\=":\n";
for (@sr) {
for(@$_) {
for (@$_) {
print;
}
}
}


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
nikolas pontikos

2007-03-27, 7:05 pm

Michele Dondi wrote:
> On Tue, 27 Mar 2007 14:47:54 +0100, nikolas pontikos
> <n.pontikos@cs.ucl.ac.uk> wrote:
>
>
> local $\=":\n";
> for (@sr) {
> for(@$_) {
> for (@$_) {
> print;
> }
> }
> }
>
>
> Michele


So $\ is a perl variable that's appended to every string which gets
printed out? That's pretty I didn't know that.

Thanks,
--
Nikolas.
Michele Dondi

2007-03-27, 7:05 pm

On Tue, 27 Mar 2007 15:40:19 +0100, nikolas pontikos
<n.pontikos@xxxxxx.com> wrote:

>So $\ is a perl variable that's appended to every string which gets
>printed out? That's pretty I didn't know that.


I mentioned it beacause I suspected that, and I'm lazily-keen on
argumentless print()s. See

perldoc perlvar

for other builtin variables.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com