Donations gladly accepted
Users, please read the following important update:
|
If you're new here please read PerlMonks FAQ and Create a new user.
Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2009 (Don't worry; you've got plenty of time.)
|
New Questions
|
Finding local maxima/minima in noisy, pediodic data
on Oct 12, 2009 at 08:24
|
2 direct replies
|
by kikuchiyo
|
|
|
Dear Monks,
I have to write a small application that visualizes 2D datasets, finds local maxima and minima in them and lets the user manage those maxima and minima interactively. The interactive GUI part comes later, this question concerns the maxima/minima finding algorithm itself.
Certain assumptions can be made about the data: it is somewhat periodic, but not in the strict sense of the word: the amplitude and the frequency of the pulses do vary. Also, the data is quite noisy. Think of an ECG curve or brain wave pattern to get the picture.
What I need is the following: I have to find only one local maximum and one local minimum in every pulse, that is, the highest and lowest points of every pulse. Because of the noisiness of the data, this is not that trivial: simply scanning through the data and marking every local peak/valley does not suffice, I have to filter them somehow.
I thought that I might exploit the periodic property of the data: First I'd find all peaks, then sort them according to their heights, then weed out those that are too close to a legitimate peak.
Here is what I have so far:
This seems to work.
However, I feel that it is quite inefficient - is there a way (are there ways) to make it better?
You can generate test data that sort of looks like the real thing with the following command:
perl -le'print $_,"\t",sin($_/10)+sin(($_/30))**2*0.2+sin($_/500)*0.4+
+4+(rand()+rand()+rand()+rand())/20 for 0..6000' > testdata.txt
|
[Offer your reply]
|
What is the best Perl library to use to connect and access MSSQL2008 Database from winXP PC?
on Oct 12, 2009 at 07:50
|
4 direct replies
|
by blackadder
|
|
|
Dear Monks, greetings
I need to connect to a MSSQL2008 database from my winXP laptop. I have googled and searched on PM for an answer, but I got a bit confused!
I wasn't sure wether to go for:
DBI, or DBD::ODBC (am I correct in assuming those two packages will only work from Linux/Unix box?)
Win32::ODBC (some say its no longer supported by Mssql2008)
Win32::ADO or Win32::OLE (which is better!? but I thought one issues ADO command using Win32::OLE)
Or Win32::Sql (Does it work with MSSQL2008? And I could NOT install win32::sql package as it was not found in any of my repositories in PPM - which contains all PPM respositories that i know of!)
Can someone please enlighten me??THアンコ.......ウソやウソ,ANKやわ,はっはっ,S!
|
[Offer your reply]
|
Storable style de-serializing for JSON structures
on Oct 11, 2009 at 03:13
|
2 direct replies
|
by Anonymous Monk
|
|
|
Hi Monks,
Wisdom I seek ..
I am receiving JSON serialized objects for some perl classes. I can easily de-serialize the JSON structure back into perl data structure - hash/array using standard JSON modules and possibly into a blessed reference.
However, when the serialized class represents objects and sub-objects, I have no way to automatically create blessed reference for sub-objects.
Storable module can easily de-serialize and create blessed references for sub-objects automatically. Is there a way to do the same for JSON?
Gracias
Dece
|
[Offer your reply]
|
Help, pls, w/ CiviCRM::Client::REST->login() failures . . .
on Oct 09, 2009 at 14:02
|
2 direct replies
|
by hesco
|
|
|
Seeking advice on use of CiviCRM::Client::REST, pls.
I went into the module itself and added debug statements to
dump the url's posted to, to STDERR.
I'm told by those on the #civicrm irc channel that the API uses the field names provided by the database tables as keys in its methods. I've checked the drpl_users table and in fact the keys in my login method's arguments do in fact match those field names from the table.
When I harvest the url from output, and run that in a browser, it gets me to an access denied page, with a login form. Using these credentials on that login form gets me to the civiCRM menu page, suggesting to me that the url is at least reasonably well formed.
There are several other tests coded and failing at this point, but they are all expected to (and in fact do) fail unless the ->login() method succeeds. Any and all ideas for how to move past this issue would be appreciated.
Thanks,
-- Hugh
#!/usr/bin/perl
use strict;
use warnings;
use CiviCRM::Client;
use Data::Dumper;
my $civicrm = CiviCRM::Client::REST->new(
'http://example.org', '37736c686aeGrt54skk705bfa9a9Hgsfll81');
print STDERR Dumper($civicrm);
if($civicrm->login({ 'name' => 'hesco', 'pass' => 'secret' })){
print STDERR "succeeded in login attempt \n";
} else {
print STDERR "failed to login \n";
}
gives me this output:
$VAR1 = bless( {
'_civicrmUrl' => 'http://example.org',
'_ua' => bless( {
'max_redirect' => 7,
'protocols_forbidden' => undef,
'show_progress' => undef,
'handlers' => {
'response_header' =
+> bless( [
+ {
+ 'owner' => 'LWP::UserAgent::parse_head',
+ 'callback' => sub { "DUMMY" },
+ 'm_media_type' => 'html',
+ 'line' => '/usr/local/share/perl/5.10.0/LWP/UserAgent.pm
+:608'
+ }
+ ], 'HTTP::Config' )
},
'no_proxy' => [],
'protocols_allowed' => undef,
'use_eval' => 1,
'requests_redirectable' => [
'GET',
'HEAD'
],
'timeout' => 180,
'def_headers' => bless( {
'user-age
+nt' => 'libwww-perl/5.830'
}, 'HTTP::H
+eaders' ),
'proxy' => {},
'max_size' => undef
}, 'LWP::UserAgent' ),
'_sessionKeyName' => 'key',
'_siteKey' => '37736c686aeGrt54skk705bfa9a9Hgsfll81'
}, 'CiviCRM::Client::REST' );
failed to login
if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }
|
[Offer your reply]
|
Checking if a non-blocking socket is active
on Oct 09, 2009 at 13:17
|
2 direct replies
|
by bucz
|
|
|
Hi
I am making some small server using sockets in non-blocking mode. I want to check if the client (telnet) is still connected, but I don't know how.
Reading routine looks like that (from web):
$rv = sysread($sock2, $buffer, $BUFSIZ);
if (!defined($rv) && $! == EAGAIN) { } # HERE
else { print $sock1 $buffer; }
I suppose that HERE I should check for some disconnect error, but I am not sure...
Oh Monks, help me with your wisdom!
|
[Offer your reply]
|
foreach loop - could it beeeeee!!
on Oct 09, 2009 at 06:24
|
4 direct replies
|
by baxy77bax
|
|
|
well,
i was messing around with implementing some security into my program and i noticed some strange thing in one of my foreach loops
foreach (@array){
do something
$self->_call($_);
do something else
}
if the number of arguments were higher than 50 in @array the foreach skipped all the variables over it. if the $_ argument was very complex then the limit was 20 arguments. so my question now is: is it possible that foreach will loop not waiting for the object (_call()) to finish and just go on. because if it is, then i have a serious problem. my program through time build up to huge number of lines and huge number of number of foreach loops. if this is the case then please help me with some quick fix. thnx PS it is interesting that i always stumble over some basic stuff, did anyone noticed the same problem (stumbling over basics while at the same time writing solutions to a really hardcore stuff)?
UPDATE:
ok what happens is this:
sub _do {
my ($self,%arg) = @_;
unless(%arg){
# some stuff (~200 lines)
foreach my $choice (@array_choices){ #
+ log update
my @choice_array = split(",",$print_hash{$choice});
my $pick;
($choice_array[0] eq 'correct') ? ($pick = "$choice_array[1]-$
+choice_array[2]") : ($pick = $choice_array[1]); # pick for correctio
+n
$self->_do($choice_array[0] => $pick);
+ # repete undo precedure with defined values
($choice_array[0] eq 'correct') ? (delete $class_log{do}[$hash
+_order{$choice_array[0]}]) : (delete $class_log{do}[$hash_order{$prin
+t_hash{$choice}}]); # delete do choice
push(@return_log,"_do($choice_array[0] => $choice_array[1]);")
+ unless (ref $pick eq 'ARRAY'); # data for physh
push(@return_log,"_do($choice_array[0] => \[$choice_array[1],$
+choice_array[2]\]);") if (ref $pick eq 'ARRAY');# data for physh
}
}
else{
# brute _do
}
}
so what happens is ido something and then use the loop to automatically delete the data from the array instead of writing another loop to do that so the answer to grizzley's second question is yes my mistake both answers are no (at least it seams for now, let me check again)also the sub uses some ~100 other objects in the first part is the sub (it is a final wrapper) so showing you the whole script won't do any good UPDATE2: the loop and objects called within the loop are "redo,last" free, no such calls are made
|
[Offer your reply]
|
Problem with script? Might be in hash? Help!
on Oct 09, 2009 at 04:28
|
2 direct replies
|
by kdmurphy001
|
|
|
Hello Monks,
I need your help yet again. The below code is mostly re-used. The sub-routine (not listed) is used by a dozen scripts and works great. The query itself works fine if I try it out on a single database.
However when I run this the results are not even close to accurate. Can anyone see any glaring errors? I thought maybe the space that was in the hash keys was the issue so I fixed that but still dosen't work. Been tinkering with this for well over 2 hours..and it's starting to erk me. This should be simple..but it's not.
What it's doing is getting a number of times a user takes something ..the key is a date/hour concat so in essence I want the number of times a user took something for each date/hour (for those date/hours that have takes). There should be a max of 24 lines per host (so 24*3 which is 3 days, 24 hours in each day). Im getting 8 lines with 200ish results..should be A LOT more..both in terms of lines and the #'s returned (I'd expect them to be between 100's and 10,000's).
#!/usr/bin/perl
use strict;
use warnings;
use DBD::mysql;
######################
#### CONFIG VARS #####
######################
my $output_file = 'Takes_by_hour.txt';
######################
#### PRIVATE VARS ####
######################
my $start_date = '2009-10-04';
my $end_date = '2009-10-06';
######################
#### MAIN BODY #######
######################
open OUTPUT, ">$output_file";
select(OUTPUT); $| = 1;
select(STDOUT); $| = 1;
while (my ($host, $default_db) = each(%hosts)) {
my %take_counts = ();
#get database urls for host
my @databases = get_databases($host, $default_db, $db_user, $db_pa
+ss);
@databases = sort(@databases);
#process data on each database
foreach my $database (@databases) {
print join ("/", $host, $database) . "\n";
#Get List of Instructor with active/current courses
my $dbh = DBI->connect("DBI:mysql:database=$database:host=$hos
+t",$db_user,$db_pass,{RaiseError=>1})|| die "$DBI::errstr\n";
my $sql = "SELECT DATE_FORMAT(ar.StartedAt,'%b%d-%k') AS DateT
+aken, COUNT(ar.UserID)
FROM Assignments AS a JOIN AssignmentResults AS ar ON a
+.ID=ar.AssignmentID
WHERE DATE(ar.StartedAt) BETWEEN '$start_date' AND '$en
+d_date' GROUP BY DateTaken";
my $sth = $dbh->prepare ( $sql );
$sth->execute();
while (my @row = $sth->fetchrow_array()) {
if (exists $take_counts{$row[0]}) {
$take_counts{$row[0]} += $row[1];
}
else {
$take_counts{$row[0]} = $row[1];
}
}
$sth->finish();
$dbh->disconnect();
}
foreach (my ($key, $value) = each (%take_counts)) {
print OUTPUT "$host\t$key\t$value\n";
}
}
close OUTPUT;
Thanks again for any help that you can provide.
Kevin M
|
[Offer your reply]
|
LWP redirect problem, produces malformed URL?
on Oct 09, 2009 at 03:25
|
3 direct replies
|
by FloydATC
|
|
|
I'm trying to write a tiny script to login and extract some information from our intranet server running eZ publish, by the use of LWP.
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
my $path = "Infrastruktur/Svitsjoversikt";
my $loginurl = "http://intranett.oikt.local/user/login";
my $finaluri = "/Infrastruktur/Svitsjoversikt";
my $user = "foo";
my $pass = "bar";
my $param = "Login=$user&Password=$pass&LoginButton=1&RedirectURI=$fin
+aluri";
# Create a user agent
my $ua = LWP::UserAgent->new;
$ua->agent("monitorezex/1.0 ");
#push @{ $ua->requests_redirectable }, 'POST'; # Make POST requests
+redirectable
$ua->cookie_jar({ file => "cookies.txt" });
# Create a request
my $req = HTTP::Request->new(
POST => $loginurl
);
$req->content_type('application/x-www-form-urlencoded');
$req->content( $param );
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print "SUCCESS!\n";
print $res->as_string;
} else {
print "FAILURE: " . $res->status_line . "\n";
print $res->as_string;
}
exit;
The web server requires a username and password, upon successful authentication it responds with a 302 redirect to the requested URI, like so:
HTTP/1.1 302 Found
Cache-Control: no-cache, must-revalidate
Connection: close
Date: Fri, 09 Oct 2009 06:45:56 GMT
Pragma: no-cache
Location: http://intranett.oikt.local/Infrastruktur/Svitsjoversikt
Location: http://intranett.oikt.local/Infrastruktur/Svitsjoversikt
Server: Apache/1.3.39 (Win32) PHP/5.2.6
Content-Language: no-bokmaal
Content-Type: text/html; charset=utf-8
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Fri, 09 Oct 2009 06:45:56 GMT
Client-Date: Fri, 09 Oct 2009 06:45:56 GMT
Client-Peer: 10.10.8.120:80
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Refresh: 0;URL=http://intranett.oikt.local/Infrastruktur/Svitsjoversik
+t
Served-By: intranett.oikt.local
Set-Cookie: eZSESSIDoikt_intranett=v8igadrdc86koc225jk55or5e2; path=/
X-Powered-By: eZ Publish
<HTML><HEAD><META HTTP-EQUIV="Refresh" Content="0;URL=http://intranett
+.oikt.local/Infrastruktur/Svitsjoversikt"><META HTTP-EQUIV="Location"
+ Content="http://intranett.oikt.local/Infrastruktur/Svitsjoversikt"><
+/HEAD><BODY></BODY></HTML>
Notice that the login is successful, I get a cookie and a redirect URL.
For some reason, if I uncomment the line to enable automatic redirection, the web server gets a malformed URL from my script:
10.15.0.2 - - [09/Oct/2009:08:38:31 +0200] "POST /user/login HTTP/1.1"
+ 302 246
10.15.0.2 - - [09/Oct/2009:08:38:32 +0200] "GET /Infrastruktur/Svitsjo
+versikt,%20http://intranett.oikt.local/Infrastruktur/Svitsjoversikt H
+TTP/1.1" 404 23015
I understand that this problem can be solved by fetching the new URL manually, but can someone point out why the automatic redirect doesn't work as I expect?
--
Time flies when you don't know what you're doing
|
[Offer your reply]
|
Mysterious Whitespaces between each character in a file
on Oct 08, 2009 at 09:35
|
4 direct replies
|
by 1wax
|
|
|
Reading lines from an MOF file and printing to STDOUT script produces lines with whitespaces between each character.
Trying to use s/\s+//g does not remove the spaces.
Because of the spaces its difficult to match any of the lines with values within the script.
Does anybody know how the file can be read and printed without the extra spaces.
Running a type on the file does not show anything untoward.
Perl version is 5.6.1 on windows 2k3.
EXTRACT OF FILE:
...
#pragma namespace("\\\\.\\Root\\HewlettPackard\\openview\\data")
instance of OV_NodeGroup
{
Caption = "xxxxx";
Description = "xxxxx";
GraphCategory = "";
. . .
};
|
[Offer your reply]
|
Two versions of Perl causing coredump
on Oct 08, 2009 at 04:48
|
1 direct reply
|
by chilukuri_perl
|
|
|
There are two versions of perl installed on system. /usr/local/bin/perl and /usr/bin/perl When /usr/bin/perl is used for XML::LibXML script is working fine. But when /usr/local/bin/perl is used it is causing BusError(coredump). Note that XML::LibXML is installed in application directory. How to resolve this? Thanks
|
[Offer your reply]
|
Trouble using XML::LibXML
on Oct 08, 2009 at 01:52
|
4 direct replies
|
by kdmurphy001
|
|
|
When I try to implement the following code:
while (my @row = $sth->fetchrow_array()){
my $parser = XML::LibXML->new();
my $doc = $parser->parse($row[0]);
my $root = $doc->documentElement();
my %linked_counts_by_abbr;
for my $usage_node ($root->findnodes('/Boo
+kReferences/BookUsage')) {
my $abbr = $usage_node->getAtt
+ribute('BookAbbr');
my $linked_count = $usage_node->getAtt
+ribute('LinkedCount');
$linked_counts_by_abbr{$abbr} += $link
+ed_count;
}
foreach (my ($key, $value) = each %linked_
+counts_by_abbr){
print OUTPUT "$key => $value\n";
}
}
(which I got mostly from this site!) I get the following error.
Can't locate auto/XML/LibXML/parse.al in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 .) at registrations_by_discipline_with_contacts.pl line 139
Any suggestions? libxml-parser-perl package v2.34 is installed along with the necessary dependencies and I'm on Debian GNU/Linux 4.0 but don't have SUDO privilages and I log in to the sytem remotely via a VPN connection.
|
[Offer your reply]
|
DBI Modifying a bind value
on Oct 07, 2009 at 21:50
|
1 direct reply
|
by journey
|
|
|
Dear monks,
I am moving data from an xml-file into a mysql db and need to make a substitution on the fly to clean up a string so it matches the required "datetime" format (replace a letter with a space and truncate).
I naively added the substitution expression to the bind value in the script below and got the following error message: Can't modify non-lvalue subroutine call at blabla.pl line X Here is the code I am using:
use strict;
use DBI;
use XML::XPath
use XML::XPath::XMLParser;
my $dbh = DBI->connect ("DBI:mysql:database",
"root", "password",
{ RaiseError => 1, PrintError => 0});
my $xp = XML::XPath->new (filename => "input_file.xml");
my $nodelist = $xp->find ('//row');
foreach my $row ($nodelist->get_nodelist ())
{
$dbh->do ("INSERT INTO users1 ( create_string, username) VALUES (
+?, ?)",
undef, # no need for \%attr
$row->find ("CreateDate")->string_value () =~ s/(\d\d\
+d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d).*00/$1 $2/g,
$row->find ("UserName")->string_value ());
}
$dbh->disconnect ()
Any guidance on where I should go from here would be appreciated. Regards ---J
Sample data
<USERS1>
<row>
<CreateDate>2008-03-17T13:31:14.345-07:00</CreateDate>
<UserName>foo</UserName>
<Email>michael@example.com</Email>
<UserId>a58d0b09-4f97-42ef-901e-cee41103bc12</UserId>
</row>
<row>
<CreateDate>2008-04-11T14:59:57.123-07:00</CreateDate>
<UserName>bar</UserName>
<Email>spot@example.com</Email>
<UserId>4b618e05-1eca-494b-baa5-ab85bd46f0f3</UserId>
</row>
</USERS1>
To create table in datatbase
create_table_users1.sql
CREATE TABLE users1
(
create_string datetime ,
username varchar(32) );
|
[Offer your reply]
|
|
|
New Meditations
|
Perl is not Dynamically Parseable
on Oct 12, 2009 at 00:11
|
2 direct replies
|
by Jeffrey Kegler
|
|
|
Some monks have already noted that the proof that Perl parsing is not,
in general, decidable applies equally to all parsing by the Perl interpreter
or by Perl scripts.
This point had already been made in my series on "Perl and Undecidability"
in The Perl Review.
[ This is now available online ].
Despite this, some confusion remains on whether, in general, Perl might be
"dynamically" parseable.
The Perl Parsing Undecidability proof shows that
a Turing machine cannot, in general, parse Perl.
Whether running a script, or parsing, the Perl interpreter, and any
program implementing the Perl language is, as far as Perl parsing goes,
a Turing machine.
This means that how you define "static" and "dynamic" Perl parsing
does not matter. All Perl processing is at best equivalent to a Turing machine.
And therefore none of it suffices to parse Perl in general.
The confusion
does have a reasonable basis in some common sense observations.
In practice, Perl almost always does parse itself just fine,
despite any difficulties people may have writing tools to analyze Perl
scripts.
And there is a very convincing (though fallacious) counter-argument.
Fallacious Counter-Argument: First, let's reduce the problem of
Perl parsing to the issue of determining whether a function's prototype is
nullary or not. If it's proved that determining nullarity
is, in general, decidable, it
reduces my original proof to rubble.
It probably also generalizes to a full counter-proof.
Consider the following code snippet:
sub runtime_nullary {
my $function = shift;
return 0
if not defined( my $prototype = prototype $function );
return $prototype eq q{};
} ## end sub runtime_nullary
print 'nullary dunno: ';
say runtime_nullary('dunno') ? 'yes' : 'no';
print 'result is ';
say dunno +4;
Now let's make 4 observations.
- Something like the above can placed to execute first (or early) in the run phase.
- We can place this code so that we always reach it and execute it.
- Once runtime_nullary runs, we know whether the function named in its argument is nullary or not.
- We can run runtime_nullary on any function we like, and on as many functions as necessary.
So therefore, Fallacious Conclusion: We can in general determine whether any Perl function has a nullary prototype or not.
First, let me concede that the Fallacious Conclusion does follow from Observations 1-4.
Let me also concede that Observations 1, 3 and 4 are correct.
And let me also concede that if Fallacious Conclusion is correct,
my Perl Parsing Undecidability Proof (and probably any other)
is kaput.
But what about Observation 2?
It looks solid, but it hides a major fallacy.
We reach the run phase only if we get out of the compile phase.
True, this is something we usually take for granted, but it
we assume the compile phase eventually ends (or that we can tell whether it will
or not), we assume there is no Halting Problem in the compile phase.
And if we assume that there is no Halting Problem in Perl's compile phase,
we assume that the compile phase does not have Turing machine power.
Perl's compile phase does have Turing machine power,
and therefore is subject to the Halting Problem.
This is not just a fact, but it
is exactly that property of Perl which causes Perl parsing to not, in general,
be decidable.
The ghost of the Halting Problem must always haunt
those who seek the power of the One Universal Machine to Bind Them All.
Update: I simplified the code snippet a bit to focus on my point in this post. The original is on page 25 of the Fall 2008 issue of The Perl Review.
|
[Offer your reply]
|
OT: A Volunteer's Lament
on Oct 11, 2009 at 22:27
|
4 direct replies
|
by Sandy
|
|
|
Once upon a time, there was a young humble programmer (ok, not so young) who wanted to use perl to improve the world.
As life would have it, there was not a lot of opportunity to solve world hunger, or create ever lasting
peace via a computer language, so she had to settle for something a little less dramatic.
With one young son in elementary school, the school seemed to be overflowing with young minds
which could be brought to the pleasures of Perl.
Quest one
A plan began to bubble forth, and congealed into an idea... teaching the older children how to program,
using Perl. After school. After classes. For free! I repeat, for free! She approached the court with a
plan, to be told that much consideration must be given before allowing an unknown subject within the castle
walls. Access to the magic of the computers could be potentially dangerous, although how so, the court
did not seem to know, only that they had been told by the great IT wizard that said that this was so.
After many months (I am not kidding here, it took from the beginning of Sept to mid-November),
the court decreed that, in spite of no blessings by the IT wizards, that they would take the risk.
At this point, the humble programmer's trusted man-servant and she taught (or at least attempted to teach) the wonders
of Perl to the young vassals, and helped those interested minds find the beginning paths to the wonders of computer programming.
Through this journey of 14 weeks, the Queen never once took notice of this humble programmer, nor of her quest.
However, the humble programmer's reward was the joy on the children's faces when they could make the
computer make farting noises on command! Ah, the joy of youth.
Quest two
A year passed, and this humble programmer once again felt the urges to save the world.
And once again, many lofty pursuits seemed beyond the skills of a simple programmer. However, having approached the courtiers
of the court (home and school association) and offered her services, a new quest came to light.
It appears that the lofty web site had gathered dust and required a good cleaning.
How, the programmer said to herself, could a good cleaning truly be a noble quest. Once cleaned, dust would simply gather again
and again. Perhaps it was time to bring forth the heros of web development, Earl Template, Duchess CSS,
and Duke Content Management of System.
But there are hazards on this quest. The Great School Board Server was protected by the mighty IT wizards, who allow no Open Source Software to
dirty their pristine MS environment. None shall enter (or have access to) the Great School Board Server.
So the quest begins, and with the help of the magic of Perl, the magic of wiki, templates, and css, a peasant's Content Management System
is devised that will allow the court to manage the web-content via very simple wiki, and beautiful pages of html shall be produced.
The only thing missing is the magic incantation to put these html pages on the Great School Board Server.
The Queen and her trusty servant, who dabbles in web-magic, were petitioned for a hearing.
The trusty servant, able to produce web pages with minimal flair, was not interested on expanding her knowledge
of web-magic, nor was she interested in modifying the results of her incantations. All shall remain as is.
As with all great tales, the fates intervened. The Queen's trusted web-dabbler moved on to fairer shores,
leaving this castle with no one to spin-webs. During the summer months of inactivity, our humble programmer worked feverishly
using her magic incantations, and the mighty web heroes, to transform the dusty dried web into a dew-sparkled
work of beauty (ok, a little exaggeration, but this is just a story...). The new dew-sparkled web site
had been infused with the magic of java-script drop-down menus, starting only with a single drop
of YAML text, a drop of templates, therein multiplying to all of the web pages, so each would share a common core. In her quest
for simplicity of maintenance, our humble programmer had decreed that nothing shall be written twice. Pictoral tales
(appropriately sized for the great internet) of great sport or celebration can be conjured with a simple flick of the wrist.
The goal, again, was to provide magic where the incantations could be performed by those not in the
least bit skilled in the art of spinning webs.
During this time of feverish activity, she joined forces with another knight, highly skilled in the art of Volunteer.
The two schemed unabashedly to defeat the curses that cause outdated websites. When the court came back from holidays,
requests for hearings were once again put forth. The Queen took no delight in outsiders' help, and would have no
discourse with either of the two subjects.
True to her skill as a great volunteer, our Knight petitioned those even more powerful than the
Queen, beseeching them to ensure a reputation worthy of new enrollment by painting the web in
beautiful colours. "It has already been done", she cried, "the only thing missing is the transfer to the
Great School Board Server". And lo and behold, the greater powers decreed that this shall be done.
Although a great achievement had been attained, the quest has not yet
ended, for there still lurks the curses of dusty and dried-up websites. The Great School Board, where great
decisions are made, hired a young eager apprentice web-spinner, not only to aid the Queen in this story,
but all the Kings and Queens under the umbrella of the Great School Board. However, this poor
apprentice was shackled with the curse of 'no open-source', and could not have access to
our humble programmer's magic.
What, pray tell, shall be done? The Queen has at her side, a fair young maiden, wishing to
be indoctrinated in the arts of web spinning, or so the Queen claims. Overtures were made to
this young maiden, with promises of spells and potions to recreate and enhance the freshly
dusted web site. Deafened by what we know not, the young maiden made no reply. Again and
again our humble programmer and Knight Volunteer made overtures, and again and again they fell on deaf
ears. Pleas were made to the Queen. "Help", they cried, "we do not wish to see the
freshly spun web dry up into dust, it must be constantly freshened. Please do not let
it lie fallow."
The Queen responded by ignoring the two servants, and appealed for web-magic from the
young apprentice at the Great School Board. The apprentice in turn could not offer
what was required, as she was busy with spells for other kingdoms. The not-so-young humble programmer
almost gave up the quest, but was heartened by Knight Volunteer's stories of noble quests,
completed in spite of many obstacles, where the rewards were many. The Great Knight Volunteer
also recounted tales of appreciation by many of those in the court.
Faced with many appeals and cries of outrage by our valiant Knight Volunteer, the
Queen condescended to request website dustings from our humble programmer. However,
the ever mystical username/password required to upload to the Great School Board Server
was still unknown to all within the castle walls. The young maiden, whom it was said
wished to be a web spinning apprentice, was still mystified by all that said "html".
Although freshly dusted html sits on our humble programmer's laptop, the website
itself begins to gather dust. Our humble programmer begins to feel that the quest was not so
noble after all, because no matter how pretty, an out-of-date web-site is simply no better
than the out-of-date information contained therein.
The humble programmer and the Knight Volunteer were again beseeching all and sundry for
someone, anyone to ask for and obtain the
mystical username/password so that the castle web-aspiring apprentice could at least upload to the
Great School Board Server. All requests were ignored.
"What to do! What to do!" cried our humble programmer and Knight Volunteer in unison.
Our Knight Volunteer grabbed her lance, her armour and her unshakable determination, and
went forth to confront the Queen. Unknown to our fair Knight, the Queen employed the
evil of unknown forces, who sent a Dragon to swallow our fair Knight whole.
The Dragon was successful at knocking the fair Knight off of her feet,
and declared that the Knight Volunteer must never again involve herself in anything
to do with the now dusty website.
The humble programmer, unaware of the of Dragon or his intentions, arranged an audience with
the Queen.
"Much goes on in my mighty kingdom that you are not aware of", says the Queen to
the programmer. "All spinning of webs must come from me or one of my own.
It is not allowed for outsiders to be privy to our magics."
"But", cried the humble programmer, "I have repeatedly beseeched you and your aspiring
web apprentice for an audience
so that I may impart my thoughts and experiences, as well as to deliver the magics
and potions that can create web sites with a few simple incantations. I have been repeatedly
ignored. My only humble request is that this meeting not take me away from
those tasks that, indirectly, put food on my table."
The audience has been tentatively committed for two weeks from this telling.
Our humble programmer is no longer eager to save the world from anything. Our humble
programmer wonders if the Queen should have access to her magics before they are
dispersed into the winds via CPAN. However, hubris (one of the three virtues of a progammer)
makes our programmer very proud of her work, and the resulting website. There would
be great disappointment if the website did not take root and flourish. "What to do?"
If there is a moral to this incomplete quest, it is simply
"Do not volunteer your
efforts, no matter how noble, no matter how supported by those around you, unless the
Queen Bee wants your help."
What to do?
|
[Offer your reply]
|
Magical data modification using $_
on Oct 11, 2009 at 06:36
|
3 direct replies
|
by Sewi
|
|
|
While working with and on Padre, the great Perl IDE, I discovered a possible bug: The shortcut F2 only worked once per Padre start. As I was busy working on something else, the issue went on the "verify and fix later" list. Today (the next morning), G?bor, the father of Padre, reported the same issue and this time I investigated it and found a common case causing very_hard_to_find errors.
Padre is using Actions for menu options, shortcuts, etc. The Action for showing the Perl help search (F2) is handled by the following piece of source:
for ( @{ $self->{event} } ) {
next if ref($_) ne 'CODE';
&{$_}(@args);
}
Once I verified that each F2 keypress reached this point by adding a debug print above the loop, the following debug prints got surprising results:
print "---START---\n";
for ( @{ $self->{event} } ) {
print STDERR $self->{name}." => $_\n";
next if ref($_) ne 'CODE';
&{$_}(@args);
}
This may trigger a "Use of uninitlized value" warning as "use warnings;" is active, but I don't care of them for debug prints which never reach the public. Anyway, here is the result:
---START---
help.search => CODE(0x9bcb9b0)
help.search => CODE(0xa2f8618)
---START---
help.search => -f
help.search => CODE(0xa2f8618)
We're walking through an array which isn't - believe me - touched anywhere, but the first value magically changes. Memory corruption? Human computer? Moon phase problems? No! It's the $_'s evil side. The fix was simple:
print "---START---\n";
for my $item ( @{ $self->{event} } ) {
print STDERR $self->{name}." => $item\n";
next if ref($item) ne 'CODE';
&{$item}(@args);
}
Here we go:
---START---
help.search => CODE(0x9bcb9b0)
help.search => CODE(0xa2f8618)
---START---
help.search => CODE(0x9bcb9b0)
help.search => CODE(0xa2f8618)
What happend?
$_ was used by the loop, but it was no copy of the first array item, it was referencing it. Because something in the called CODE(0x9bcb9b0) was using $_, the new value was stored into the referenced place - the first array item overriding it's own CODE-reference.
By using a private (my) variable for the loop, $_ isn't used any longer and the problem was gone: http://padre.perlide.org/trac/changeset/8727/trunk/Padre/lib/Padre/Action.pm
This is a common problem which triggers Perl newbies and experts and which is usually hard to find, because the errors occurs at a place somewhere later when using the modified data, but if you respect this rule, you should be safe:
Use a private my-variable for looping whenever you call a sub or method within your loop!
|
[Offer your reply]
|
Google like scalability using perl?
on Oct 08, 2009 at 19:48
|
5 direct replies
|
by dpavlin
|
|
|
I have had enough with CouchDB. Really. I just couldn't wait for queries to run for the first time any longer. And I really wanted to write my views in perl. Because I was mostly manipulating hashes which came from perl anyway.
Then I started dreaming. Disks are slow. Only right way to read them is sequentially, so it rules out disk as storage if you want to have fast access. So, what is fastest way to run perl snippets? In memory.
But, I would run out of memory eventually. So I would have to support sharding across bunch of machines... That would also enable me to scale linearly just by adding a new machine or two...
I just had a bunch of web kiosks running Debian live around, so I decided to try does this idea sound sane in a week. And sure enough, I had working version after a week.
Then I decided to rip it apart and rewrite into simpler one which is modeled around management of individual nodes and much simpler network protocol. And I discovered that parsing file on master node isn't bad because it cuts down on required dependencies on deployment. And with a little bit of caching it even provides speedup on startup.
In this stage, it's quite usable toy. I would really appreciate feedback about it. Is it interesting for other people to try it? Or did I just learned a few lessons about scalability that everybody else already knows?
And lastly how would you release such a toy? CPAN doesn't really seems like a right place, so is Ohloh enough? It's not in git, so github isn't really an option.
|
[Offer your reply]
|
|
|
New Cool Uses for Perl
|
Get warranty information from a list of hosts
on Oct 12, 2009 at 05:07
|
1 direct reply
|
by mickep76
|
|
|
Will take a list of hosts from either STDIN or a file. It will resolve the hosts and then try to
access them using SSH to extract manufacturer, serial number and product name using dmidecode. It
will then access the manufacturers support page to determine the warranty of the host. Currently
it works with IBM, HP and DELL.
Assumes you are using SSH Public Keys, if your key has a password use ssh-agent to automate the password typing.
Using it on HP has some shortcomings because of their support page. It requires you to specify country
and product number, neither is possbile to extract from a host in any automated faschion. To work around
this issue there is a convertion table for HP product name to product number and country will need to
be specified either per subnet or one default location.
|
[Offer your reply]
|
Shell Command plugin for Padre
on Oct 09, 2009 at 18:21
|
0 direct replies
|
by gsiems
|
|
|
This Padre plugin allows users to type shell commands/scripts into the active document and run them. The output from the command is then inserted into the document after the command. See the POD for examples.
Caveat emptor: I've only tested this on Linux, but it *should* work on pretty much any *nix like system.
--gsiems
|
[Offer your reply]
|
|
|
New Perl Poetry
|
From C++ class
on Oct 05, 2009 at 16:18
|
1 direct reply
|
by Anonymous Monk
|
|
|
It's not the most eloquent way to put it, and it's still got some code structure instead simply flowing, but I've never tried this before. It's venting/jest.
#!/usr/bin/perl
use strict;
open (BLACKBOARD, "+>blackboard"); #look around
no strict;
use less 'time';
my $hand = 'reluctant'; @chalk = 'obsolete';
sub cheat {print BLACKBOARD "I will not use Perl in C class\n";}
until ($caught) {
use warnings;
&cheat;
$teacher_enters = int(rand(10));
if ($teacher_enters == 1) {
no warnings;
$caught = "red handed";
close BLACKBOARD;
delete @chalk[1,2,4];
} else {redo}
}
die "You are not to use Perl in C class, start the assignment again!";
|
[Offer your reply]
|
|
|
New Monk Discussion
|
Making assessments
on Oct 08, 2009 at 03:47
|
6 direct replies
|
by ELISHEVA
|
|
|
A few months ago (end of July) we had an intrusion into an old PerlMonks database that created and continues to create an on-going discussion and strong emotions. The question I'd like to know is what material impact has the password debacle had on PerlMonks?
I'd like to know our gut feelings and I'd like to put some numbers behind that. Usually when someone has an idea for an interesting new set of site stats they code it up and then present a post to show it off. But I want to reverse the process. Before I start coding or make requests for missing information, I'd like to discuss this.
What differences have you noticed, if any? Consider site traffic volume, composition of users visiting, quality of questions and responses, number of nodes. Is there anything missing from this list? What other indicators should be considered?
Any attempt to quantify our gut observations is likely to be ambiguous at best. Numbers never tell the whole story. Worse yet, to quantify something we often need to use a proxy that only partially correlates with the behavior we want to measure.
However, observation is vulnerable to issues of salience and sometimes wishful thinking. It is human nature to see what we want to see. But even when we try to be objective, things have to catch our attention for us to observe them. We tend to give more weight to the things we care about than the things we don't. What numbers would give us objective information that we could use to counter bias in our observations?
Here are some of my preliminary ideas. I'd like to see before and after trends in the following statistics. I emphasize the word "trend" because there could be normal seasonal variations in PM traffic and I wouldn't want to confuse that with impact analysis.
- rate of new user creation.
- number of daily users by level, frequency of visit, and length of membership
- number of daily "unique visitors"
- number of anonymous monk posts
- votes per day, also by level, frequency of visit, and length of membership
- posts per day, by level
What I'd like to know is: did the exploit change the behavior of monks in any way? Is the impact, if any, primarily among experienced regular users or occassional and/or low level users?
If for example, the impact is primarly in the rate of non-spam new user creation, I would surmise that we likely have suffered significant PR damage (or we have an SEO problem). If long term members are visiting less often, voting less regularly, or posting less frequently I might worry about loss of trust in the established Perl community. I would hope that such numbers would show no statistically significant impact. But I think it is important to know, even if the results are scary or painful. If there is damage, we need to correct it. It is impossible to know the right course of action unless we understand the nature of that damage.
What do you want to know? What would you do to measure it? What implications would you draw from the data? What corrective action would that imply?
Best, beth
|
[Offer your reply]
|
|
|
|