Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: (OT) Interview questions -- your response?

by tadman (Prior)
on Sep 04, 2002 at 07:32 UTC ( [id://194994]=note: print w/replies, xml ) Need Help??


in reply to (OT) Interview questions -- your response?

Here's my take on Q1, which isn't entirely original, but is self-contained:
my @c = do { my %tmp = map { $_ => 1 } @a; grep {$tmp{$_}} @b };
Here's my take on Q2 which ended up the same as others:
for (1..@foo/2) { @foo[$_-1,-$_] = @foo[-$_,$_-1]; }
The first thing that came to mind was:
@foo = map { pop(@foo) } 1..@foo;
But that's not precisely an in-place version, even though you could argue that the temporary "array" only holds things that have been removed from @foo.

Replies are listed 'Best First'.
Re: Re: (OT) Interview questions -- your response?
by demerphq (Chancellor) on Sep 04, 2002 at 19:01 UTC
    If your going to use $_ anyway you might as well use the more efficient modifier form (no scope handling overhead).
    @foo[$_-1,-$_] = @foo[-$_,$_-1] for (1..@foo/2);
    BTW: I think this is probably the best implementation (starting at one instead of zero) of all that have been present along this line (especially including my embarrasing fencepost error version) so ++ to you.

    Yves / DeMerphq
    ---
    Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found