Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: treat pairs, set as one item: looking for better way

by remiah (Hermit)
on Oct 20, 2013 at 02:50 UTC ( #1058970=note: print w/replies, xml ) Need Help??

in reply to Re: treat pairs, set as one item: looking for better way
in thread treat pairs, set as one item: looking for better way

Hello, thanks for reply.
It took me some time to understand this.

#!usr/bin/perl use strict; use warnings; use Data::Dumper; my @key_array = 'a' .. 'z'; my @set_array = ( ['a', 'b'], ['e','f'], ['f','g'],['x','y'] ); # {a =>{a=>1}, b=>{b=>1}, ....} my %set = map {$_ => {$_ => 't'}} @key_array; for my $s (@set_array) { @{$set{$_}}{@$s} = (1) x @$s for @$s; =my_memo #same as ... for (@$s){ @{$set{$_}}{@$s} = (1) x @$s } #fill hash value at one time my %h; @h{ 1 .. 5 }= 'A' ..'F'; #(1) x @$s if @$s === (a,b) , (1) x @$s === (1,1) #vertex which has edge information .. #{ a=>{a=>1,b=>1}, b=>{a=>1,b=>1} ... =cut } my $saw = ''; print map "$_\n", grep $saw =~ s/^(?!.*$_)/$_ /, =my_memo # ??? how it can remove duplicate like "a,b","a,b" or "e,f,g","e, +f","f,g" here comes "e,f,g", $saw='', ==> $saw="e,f,g" ==> +true #saw doesn't have "" replace ^ to "e,f,g" "a,b" $saw="e,f,g" ==> $saw="a,be,f,g" ==> +true #saw doesn't have "a,b", replace ^ to "a,b "a,b" $saw="a,be,f,g" ==> $saw="a,be,f,g" = +=> false #saw have "a,b" not match; "e,f" $saw="a,be,f,g" ==> $saw="a,be,f,g" = +=> false #saw have "e,f" not match; ... removes edge already seen ... really great. =cut sort {length $b <=> length $a || $a cmp $b} #sort by length + desc || a cmp b map join(',', sort keys %$_), #"a,b" ... sort +ed values %set; # values => {a= +>1,b=>1}, {a=>1,b=>1},{c=>1},{d=>1},,,
short and great!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058970]
[shmem]: silly question, silly answer:
[Discipulus]: i know, i know..
[shmem]: man perlfunc |perl -nle '$ok++ if /Alphabetical Listing of Perl Functions/;if($ok ){$s{$1}++if /^ (\w+)/}}{for(keys %s){$f="prototype \\\&CORE::$_"; eval"$f"||delete $CORE::{$_}}print for sort keys%CORE::'
[shmem]: well, there are some builtins which don't have a prototype...
[Discipulus]: eh eh.. i was looking in toke.c but dunno if is already used
[shmem]: oh the whitespace in the regex got condensed, meh
[shmem]: should be /^ {7}(\w+)/ or such
[shmem]: least for my perldoc on Linux debian 8
[Discipulus]: mmh.. at themomemt i just an old 5.8 and outputs just GLOBAL::

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-05-23 10:08 GMT
Find Nodes?
    Voting Booth?