[Israel.pm] sliding window on streaming lines

Shlomo Yona shlomo at cs.haifa.ac.il
Sun Jun 6 12:14:19 PDT 2004


Hello, Shlomi.

Thanks for your suggestion.

Here's the recursive function I wrote today in my notebook
this morning after I disconnected from the web. 
I've typed it to try it and it worked well.

I'll next try to read yours and see if it fits my needs and
if it is also better than mine, I'll gladly use it.

Here's mine (recall how a lattice might look like from my
previous email):

	sub lattice2vectors {
		my ($lattice) = @_;
		return [ {t=>1,p=>[]}] if @$lattice==0;
		my $current = shift @$lattice;
		my $post = lattice2vectors($lattice);
		my $pasted=[];
		while (my ($current_key, $current_value) = each %$current) {
			foreach my $p (@$post) {
				if ($current_value * $p->{t}) { # 1
					push @$pasted, {
						t => 1,
						p => [$current_key,@{$p->{p}}],
					};
				} else { # 0
					push @$pasted, {
						t => 0,
						p => [$current_key,@{$p->{p}}],
					};
				}
			}
		}
		$current=undef; # give back memory...
		$post=undef;	# like it matters...
		return $pasted;
	}

The code is a bit cumbersome as I wanted to keep the
information wether the path was "all 1s" or not... so the
vectors I create from the lattice are array refs with hash
refs as elements. The hash refs look like this:
          {
            'p' => [
                     'foo'
                     'moo',
                     'baz',
                   ],
            't' => 1
          },
of course, content may vary...


-- 
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/



More information about the Perl mailing list