[28091] in Perl-Users-Digest
Perl-Users Digest, Issue: 9455 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 12 14:05:43 2006
Date: Wed, 12 Jul 2006 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 12 Jul 2006 Volume: 10 Number: 9455
Today's topics:
Bad protocol 'tcp' garrett.hennessey@gmail.com
Re: Bad protocol 'tcp' <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Bad protocol 'tcp' garrett.hennessey@gmail.com
Re: Capture a frame from AVI/MOV pjsenthil@gmail.com
Re: converting line input into columns <tadmc@augustmail.com>
Re: Dereferencing Hash of Arrays <mritty@gmail.com>
Re: Dereferencing Hash of Arrays <nobull67@gmail.com>
Re: Dereferencing Hash of Arrays <tadmc@augustmail.com>
Re: Dereferencing Hash of Arrays <tadmc@augustmail.com>
Re: finding perl info on google can be hard <sgt19@tid.es>
Re: finding perl info on google can be hard ilikesluts@gmail.com
Re: finding perl info on google can be hard <sherm@Sherm-Pendleys-Computer.local>
Re: Perl +lists/unions/intersection: <glennj@ncf.ca>
Re: Perl +lists/unions/intersection: <orodionov@gmail.com>
Re: Perl +lists/unions/intersection: xhoster@gmail.com
Re: Perl +lists/unions/intersection: <orodionov@gmail.com>
Re: Perl +lists/unions/intersection: <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Jul 2006 09:31:08 -0700
From: garrett.hennessey@gmail.com
Subject: Bad protocol 'tcp'
Message-Id: <1152721868.564521.305880@s13g2000cwa.googlegroups.com>
Hello -
I have searched endlessly for a solution to the following problem. I am
trying to use various packages within the perl 'Net' package (ie.
Net::FTP, Net::SMTP, etc). Everytime I try to use these packages I get
the following error: Net::FTP: Bad protocol 'tcp'. I also get this
error when using ppm.
I am using Active Perl and also cygwin perl, and they both exhibit the
same error.
One important thing to note is that I do not have this problem on other
computers on my network. All the computers are running either Windows
200 or XP. Searching through the newsgroups and mailing list archives
at Active Perl, I've found multiple people suggest adding an
environment variable for http_proxy, but I am not behind a proxy. Also
people have suggested checking for the file protocol in
c:\winnt\system32\drivers\etc directory. This file exisits and is the
same as other computers on my netwok where this all works.
One big clue I have is that any call to 'getprotobyname' returns an
empty string. This is also true for 'getprotobynumber'. This same call
on the other computers returns the appropriate values as indicated in
the protocol file.
Here's some example code:
use strict;
use warnings;
use Net::FTP;
my $hostname = '192.168.1.211';
my $username = 'xxxx'; # removed username
my $password = 'xxxxx'; # removed passoword
my $ftp = Net::FTP->new("192.168.1.211", Debug => 1)
or die "Cannot connect to 192.168.1.211: $@";
which produces:
Cannot connect to 192.168.1.211: Net::FTP: Bad protocol 'tcp' at ftp.pl
line 9.
Any help would be greatly appreciated!
Thanks,
Garrett Hennessey
------------------------------
Date: Wed, 12 Jul 2006 18:44:02 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Bad protocol 'tcp'
Message-Id: <44b526ce$0$838$ba4acef3@news.orange.fr>
garrett.hennessey@gmail.com wrote:
> Hello -
>
> I have searched endlessly for a solution to the following problem. I am
> trying to use various packages within the perl 'Net' package (ie.
> Net::FTP, Net::SMTP, etc). Everytime I try to use these packages I get
> the following error: Net::FTP: Bad protocol 'tcp'. I also get this
> error when using ppm.
>
> I am using Active Perl and also cygwin perl, and they both exhibit the
> same error.
>
> One important thing to note is that I do not have this problem on other
> computers on my network. All the computers are running either Windows
> 200 or XP. Searching through the newsgroups and mailing list archives
> at Active Perl, I've found multiple people suggest adding an
> environment variable for http_proxy, but I am not behind a proxy. Also
> people have suggested checking for the file protocol in
> c:\winnt\system32\drivers\etc directory. This file exisits and is the
> same as other computers on my netwok where this all works.
>
> One big clue I have is that any call to 'getprotobyname' returns an
> empty string. This is also true for 'getprotobynumber'. This same call
> on the other computers returns the appropriate values as indicated in
> the protocol file.
>
> Here's some example code:
> use strict;
> use warnings;
> use Net::FTP;
>
> my $hostname = '192.168.1.211';
> my $username = 'xxxx'; # removed username
> my $password = 'xxxxx'; # removed passoword
>
> my $ftp = Net::FTP->new("192.168.1.211", Debug => 1)
> or die "Cannot connect to 192.168.1.211: $@";
>
> which produces:
> Cannot connect to 192.168.1.211: Net::FTP: Bad protocol 'tcp' at ftp.pl
> line 9.
>
> Any help would be greatly appreciated!
>
I can reproduce this error by commenting out the "tcp" line in
c:\WINDOWS\System32\Drivers\Etc\protocol
Mark
------------------------------
Date: 12 Jul 2006 10:20:39 -0700
From: garrett.hennessey@gmail.com
Subject: Re: Bad protocol 'tcp'
Message-Id: <1152724839.763687.237870@m79g2000cwm.googlegroups.com>
Thanks Mark -
This supports my belief that for whatever reason, my 'protocol' file is
never being used. Any ideas why this may happen?
Mark Clements wrote:
> garrett.hennessey@gmail.com wrote:
> > Hello -
> >
> > I have searched endlessly for a solution to the following problem. I am
> > trying to use various packages within the perl 'Net' package (ie.
> > Net::FTP, Net::SMTP, etc). Everytime I try to use these packages I get
> > the following error: Net::FTP: Bad protocol 'tcp'. I also get this
> > error when using ppm.
> >
> > I am using Active Perl and also cygwin perl, and they both exhibit the
> > same error.
> >
> > One important thing to note is that I do not have this problem on other
> > computers on my network. All the computers are running either Windows
> > 200 or XP. Searching through the newsgroups and mailing list archives
> > at Active Perl, I've found multiple people suggest adding an
> > environment variable for http_proxy, but I am not behind a proxy. Also
> > people have suggested checking for the file protocol in
> > c:\winnt\system32\drivers\etc directory. This file exisits and is the
> > same as other computers on my netwok where this all works.
> >
> > One big clue I have is that any call to 'getprotobyname' returns an
> > empty string. This is also true for 'getprotobynumber'. This same call
> > on the other computers returns the appropriate values as indicated in
> > the protocol file.
> >
> > Here's some example code:
> > use strict;
> > use warnings;
> > use Net::FTP;
> >
> > my $hostname = '192.168.1.211';
> > my $username = 'xxxx'; # removed username
> > my $password = 'xxxxx'; # removed passoword
> >
> > my $ftp = Net::FTP->new("192.168.1.211", Debug => 1)
> > or die "Cannot connect to 192.168.1.211: $@";
> >
> > which produces:
> > Cannot connect to 192.168.1.211: Net::FTP: Bad protocol 'tcp' at ftp.pl
> > line 9.
> >
> > Any help would be greatly appreciated!
> >
>
> I can reproduce this error by commenting out the "tcp" line in
>
> c:\WINDOWS\System32\Drivers\Etc\protocol
>
> Mark
------------------------------
Date: 12 Jul 2006 08:32:50 -0700
From: pjsenthil@gmail.com
Subject: Re: Capture a frame from AVI/MOV
Message-Id: <1152718370.344230.243630@m79g2000cwm.googlegroups.com>
First of all thanx for your reply.
I read the mplayer. there is option like converting the whole video
file into frames..but not the required frame.
That option is also there "grab_frame" but it is not implemented.
one more thing..I have to embed the Mplayer into a web page.how can i
do that .
and also how can i control the command line options Mplayer from my
perl code.through which package can i able to do it.
Regards
Senthil
Mumia W. wrote:
> pjsenthil@gmail.com wrote:
> > Hi,
> >
> >
> > I am writing code in CGI-perl,in which i am want to capture
> > frames from a media player which runs mpeg or any video.(mov file in
> > Quick time).'
> >
> > the purpose of doing this is to generate thumbnails (snapshot ) of the
> > video when it is in the play mode..
> >
> > Friends pl help..Becoz i am not familiar in working on images.
> >
> > Regards
> > Senthil
> >
>
> Perhaps you should get mplayer and investigate
> mplayer's command line parameters. Because mplayer
> creates something other than a normal X Window, you'll
> probably not be able to simply take a snapshot of the
> window image. Instead, you'll want to command mplayer
> to output one of the video frames to disk.
>
> HTH
------------------------------
Date: Wed, 12 Jul 2006 11:47:31 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: converting line input into columns
Message-Id: <slrneba9t3.cp3.tadmc@magna.augustmail.com>
vanagas99@yahoo.com <vanagas99@yahoo.com> wrote:
> Tad McClellan wrote:
>> vanagas99@yahoo.com <vanagas99@yahoo.com> wrote:
>> > A. Sinan Unur wrote:
>> >> vanagas99@yahoo.com wrote in
>> >> news:1152496902.511701.167670@p79g2000cwp.googlegroups.com:
>> >> > Tad McClellan wrote:
>> >> >> vanagas99@yahoo.com <vanagas99@yahoo.com> wrote:
>> >> >>
>> >> >> > sorry,
>> >> >>
>> >> ...
>> >>
>> >> >> It is pretty clear that your "sorry" is not at all sincere,
[ snip rest of full-quote, including .sig ]
> Tad, what's the matter?
You are not composing your followups in accordance with widely
accepted netiquette. (Probably because you did not know that
it was bad manners.)
But you'd been educated about those before I even entered the thread.
> So I made a mistake.
^
^
I did not say anything when you made _a_ mistake!
I did not even say anything when you repeated the same mistake
a 2nd time.
I did not enter the thread until you repeated the same mistake
a 3rd time.
Now you have repeated it for a 4th time.
> Bid deal...
Learn to compose followups the way folks like them, or be prepared
to annoy them further.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Jul 2006 08:45:19 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Dereferencing Hash of Arrays
Message-Id: <1152719119.183014.58560@s13g2000cwa.googlegroups.com>
Jennifer I. Drake wrote:
> I do have a the 'my ($keysRef) = @_' in my code. I tried to remove
> some of the code to be more clear. I guess it has the opposite effect.
> The rest of the code is quite long and contains a lot of
> CGI/PostgreSQL calls that don't do anything with this issue, so I
> wasn't sure if I should post all of it.
You were right to be weary about that. What you *should* have done was
created a *short* but still complete script that demonstrates your
error. That is, par your code down, removing the bits that aren't
relevant to the problem at hand, until you are left with a short script
that someone can run by copy and pasting which still demonstrates your
error.
Please read the Posting Guidelines that are posted here twice a week.
They contain valuable information that will help you get the most help
out of this newsgroup.
> ###############################################
> sub GetData{
> ###############################################
>
> my ($keysRef, $exptIDsRef, $IDToNameRef, $keyToSUIDRef, $SUIDToKeyRef,
> $where, $join, $from, $coordsRef, $retrieveBy, $selectedColumn,
> $joinHashRef) = @_;
>
> my $exptnum = scalar(@$exptIDsRef);
>
> print "Using ", font({-color=>'red'}, "$exptnum"), " experiments and
> retrieving from the ", font({-color=>'red'}, "Result"), " table for
> each experiment\n", p;
>
> my ($exptname, $exptid, $seqname);
> my ($key, $spot, $suid, $val, $sth, @values, $keyOffset, %data);
I'm willing to bet this is your central problem. A good general rule
is to always declare variables in the shortest scope possible.
> my $count = 1;
>
> my $select = "SELECT RESULT.SPOT, RESULT.LOG_RAT2N_MEAN,
> RESULT.CH1I_MEAN ";
>
> $from =~ s/, $//;
>
> my %reverseExpts;
> &selectReverse($exptIDsRef, \%reverseExpts);
Why are you prepending your subroutine calls with the ampersand? Do
you know what two side effects that produces? If not, you shouldn't be
using it.
> my $reverseFlag = $query->param('isReverse');
>
> my $sql = "$select $from $join AND exptid = ? $where $selectedColumn
> IS NOT NULL";
>
> my $sth = $dbh->prepare($sql);
>
> print "Retrieving data...\n<br>";
>
> #print "SQL Statement: $sql<br>";
> eval {
> foreach $exptid (@{$exptIDsRef}) {
>
> print "$count: $$IDToNameRef{$exptid}",br;
>
> print "Experiment ID: $exptid<br>";
> $sth->execute($exptid);
>
> while(($spot, @values) = $sth->fetchrow_array) {
Here you're re-assigning @values each time through your loop, but
you're not re-*declaring* it. That is, you're re-using the same
variable each time through...
> if (($reverseFlag eq 'Y' && $reverseExpts{$exptid} eq 'N') ||
> ($reverseFlag eq 'N' && $reverseExpts{$exptid} eq 'Y')) {
> for (my $i = 0; $i < scalar(@values); $i++) {
> $values[$i] = -$values[$i];
> }
> }
Er, what's the point of this? Are you really just trying to make every
value in the array it's opposite? That's really so verbose as to be
difficult to read. Try:
$_ *= -1 for @values;
>
>
> $$keysRef{$spot} = 1;
> $data{$spot}{$exptid} = \@values;
...and here, you're storing multiple references to that same variable
at different points in your structure. So every time you changed the
contents of @values above, you changed the values previously stored in
your overall structure. Change that while loop to:
while (my ($spot, @values) = $sth->fetchrow_array) {
>
> }
>
> if ((!($count%$numToDump)) || ($count==$exptnum)) {
> print "Caching data to disk...\n";
>
> &StoreData(\%data, $count, $exptIDsRef, $IDToNameRef);
> undef %data;
Why are you undef'ing %data? If you want %data to go away at this
point so you get a new blank version of it next time through your loop,
then properly scope your variables. Declare `my %data` in the smallest
scope in which it is needed. At the end of that scope, before the next
iteration begins, %data will be destroyed and your next iteration will
create a brand new version of it.
>
> }
>
> $count++;
>
> }
> };
>
>
> print br;
>
> &StitchFilesTogether($exptnum, $keysRef, $exptIDsRef, $IDToNameRef);
>
> return(undef);
>
> }
>
> #########################################################
> sub StoreData{
> #########################################################
>
> my ($dataRef, $count, $exptIDsRef, $IDToNameRef) = @_;
> my ($i, $start, $key, $num);
> my %data = %$dataRef;
> my $number = int(($count-1)/$numToDump) + 1;
> my $filename = $$.".".$number.".tmp";
Gah. Use interpolation to improve readability:
my $filename = "$$.$number.tmp";
I'm *guessing* that @values above was the cause of your error. After
making that change, if you still aren't seeing the results you desire,
please post a *short* but *complete* script that demonstrates the
error, along with your sample input, desired output, and actual output.
Paul Lalli
------------------------------
Date: 12 Jul 2006 10:11:32 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Dereferencing Hash of Arrays
Message-Id: <1152724292.897336.325510@p79g2000cwp.googlegroups.com>
Paul Lalli wrote:
> > my ($key, $spot, $suid, $val, $sth, @values, $keyOffset, %data);
>
> I'm willing to bet this is your central problem.
Yes, a nasty attack of premature declaration indeed.
> A good general rule
> is to always declare variables in the shortest scope possible.
Just to re-enforce what Paul said, this is a _general_ rule. It's not
specific to programming in Perl. It applies to programming in _general_
(whenever the concept of variable scope exists).
Any teacher, collegue, book or ($DEITY forbid) language[1] that
encourages premature declarartion should be viewed with suspicion.
[1] Pascal-like languages
------------------------------
Date: Wed, 12 Jul 2006 12:03:34 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Dereferencing Hash of Arrays
Message-Id: <slrnebaar6.cp3.tadmc@magna.augustmail.com>
Jennifer I. Drake <jennifer.drake@gmail.com> wrote:
> #!/usr/bin/perl
> use strict;
> use warnings;
Good. Very good. Thank you for your courtesy.
> &GetData(\%keys);
You should not use an ampersand on subroutine calls unless you know
why you need an ampersand on your subroutine call. See perlsub.pod.
GetData(\%keys);
> ### Retrieving information from a PostgreSQL database here.
> my %data;
> my $keysRef;
>
> foreach my $secondKey (@{$secondKeysRef}) {
> while (($key, @values) = $sth->fetchrow_array) {
> $$keysRef{$key} = 1;
> $data{$key}{$secondKey} = \@values;
> }
> &StoreData(\%data, $keysRef);
> }
It would be helpful to see what data structure you ended up building.
use Data::Dumper; # at top of program file
then here you can have a look at %data:
print Dumper \%data;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 12 Jul 2006 12:44:38 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Dereferencing Hash of Arrays
Message-Id: <slrnebad85.cp3.tadmc@magna.augustmail.com>
Jennifer I. Drake <jennifer.drake@gmail.com> wrote:
> I do have a the 'my ($keysRef) = @_' in my code. I tried to remove
> some of the code to be more clear. I guess it has the opposite effect.
> The rest of the code is quite long and contains a lot of
> CGI/PostgreSQL calls that don't do anything with this issue, so I
> wasn't sure if I should post all of it. I'll post the complete GetData
> and StoreData subroutines.
You should instead post a short and complete program *that we can run*
that illustrates your problem.
Please have a look at the Posting Guidelines that are posted
here frequently.
Your code is too much, and too incomplete to try and figure out, so I
don't have any help for your real problem. But I will point out
some strangeness that I noticed in a quick scan.
> print "Using ", font({-color=>'red'}, "$exptnum"),
^^^^^^^^^^
perldoc -q vars
What's wrong with always quoting "$vars"?
So make that:
print "Using ", font({-color=>'red'}, $exptnum),
> my ($key, $spot, $suid, $val, $sth, @values, $keyOffset, %data);
^^^^
You should restrict the scope of variables to the smallest possible,
so you should declare them right before you use them rather than
way up here.
You redeclare $sth later on, aren't you getting a warning message
about that?
> print "Retrieving data...\n<br>";
Now that I see you are outputting HTML, I am worried that this is a
CGI application without any taint checking. Please think carefully
about security before going "live" with a CGI program that talks
to a database.
perldoc perlsec
> for (my $i = 0; $i < scalar(@values); $i++) {
Easier to read, and harder to insert a bug, if you replace that
line with:
foreach my $i ( 0 .. $#values ) {
> $values[$i] = -$values[$i];
> }
> }
Oh. You didn't even need that actual index.
Easier to read, and harder to insert a bug, if you let perl handle the
indexing for you and replace that whole loop with:
foreach my $value ( @values ) {
$value = -$value;
}
or
@values = map -$_, @values;
> $$keysRef{$spot} = 1;
Easier to read, and harder to insert a bug, if you use the arrow
operator when you can:
$keysRef->{$spot} = 1;
See perlreftut.pod.
> my $filename = $$.".".$number.".tmp";
Easier to read if you use interpolation instead of explicit concatenation:
my $filename = "$$.$number.tmp";
[ snip TOFU ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 12 Jul 2006 17:06:04 +0200
From: Stephan Titard <sgt19@tid.es>
Subject: Re: finding perl info on google can be hard
Message-Id: <e9334q$35j8@news.hi.inet>
Sherm Pendley escribió:
> John Bokma <john@castleamber.com> writes:
>
>> Does seek set $! or not? (According to Programming
>> Perl is does, but perldoc -f seek didn't say so).
>
> That's a damn good question! I ran a test trying to seek(FILE, 50, 0) in
> an 0-byte read-only file - the seek didn't even *fail*, much less set $! -
> it just happily and silently returned a 1.
>
> So I tried again, this time seek(FILE, -50, 0) - obvious nonsense, trying
> to seek to position -50 from the beginning. That time it returned 0 and set
> $! to "Invalid argument".
>
> So it looks like seek does some basic sanity checking for arguments that
> are nonsensical regardless of the file size, but doesn't do a bounds check
> against the actual file size. That makes sense in the case of a writable
> file which can be grown to fit the new position, but for a read-only file
> it's completely non-intuitive.
>
> sherm--
>
actually on UN*X you can seek past the end of a file, ... you get holes
very often a core file has holes actually
try to generate one and compare the output of ls and du
some of my backup scripts *does* check for this when files are reported
to be bigger that some max value
cp tar and such do read these holes and they count!
the perl side will probably do what the io-library o the low-level io does
I usually use the sys* functions when I need to seek
hth
--stephan
------------------------------
Date: 12 Jul 2006 09:22:35 -0700
From: ilikesluts@gmail.com
Subject: Re: finding perl info on google can be hard
Message-Id: <1152721355.097027.197930@i42g2000cwa.googlegroups.com>
Hi Sherm,
Sorry if I wasn't completely clear. Please let me restate my point for
better understanding. Using google to find some types of info is easy,
find other types of info is hard. It depends on what characters are in
the search. You see, google only handles alpha numeric characters.
Anyways, what do you have against google? It's just a tool and I find
it useful.
Hope that helps!
Sherm Pendley wrote:
> You were just complaining that it's not so useful for finding information
> about Perl. Make up your mind.
------------------------------
Date: Wed, 12 Jul 2006 12:49:05 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: finding perl info on google can be hard
Message-Id: <m2fyh6epku.fsf@Sherm-Pendleys-Computer.local>
ilikesluts@gmail.com writes:
> Anyways, what do you have against google?
Nothing - I use it daily. But I don't use it as a substitute for the docs
that are already on my hard drive.
> Hope that helps!
What makes you think I need help?
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 12 Jul 2006 15:26:50 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Perl +lists/unions/intersection:
Message-Id: <slrneba55q.m92.glennj@smeagol.ncf.ca>
At 2006-07-11 10:13PM, oleg <orodionov@gmail.com> wrote:
> Here is an example:
>
> Combine seven lists below into new lists. New lists must contain less
> then 10 elements
> list_1: { a, b, c, d ,e }
> list_2: { c, d, a, g }
> list_3: { a, g, s, h, y }
> list_4: { t, r, n, l, o }
> list_5: { c, f, g, s, w, y }
> list_6: { n, y, r, s }
> list_7: { k, b, s }
>
> list_1+list_2: { a, b, c, d, e, g }
> list_3 + list_5; { a, g, s, h, y, c, f, w, y }
> list_4 + list_6 + list_7: { t, r, n, l, o, y, s, k, b }
Are you dropping duplicated elements or not? Your "list_3 + list_5"
contains 2 "y". Is there any reason to associate the new lists with
particular old lists?
use strict;
use warnings;
sub printLoL {
my $count = 0;
print(++$count, "\t", join(", ", @$_), "\n") foreach @_;
}
my @orig = (
[qw(a b c d e)],
[qw(c d a g)],
[qw(a g s h y)],
[qw(t r n l o)],
[qw(c f g s w y)],
[qw(n y r s)],
[qw(k b s)],
);
print "original lists:\n";
printLoL(@orig);
# combine elements into one big list
my %hash;
foreach my $list (@orig) {
$hash{$_}++ foreach @$list;
}
my @biglist = sort keys %hash;
# then, split the big list into constrained smaller lists
my @newlists;
my $K = 10;
while (@biglist) {
push @newlists, [splice @biglist, 0, $K];
}
print "new lists:\n";
printLoL(@newlists);
output:
original lists:
1 a, b, c, d, e
2 c, d, a, g
3 a, g, s, h, y
4 t, r, n, l, o
5 c, f, g, s, w, y
6 n, y, r, s
7 k, b, s
new lists:
1 a, b, c, d, e, f, g, h, k, l
2 n, o, r, s, t, w, y
--
Glenn Jackman
Ulterior Designer
------------------------------
Date: 12 Jul 2006 08:52:20 -0700
From: "oleg" <orodionov@gmail.com>
Subject: Re: Perl +lists/unions/intersection:
Message-Id: <1152719540.750928.33000@i42g2000cwa.googlegroups.com>
Glenn,
Thank you for looking into this!
>
> Are you dropping duplicated elements or not? Your "list_3 + list_5"
> contains 2 "y". Is there any reason to associate the new lists with
> particular old lists?
I am only dropping the duplicate elements within the lists that are
selected to be combined. The key here is to find among original lists
those with the largest intersection. YES, there must be association
between the old and new lists. All elements of any given old list must
be accessible in one of the new lists.
Thanks!
Oleg
------------------------------
Date: 12 Jul 2006 16:30:14 GMT
From: xhoster@gmail.com
Subject: Re: Perl +lists/unions/intersection:
Message-Id: <20060712123409.460$S3@newsreader.com>
"oleg" <orodionov@gmail.com> wrote:
> [Sinan wrote:]
> > [Oleg wrote:]
> > >
> > > Combine seven lists below into new lists. New lists must contain
> > > less then 10 elements
> > > list_1: { a, b, c, d ,e }
> > > list_2: { c, d, a, g }
> > > list_3: { a, g, s, h, y }
> > > list_4: { t, r, n, l, o }
> > > list_5: { c, f, g, s, w, y }
> > > list_6: { n, y, r, s }
> > > list_7: { k, b, s }
> > >
> > > list_1+list_2: { a, b, c, d, e, g }
> > > list_3 + list_5; { a, g, s, h, y, c, f, w, y }
> > > list_4 + list_6 + list_7: { t, r, n, l, o, y, s, k, b }
> >
> >
> > perldoc -q intersection
> > perldoc -q duplicate
> >
> In real world, I have "bunches" of signals coming from hardware
> substate machines ( very large state machine split up into many smaller
> ones) . I want to write a script to equalize these signals into the
> least number of 21bit chunks to minimize the muxing.
I don't get it. If you have real hardware, surely you aren't writing the
kernel/microcode in Perl! And if you are merely simulating hardware, I'm
not sure why you would want to write a simulation in such a way that, if
the simulation turns out to be successful, it cannot be translated into
reality.
In any event, I believe this is a type of bin-packing problem for which
there is no efficient way to find the optimal packing without exhaustive
checking every possiblity (or doing something on the same order as that.)
It isn't obvious whether you need the optimal solution, or merely a
sufficiently good one.
> I did it by hand once, but state machine keeps changing and so I would
> rather automate procedure. I already wrote a perl script that extracts
> the signals and build the lists. Now, I just need the right algorithm
> for the lists
If you only need a sufficiently good solution, then check the size of the
union of randomly chosen pairwise combinations of lists (how to do this is
covered in the docs you have been referred to). If it is small enough to
meet your criteria, fuse them. Stop when you can't find any more pairwise
combinations that meet the criteria, or when you get sick of searching, or
when some other criteria of your choosing is met.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 12 Jul 2006 10:20:50 -0700
From: "oleg" <orodionov@gmail.com>
Subject: Re: Perl +lists/unions/intersection:
Message-Id: <1152724850.600675.238860@m79g2000cwm.googlegroups.com>
> I don't get it. If you have real hardware, surely you aren't writing the
> kernel/microcode in Perl! And if you are merely simulating hardware, I'm
> not sure why you would want to write a simulation in such a way that, if
> the simulation turns out to be successful, it cannot be translated into
> reality.
I am designing hardware in RTL. I merely need a tool to speed up a
tidius task of manually building up the signal lists of this huge state
machine .
>
> In any event, I believe this is a type of bin-packing problem for which
> there is no efficient way to find the optimal packing without exhaustive
> checking every possiblity (or doing something on the same order as that.)
> It isn't obvious whether you need the optimal solution, or merely a
> sufficiently good one.
>
> > I did it by hand once, but state machine keeps changing and so I would
> > rather automate procedure. I already wrote a perl script that extracts
> > the signals and build the lists. Now, I just need the right algorithm
> > for the lists
>
> If you only need a sufficiently good solution, then check the size of the
> union of randomly chosen pairwise combinations of lists (how to do this is
> covered in the docs you have been referred to). If it is small enough to
> meet your criteria, fuse them. Stop when you can't find any more pairwise
> combinations that meet the criteria, or when you get sick of searching, or
> when some other criteria of your choosing is met.
Yes, I only need a "good enough" solution.
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 12 Jul 2006 17:24:34 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl +lists/unions/intersection:
Message-Id: <Xns97FE888132D3Easu1cornelledu@127.0.0.1>
"oleg" <orodionov@gmail.com> wrote in
news:1152724850.600675.238860@m79g2000cwm.googlegroups.com:
[ attribution missing. please do not snip attributions. ]
>> If you only need a sufficiently good solution, then check the size of
>> the union of randomly chosen pairwise combinations of lists (how to
>> do this is covered in the docs you have been referred to). If it is
>> small enough to meet your criteria, fuse them. Stop when you can't
>> find any more pairwise combinations that meet the criteria, or when
>> you get sick of searching, or when some other criteria of your
>> choosing is met.
>
> Yes, I only need a "good enough" solution.
Well, Xho has told you how to do it. Now, it is your turn to give it a
shot. You have all the information you need to write this thing.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9455
***************************************