[31005] in Perl-Users-Digest
Perl-Users Digest, Issue: 2250 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 4 16:09:46 2009
Date: Wed, 4 Mar 2009 13:09:11 -0800 (PST)
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, 4 Mar 2009 Volume: 11 Number: 2250
Today's topics:
calculate an average with every data in an array <jogsalot75@yahoo.de>
Re: calculate an average with every data in an array <darkon.tdo@gmail.com>
Re: calculate an average with every data in an array <burner+usenet@imf.au.dk>
Re: calculate an average with every data in an array <edwards@nouce.trurl.bsd.uchicago.edu>
CGI query string encoding issue... <howachen@gmail.com>
Re: CGI query string encoding issue... <syscjm@sumire.gwu.edu>
Re: Handling external data <lvirden@gmail.com>
Re: Handling external data <ben@morrow.me.uk>
Re: Handling external data <noreply@gunnar.cc>
Re: Handling external data <tadmc@seesig.invalid>
Re: system(@args) query, result not as expected. <schaitan@gmail.com>
Re: system(@args) query, result not as expected. <ben@morrow.me.uk>
Re: system(@args) query, result not as expected. <justin.0903@purestblue.com>
Telnet and then SSH <hirenshah.05@gmail.com>
Re: Telnet and then SSH <ben@morrow.me.uk>
Re: Telnet and then SSH <hirenshah.05@gmail.com>
Re: Telnet and then SSH <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 4 Mar 2009 06:11:25 -0800 (PST)
From: Erol Akman <jogsalot75@yahoo.de>
Subject: calculate an average with every data in an array
Message-Id: <f96436bf-bf9c-467a-a032-546269f1704f@x13g2000yqf.googlegroups.com>
Hi,
I have following (crazy) task and was hoping to solve it via perl, but
I need your help, please.
I have an array of values and need to calculate every possible average
and sort it by the average data:
@array = qw(4 6 2 7 1 8 3 5 9 10);
This should be printed out:
4+2 = 6, Average =3
4+6+2 = 12, Average=4
4+6 = 10, Average=5
...
10+4+6+2+3 = 25, Average=5
also nice to have, but not must have: I need to see which scalar perl
used to sum up, maybe "4+6+2 = 12, Average=4, scalar 0,1,3 were summed
up"
I know, its nuts, but I really need this.
Background: I have lots and lots of data like 23.33, 12.25, 84.56 and
so on and hundreds of values like 54, 32, 45. I don't know which and
how many of these values where summed up to get the data above. My
idea was to calculate every possible average to find out which values
where summed up and averaged out.
Is this possible? Can you help me?
Best regards
Erol
------------------------------
Date: Wed, 4 Mar 2009 10:21:29 -0500
From: "darkon" <darkon.tdo@gmail.com>
Subject: Re: calculate an average with every data in an array
Message-Id: <bbudnfffUY7mATPUnZ2dnUVZ_ryWnZ2d@supernews.com>
"Erol Akman" <jogsalot75@yahoo.de> wrote in message
news:f96436bf-bf9c-467a-a032-546269f1704f@x13g2000yqf.googlegroups.com...
> I have an array of values and need to calculate every possible average
> and sort it by the average data:
>
> @array = qw(4 6 2 7 1 8 3 5 9 10);
>
>
> This should be printed out:
> 4+2 = 6, Average =3
> 4+6+2 = 12, Average=4
> 4+6 = 10, Average=5
> ...
> 10+4+6+2+3 = 25, Average=5
>
> also nice to have, but not must have: I need to see which scalar perl
> used to sum up, maybe "4+6+2 = 12, Average=4, scalar 0,1,3 were summed
> up"
Take a look at Math::Combinatorics. That should put you on your way.
http://search.cpan.org/~allenday/Math-Combinatorics-0.09/lib/Math/Combinatorics.pm
------------------------------
Date: Wed, 04 Mar 2009 17:21:03 +0100
From: Rasmus Villemoes <burner+usenet@imf.au.dk>
Subject: Re: calculate an average with every data in an array
Message-Id: <u0locwhuumo.fsf@orc10.imf.au.dk>
Erol Akman <jogsalot75@yahoo.de> writes:
> Background: I have lots and lots of data like 23.33, 12.25, 84.56 and
> so on and hundreds of values like 54, 32, 45. I don't know which and
> how many of these values where summed up to get the data above. My
> idea was to calculate every possible average to find out which values
> where summed up and averaged out.
>
> Is this possible? Can you help me?
If I understand the problem, you have, say, 100 integers a_1, a_2,
..., a_100 (your 54, 32, 45,... for instance). Some mean person has
taken some of these integers, computed the average and told you this
average (eg. 23.33). Your job is to find the integers which were used
to arrive at this average. Then you are given another average (like
12.25) and must do the same, etc. Is this correct? (If not, ignore the
rest.)
You do realize that the number of subsets of your "hundreds of values"
is larger than the expected lifetime of the solar system in
femtoseconds? So even calculating the average of one subset every
1E-15 seconds wouldn't complete the task in time for it to be
useful. So in theory your approach is possible (the problem is finite,
and an exhaustive search on all subsets would certainly do the job),
but in reality it is only applicable for very small sets of integers.
Maybe a quantum computer could do it, but I don't know if perl is
ported to that platfrom yet :-)
--
Rasmus Villemoes
<http://rasmusvillemoes.dk/>
------------------------------
Date: Wed, 04 Mar 2009 18:44:09 GMT
From: Edwards <edwards@nouce.trurl.bsd.uchicago.edu>
Subject: Re: calculate an average with every data in an array
Message-Id: <slrngqtitg.pe0.edwards@trurl.bsd.uchicago.edu>
On 2009-03-04, Erol Akman <jogsalot75@yahoo.de> wrote:
> I have an array of values and need to calculate every possible average
> and sort it by the average data:
>
> @array = qw(4 6 2 7 1 8 3 5 9 10);
>
>
> This should be printed out:
> 4+2 = 6, Average =3
> 4+6+2 = 12, Average=4
> 4+6 = 10, Average=5
> ...
> 10+4+6+2+3 = 25, Average=5
>
> also nice to have, but not must have: I need to see which scalar perl
> used to sum up, maybe "4+6+2 = 12, Average=4, scalar 0,1,3 were summed
> up"
>
> I know, its nuts, but I really need this.
>
> Background: I have lots and lots of data like 23.33, 12.25, 84.56 and
> so on and hundreds of values like 54, 32, 45. I don't know which and
> how many of these values where summed up to get the data above. My
> idea was to calculate every possible average to find out which values
> where summed up and averaged out.
>
> Is this possible? Can you help me?
Coding-wise this seems fairly straightforward, but I see a couple of
potential problems given the background you provide above. The first,
which you've probably already realized, is that since there are
different ways of summing to a given number, the resulting averages
aren't going to be unique. In your example problem, for instance, I
get several dozen ways (75, actually) of obtaining an average of "6";
and while "unique" solutions aren't exactly rare (10 is only the
average of 10; 9.5 of "9 10", 8.6667 of "7 9 10" etc), they are
definitely in the minority.
The other is that since you have to look at combinations of elements
where the number of elements in the combination is also arbitrary, the
search space is over what I believe is called the "power set" of your
set of values. In your example, there are 10 values, so the number of
possible lists made from sets of these values is 2**10... well,
(2**10)-1, since of course we don't count the empty set. That ran
pretty quickly on my machine, but you mention "hundreds of values"
above and 2**100 is what, 10**30 or so? Which, by itself, would
merely be "nuts" as you say; but in light of the first problem, I am
betting that most of the time a given average is going to have an
incredibly huge number of "lists" associated with it, and the averages
with only a single associated list (ie, a unique list of numbers out
of your set of possible values that has the given average) are going
to be quite rare.
Sorry to sound so negative, but I guess I am trying to say that you
might want to try to figure out how long this would take (eg benchmark
starting with a small subset of your data, ten or so as in your
example problem, then gradually increase the subset size) relative to
how badly you really need it...
--
Darrin
------------------------------
Date: Wed, 4 Mar 2009 06:52:45 -0800 (PST)
From: howa <howachen@gmail.com>
Subject: CGI query string encoding issue...
Message-Id: <373bd825-c42c-4269-915d-c7be6916ffdb@k36g2000pri.googlegroups.com>
Hello, consider my simple cgi program below:
#=======
#!/usr/bin/perl
use strict;
use CGI;
my $q = new CGI;
my $s = $q->param("s");
print $q->header( -type => "text/html" );
print utf8::valid ($s);
#=======
Then I call, e.g.
http://www.example.com/cgi-bin/test.cgi?s=abc (print 1, ok)
http://www.example.com/cgi-bin/test.cgi?s=中文 (also print 1, but my
paramater s is BIG5 traditional Chinese encoding, not utf8!)
So now I am really confused with the encoding stuff... Can anyone
modify my program above ... so not to print 1 if my $s contains non-
UTF8 characters?
Thanks.
------------------------------
Date: Wed, 04 Mar 2009 09:41:25 -0600
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: CGI query string encoding issue...
Message-Id: <slrngqt895.i0h.syscjm@sumire.gwu.edu>
On 2009-03-04, howa <howachen@gmail.com> wrote:
> Hello, consider my simple cgi program below:
>
> #=======
> #!/usr/bin/perl
> use strict;
>
> use CGI;
> my $q = new CGI;
> my $s = $q->param("s");
> print $q->header( -type => "text/html" );
>
> print utf8::valid ($s);
> #=======
>
> Then I call, e.g.
>
> http://www.example.com/cgi-bin/test.cgi?s=abc (print 1, ok)
> http://www.example.com/cgi-bin/test.cgi?s=中文 (also print 1, but my
> paramater s is BIG5 traditional Chinese encoding, not utf8!)
>
> So now I am really confused with the encoding stuff... Can anyone
> modify my program above ... so not to print 1 if my $s contains non-
> UTF8 characters?
>
Not really, because there's no way to look at an arbitrary bit string and
know that it's BIG5, or utf8, or whatever. You said parameter s is a BIG5
string in the second case--but it's also a utf8 string: "^[$BCfJ8^[(B".
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
------------------------------
Date: Wed, 4 Mar 2009 07:36:57 -0800 (PST)
From: "Larry W. Virden" <lvirden@gmail.com>
Subject: Re: Handling external data
Message-Id: <e9ac2334-8c6e-4e81-b19e-171c2a06c77a@l37g2000vba.googlegroups.com>
On Mar 4, 8:31=A0am, Tad J McClellan <ta...@seesig.invalid> wrote:
>
> =A0 =A0 system 'mycommand', 'arg1=3Dabc', 'arg2=3D123 456', "details=3D$m=
essage";
Thank you very much. I'd tried some of the other options in this
thread, but found trying to use substituion to add backslashes to be a
bit tricky.
However, so far, this version of system invocation appears to handle
the data I was getting that was generating errors.
I really appreciate your help.
------------------------------
Date: Wed, 4 Mar 2009 15:40:57 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Handling external data
Message-Id: <91k286-gd1.ln1@osiris.mauzo.dyndns.org>
Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
>
> Try:
>
> my @args = ("mycommand", "arg1='abc'", "arg2='123 456'", $message);
> system(@args);
You don't want the single quotes.
(Is it something in the weather today? :) )
Ben
------------------------------
Date: Wed, 04 Mar 2009 17:11:34 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Handling external data
Message-Id: <717ne8Fjpt56U1@mid.individual.net>
Ben Morrow wrote:
> Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
>> Try:
>>
>> my @args = ("mycommand", "arg1='abc'", "arg2='123 456'", $message);
>> system(@args);
>
> You don't want the single quotes.
True. Thanks for the correction.
> (Is it something in the weather today? :) )
Must be. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 4 Mar 2009 10:24:52 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Handling external data
Message-Id: <slrngqtaqk.72v.tadmc@tadmc30.sbcglobal.net>
Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
>>
>> Try:
>>
>> my @args = ("mycommand", "arg1='abc'", "arg2='123 456'", $message);
>> system(@args);
>
> You don't want the single quotes.
>
> (Is it something in the weather today? :) )
I think so, as I made the same mistakes in both threads too...
... but managed to correct them before hitting "send".
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 4 Mar 2009 07:30:06 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <8ad150dd-4f0d-4350-9429-f194988a665f@d36g2000prf.googlegroups.com>
>
> This is only half-way and won't work:
>
> "mount: unknown filesystem type ' smbfs'" (note the blank before "smbfs").
That's because of what I had said above, I guess.....any space present
in the list items will be preserved verbatim at the program invocation
time.
------------------------------
Date: Wed, 4 Mar 2009 15:37:48 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <crj286-gd1.ln1@osiris.mauzo.dyndns.org>
Quoth Josef Moellers <josef.moellers@fujitsu-siemens.com>:
>
> Try putting each argument into a separate string:
>
> my @args = ("mount", "-t", "smbfs", "-o",
> "username=boris,password=drowssap",
> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
You don't want those \"s in there. They are shell quoting, which is
appropriate for system STRING but not for system LIST.
I would also take advantage of => here:
my @args = (
"mount",
-t => "smbfs",
-o => "...",
"...", "...",
);
Ben
------------------------------
Date: Wed, 04 Mar 2009 16:04:28 -0000
From: Justin C <justin.0903@purestblue.com>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <7167.49aea68c.30988@zem>
On 2009-03-04, Justin C <justin.0903@purestblue.com> wrote:
>
> I have the following:
>
> my @args = ("mount", "-t smbfs -o username=boris,password=drowssap",
> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
[snip]
Thank you all, very clear and concise. I have a better understanding of
the command now and shall implement it correctly.... and have, and all
is good.
Thank all, again, for your regular help.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Wed, 4 Mar 2009 11:21:11 -0800 (PST)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: Telnet and then SSH
Message-Id: <e9f42a82-b72c-4bf8-95c7-cbedcdd9990e@r3g2000vbp.googlegroups.com>
There are 3 servers.
I am on server 1. I need to get some files from server 3. But I dont
have direct access to server 3. I have to go through Server 2.
- From Server 1 I have to Telnet to Server 2
- From Server 2 I can ftp or ssh to Server 3.
I also don't to whole directory from Server 3. I want to read the file
name and then tranfer only selected files from Server 3 to Server 1.
I want to automate this whole process.
Any suggestion how can I do this.??
One method I was trying was:
Use perl telnet module. And the in telnet command I give SSH command
(using Perl SSH module).
I did ls in ssh command (vis telnet command). But now how will get ls
output to viarable.
Once I have file name which I need then I can scp to server 2. And
from there I can ftp to my local server 1.
------------------------------
Date: Wed, 4 Mar 2009 19:47:08 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Telnet and then SSH
Message-Id: <se2386-mt4.ln1@osiris.mauzo.dyndns.org>
Quoth "friend.05@gmail.com" <hirenshah.05@gmail.com>:
> There are 3 servers.
>
> I am on server 1. I need to get some files from server 3. But I dont
> have direct access to server 3. I have to go through Server 2.
>
> - From Server 1 I have to Telnet to Server 2
It is not easy to transfer files via telnet. Are you sure there's no
other way of communicating between these machines?
> - From Server 2 I can ftp or ssh to Server 3.
>
> I also don't to whole directory from Server 3. I want to read the file
> name and then tranfer only selected files from Server 3 to Server 1.
>
> I want to automate this whole process.
>
> Any suggestion how can I do this.??
Post the code you have, and explain what's going wrong with it.
Ben
------------------------------
Date: Wed, 4 Mar 2009 11:59:22 -0800 (PST)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: Re: Telnet and then SSH
Message-Id: <d58ceaa0-3acd-46a1-91f6-2a25144b76d3@l37g2000vba.googlegroups.com>
On Mar 4, 2:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth "friend...@gmail.com" <hirenshah...@gmail.com>:
>
> > There are 3 servers.
>
> > I am on server 1. I need to get some files from server 3. But I dont
> > have direct access to server 3. I have to go through Server 2.
>
> > - From Server 1 I have to Telnet to Server 2
>
> It is not easy to transfer files via telnet. Are you sure there's no
> other way of communicating between these machines?
>
> > - From Server 2 I can ftp or ssh to Server 3.
>
> > I also don't to whole directory from Server 3. I want to read the file
> > name and then tranfer only selected files from Server 3 to Server 1.
>
> > I want to automate this whole process.
>
> > Any suggestion how can I do this.??
>
> Post the code you have, and explain what's going wrong with it.
>
> Ben
From Server 1 I have to Telnet to Server 2 . I can also ftp. So that
won't be problem.
Sample Code: Not sure just trying this one
use Net::Telnet;
use Net::SSH::Perl;
#telnet to Server 2
$telnet =3D new Net::Telnet ( Timeout=3D>10,Errmode=3D>'die');
$telnet->open($server2);
$telnet->waitfor('/login: $/i');
$telnet->print('hs767s');
$telnet->waitfor('/password: $/i');
$telnet->print('india512');
$telnet->waitfor('/\$ $/i');
#From Telnet, SSH to Server 3.
$scmd =3D "$ssh =3D Net::SSH::Perl->new($server3)";
$telnet->print($scmd);
$scmd =3D "$ssh->login('user', 'pass')";
$telnet->print($scmd);
$scmd =3D "$ssh->cmd(\"cd /xyz\")";
$telnet->print($scmd);
$scmd =3D "$ssh->cmd(\"ls\")";
$telnet->print($scmd);
#here what I am trying to do is "ls on Server 3". So I know what
directories are there. Then I want to scp one by one to Server 2.
But how Can I read output of "ls" as I am using SSH-CMD in TELnet cmd.
Once I have it Server 2 then I can ftp to server 1.
------------------------------
Date: Wed, 4 Mar 2009 20:15:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Telnet and then SSH
Message-Id: <444386-525.ln1@osiris.mauzo.dyndns.org>
Quoth "friend.05@gmail.com" <hirenshah.05@gmail.com>:
>
> From Server 1 I have to Telnet to Server 2 . I can also ftp. So that
> won't be problem.
>
>
> Sample Code: Not sure just trying this one
>
> use Net::Telnet;
> use Net::SSH::Perl;
>
> #telnet to Server 2
>
> $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
> $telnet->open($server2);
> $telnet->waitfor('/login: $/i');
> $telnet->print('hs767s');
> $telnet->waitfor('/password: $/i');
> $telnet->print('india512');
I hope that's not your real password.
> $telnet->waitfor('/\$ $/i');
>
> #From Telnet, SSH to Server 3.
>
> $scmd = "$ssh = Net::SSH::Perl->new($server3)";
Umm... you seem to be confused here. This string will be sent to
$server2 as a *shell* command, not a Perl statement. If you want you
could run perl on $server2 and pass it statements to execute, but to be
honest it's probably easier just to use ssh(1) on the remote machine.
Ben
------------------------------
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 V11 Issue 2250
***************************************