Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Syntax explanation required

by eyepopslikeamosquito (Chancellor)
on Jan 03, 2013 at 01:27 UTC ( #1011379=note: print w/replies, xml ) Need Help??

in reply to Syntax explanation required

Two alternative ways derived from: perldoc -q duplicate

my %seen; my @uniq = grep { !$seen{$_}++ } keys(%hash1), keys(%hash2);

use List::MoreUtils qw(uniq); my @uniq = uniq( keys(%hash1), keys(%hash2) );

Replies are listed 'Best First'.
Re^2: Syntax explanation required (uniq)
by LanX (Chancellor) on Jan 03, 2013 at 01:58 UTC
    I was meditating about advising List::MoreUtils:uniq as a best practice, cause I thought it prevents any stringification problems.

    Unfortunately it doesn't! :(

    DB<125> $a=["A"] => ["A"] DB<126> $b=["B"] => ["B"] DB<127> @a=($a,"$a",$b,"$b") => (["A"], "ARRAY(0x96cb0f0)", ["B"], "ARRAY(0x96cfd80)") DB<128> @b= uniq @a => (["A"], ["B"])

    thats quite disappointing for an XS-module ...

    EDIT: Well at least it preserves order...

    Cheers Rolf

    ) I should explain, the problem with using hashes for set operations is that keys are stringified, that means working with anything which isn't a string or at least a scalar comes with a risk.

    Practically it's not possible to safely use a ref as a key because of the resulting string is irreversible.

    DB<130> $h{$a}=5 => 5 DB<131> %h => ("ARRAY(0x96d1f00)", 5)


    improved code example...

      Thank you all. Very helpful !!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011379]
[thezip]: Ooops... I lied. I guess Cygwin is back. I'll just do a tail -f instead. Better. Sorry for the noise.
[Corion]: Once more, I'm looking for a sane client-side framework, but I guess these don't exist. Everything I look at either uses a weirdo home-grown templating language (like Angular in all its incarnations) or uses weirdo Javascript incarnations (like ...
[Corion]: ... Inferno.js, which uses ES2015) or uses some horrible amount of Javascript infrastructure before you can even render a single file.
[Corion]: I'd really like to create a dynamic frontend for my Google Keep clone, but so far, all the templating solutions seem to bring their own template language or require me to hand-code everything in (their own flavour of) Javascript. I'd like something ...
[Corion]: ... that can use templates from the HTML (via <script language="text/ template">... my template ...</script> and otherwise gets out of my way. But it seems that is not how the Javascript world is, currently :-/

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2017-03-27 18:58 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (321 votes). Check out past polls.