Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

This is a useless node

by shagbark (Acolyte)
on Apr 25, 2018 at 02:37 UTC ( #1213506=perlquestion: print w/replies, xml ) Need Help??

shagbark has asked for the wisdom of the Perl Monks concerning the following question:

I asked a question, then realized that there was no point in asking what I was asking.

So I have deleted it. does not allow deletion of nodes, so here we are.

Replies are listed 'Best First'.
Re: This is a useless node
by Marshall (Canon) on Apr 25, 2018 at 05:01 UTC
    Update your original post.
    You can't delete it, but you can modify it and add stuff to it.
    Everybody here occasionally makes mistakes.
    Not a big deal.

      Marshall hits the nail on the head here. While you cannot delete your original node, you can edit it.

      If you originally asked a question for which you have found the answer, just add the answer into the question with an edit. This will enable others to find the question (and answer!) should they be searching for answers to the same (or a similar) question.

Re: Hash slice from a hashref, into a hashref
by haukex (Bishop) on Apr 25, 2018 at 17:42 UTC
    I just realized the question is useless.

    I'm not sure why you think so, how to take a slice of a hash is a valid question, maybe you could explain what resolution you found for your question?

    Anyway, there are several ways to make a (shallow) copy of a part of a hash, here are a few:

    1. Using map: %slice = map { $_ => $hash{$_} } @keys;
    2. Using Foreach Loops (in this case as a statement modifier): $slice{$_} = $hash{$_} for @keys;
    3. Using Slices: @slice{@keys} = @hash{@keys};
    4. Using Key/Value Hash Slices, new in Perl 5.20: %slice = %hash{@keys};
    my %h is really big and I don't have enough RAM to make a copy of it

    This makes the question interesting. It turns out that, at least on my machine with Perl 5.26, from the options above:

    1. map takes the most memory, about 180% as much as a regular @ slice,
    2. a regular @ slice takes about as much memory as a key/value % slice,
    3. a key/value % slice takes about as much memory as a regular @ slice, and
    4. the for loop variant takes the least amount of memory, taking only about 88% of a regular @ slice.
    I want to load the slice directly into a hashref

    As it turns out, changing my %slice into my $slice and changing the syntaxes into the following doesn't really make a big difference:

    1. $slice = { map { $_ => $hash{$_} } @keys }; - about 6% more memory
    2. @{$slice}{@keys} = @hash{@keys}; - about the same amount of memory
    3. $slice = {%hash{@keys}}; - about the same amount of memory
    4. $slice->{$_} = $hash{$_} for @keys; - about the same amount of memory

    On the other hand, if for example the values in your hash are huge, then perhaps a different approach is needed - for example, in your second hash you could store references to the values of the first hash. Or, you may not even need to create a second hash in the first place, perhaps simply keeping the list of keys around to select values from the first hash is enough.

Re: This is a useless node
by Your Mother (Archbishop) on Apr 25, 2018 at 04:56 UTC

    Just about every question whether it seems pointless or silly or whatever contributes to the site and often sparks interesting replies so is considered worth keeping. It's the ethos of the place that things are transparent so deletions or silent redaction are frowned upon, sometimes openly blocked. I don't have a dog in the no deleted nodes fight but don't mind going with the flow either.

Re: This is a useless node
by haukex (Bishop) on Apr 25, 2018 at 09:13 UTC
    I asked a question, then realized that there was no point in asking what I was asking.

    Don't worry, just about everyone here has had moments like that. How do I change/delete my post? explains a bit more about what the others have said, that it's best to either edit your original post (or answer your own question), so that others who may have the same question can learn from it.

Re: This is a useless node
by virtualsue (Vicar) on Apr 25, 2018 at 11:08 UTC
    I'm so tempted to frontpage this.
        Because not allowing users to delete nodes is frankly silly, not matter what tales are told about why it isn't allowed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1213506]
Approved by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-04-23 07:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found