Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: A better (ie.more concise) way to write this?

by BrowserUk (Pope)
on Dec 13, 2013 at 18:23 UTC ( #1067052=note: print w/replies, xml ) Need Help??

in reply to Re: A better (ie.more concise) way to write this?
in thread A better (ie.more concise) way to write this?

I'd do it like this:@a = map { ++$_ % 10 } @a;

That pretty much defeats the purpose. Instead of:

$things{ $thing }{$someotherkey}[$someindex]{$somekey}[ $_ ] = $things +{ $thing }{$someotherkey}[$someindex]{$somekey}[ $_ ] + 1 % 10 for 1 +.. 10;

You get:

@{ $things{ $thing }{$someotherkey}[$someindex]{$somekey} }[ 1 .. 10 ] + = map{ ++$_ % 10 } @{ $things{ $thing }{$someotherkey}[$someindex]{$ +somekey} }[ 1 .. 10 ];

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: A better (ie.more concise) way to write this?
by Laurent_R (Canon) on Dec 13, 2013 at 18:55 UTC
    Then , if you want to modify an existing data structure, what about using the fact that modifying $_ will modify the original array? Something like this, shown under the debugger:
    DB<1> @a = 1..9; DB<2> map{ $_ = ++$_% 10 } @a; DB<3> x @a 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 0 DB<4>
    Well, this obviously works, but something like $c = ++$c is, I believe, not defined in C and probably also not in Perl (i.e. the implementor if free to do whatever). It could be changed to:
    map { $_ ++; $_ = $_ % 10} @a;
    This would probably be more secure against any change of implementation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067052]
[erix]: that would make sense but wikipedia thinks otherwise
[LanX]: oh me was wrong ...
[erix]: but it always works both ways of course
[LanX]: Funny some weeks ago, I met people from the Cimbrian peninsula who didn't know it's called the Cimbrian peninsula ...
[LanX]: ... treid to make smalltalk and felt like Sheldon.
erix looks up Sheldon ...
[erix]: ah. well, that must feel nice, no? ;)
[erix]: not the best way to make friends, though (I suppose)
LanX Fun with Flags anyone?

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-03-22 18:46 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (283 votes). Check out past polls.