Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts
Tuesday, September 8, 2009
Perl Now Runs On Android Scripting Environment (ASE)
I think I have heard about it before, but I managed to push it down to my subconscious level. Now off to figure out which android phone to throw into the ring of my gadget wishlist.
Wednesday, September 2, 2009
ActiveState - People Don't Like You?
This is the first time I heard about people emitting strong comments against ActiveState, but I agree with Dami, ActiveState has been making my life very productive, it's products and business practices has been very satisfactory to me.
Wednesday, August 12, 2009
Translating The Name of Month To Number
Another Perl code posted since I am getting tired of rewriting it all the time.
eg:my %months = (
Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6,
Jul=>7, Aug=>8, Sep=>9, Oct=>10, Nov=>11, Dec=>12,
January=>1, February=>2, March=>3,
April=>4, May=>5, June=>6,
July=>7, August=>8, September=>9,
October=>10, November=>11, December=>12,
);
parseDate('Jan 1 2009 12:00:00:000AM');
sub parseSQLDate {
my ($txt) = @_;
if ($txt =~ /^(\w+)\s+(\d+)\s+(\d+)\s+(\d+):(\d+):(\d+):(\d+)/) {
use DateTime;
my %months = (
Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6,
Jul=>7, Aug=>8, Sep=>9, Oct=>10, Nov=>11, Dec=>12,
January=>1, February=>2, March=>3,
April=>4, May=>5, June=>6,
July=>7, August=>8, September=>9,
October=>10, November=>11, December=>12,
);
my $dt = DateTime->new(
year => $3,
month => $months{$1},
day => $2,
time_zone => 'floating',
);
return $dt;
}
}
Thursday, July 30, 2009
Ambigous Win32:OLE::LastError() Message
Running this code snippet:
Yields:use Win32::OLE;
$lrEngine = Win32::OLE->new('wlrun.LrEngine');
$lrScenario = $lrEngine->Scenario();
$rc = $lrScenario->new(0, 1);
# do not save previous
# regular vusers based scenario
$scriptLocation = 'PATH\TO\SCRIPTNAME\SCRIPTNAME.usr';
$scriptName = 'SCRIPTNAME';
$lrScenario->Scripts->Add($scriptLocation, $scriptName);
print "Win32::OLE::LastError: ".Win32::OLE::LastError()."\n";
Yes, the code passes string, even changing the code to force COM BSTR usage still generates the same error messageWin32::OLE::LastError: Win32::OLE(0.1709) error 0x80020005: "Type mismatch"
in METHOD/PROPERTYGET "Add" argument 2
What gives? The code definitely follows the documentation to the dotuse Win32::OLE::Variant;
$scriptName = Variant(VT_BSTR, 'SCRIPTNAME');
The answer: Variants by reference, changing the code, to reflect the snippet below, fixes the problem.Function Add(Path As String, Name As String) As Long
Add Script to Scenario
use Win32::OLE::Variant;
$scriptName = Variant(VT_BSTR|VT_BYREF, 'SCRIPTNAME');
Wednesday, July 29, 2009
Submitted 1st Perl Bug To ActiveState
http://bugs.activestate.com/show_bug.cgi?id=83895
--Note: I see, basically reverse doesn't sort the list in reverse order, but it will reverse the list.
--Note: I see, basically reverse doesn't sort the list in reverse order, but it will reverse the list.
Reverse Function Is Not Working Properly
Dan caught it, not me
It prints:
--Apparently I can reproduced this using ActiveState v5.10.0 build 1001 [283495]
use strict;
my $DATA;
{
local $/ = undef;
my $DATA_text = ;
eval "$DATA_text";
die $@ if $@;
}
print "# incorrect reverse sort using reverse function\n";
foreach my $date (reverse keys %{$DATA}) {
print "$date\n";
}
print "\n";
print "# correct reverse sort\n";
foreach my $date (sort {$b cmp $a} keys %{$DATA}) {
print "$date\n";
}
__DATA__
$DATA = {
'2009/07/19' => {
files => 1,
},
'2009/07/12' => {
files => 1,
},
'2009/07/05' => {
files => 1,
},
'2009/06/28' => {
files => 1,
},
'2009/06/21' => {
files => 1,
},
};
It prints:
>perl reverse_problem.pl
# incorrect reverse sort using reverse function
2009/07/12
2009/07/05
2009/07/19
2009/06/28
2009/06/21
# correct reverse sort
2009/07/19
2009/07/12
2009/07/05
2009/06/28
2009/06/21
>perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 18 registered patches, see perl -V for more detail)
Copyright 1987-2007, Larry Wall
Binary build 822 [280952] provided by ActiveState http://www.ActiveState.com
Built Jul 31 2007 19:34:48
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
--Apparently I can reproduced this using ActiveState v5.10.0 build 1001 [283495]
Wednesday, June 3, 2009
Use PPM-Make To Make My Own PPM Repository
After getting tired of disappearing modules @ theoryx5.uwinnipeg.ca, and having to merge the files between several machines manually, I decided to build my own repository.
Luckily, Randy Kobes (the maintainer of theoryx5.uwinnipeg.ca) also releases PPM-Make to compile the code from scratch, together with the release of MinGW under PPM, these make my life a lot easier to compile and host the ppm myself.
Playing with the PPM-Make module for a while, I realized that I sorely need:
> ppm install http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/Acme-Bleach.ppd
I'll upload more modules as I get them successfully compiled and tested.
Luckily, Randy Kobes (the maintainer of theoryx5.uwinnipeg.ca) also releases PPM-Make to compile the code from scratch, together with the release of MinGW under PPM, these make my life a lot easier to compile and host the ppm myself.
Playing with the PPM-Make module for a while, I realized that I sorely need:
- To organize the directory structure
- The .ppd & .tar.gz files: http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/
- Archive (zip file for local install): http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/zips/
- Another option (I named it vsz) to insert the version of the module to the zip file name for archiving purposes.
> ppm install http://angrybots.com/ppm/as_p5_8_b822/x86/sandbox/Acme-Bleach.ppd
I'll upload more modules as I get them successfully compiled and tested.
Tuesday, June 2, 2009
PPM-Make
Just research the PPM::Make problem on my desktop, it appears that it has v0.94, I need to upgrade it to v0.96, and that's not half of the problem: apparently the ppm repository at theoryx5.uwinnipeg.ca doesn't have v0.96. Surprise!
So I need to add tcool.org PPM repository:
> ppm repo add http://ppm.tcool.org/archives/package.xml
Researching the module again:
>ppm search ppm-make
1: PPM-Make
Make a ppm package from a CPAN distribution
Version: 0.940
Repo: theoryx5.uwinnipeg.ca
2: PPM-Make
Make a ppm package from a CPAN distribution
Version: 0.96
Repo: ppm.tcool.org
Remedy:
>ppm install 2 --force
Downloading PPM-Make-0.96...done
Downloading libwww-perl-5.826...done
Downloading version-0.76...done
Downloading IO-Compress-2.019...done
Downloading Compress-Raw-Bzip2-2.019...done
Downloading Compress-Raw-Zlib-2.019...done
Unpacking PPM-Make-0.96...done
Unpacking libwww-perl-5.826...done
Unpacking version-0.76...done
Unpacking IO-Compress-2.019...done
Unpacking Compress-Raw-Bzip2-2.019...done
Unpacking Compress-Raw-Zlib-2.019...done
Generating HTML for PPM-Make-0.96...done
Generating HTML for libwww-perl-5.826...done
Generating HTML for version-0.76...done
Generating HTML for IO-Compress-2.019...done
Generating HTML for Compress-Raw-Bzip2-2.019...done
Generating HTML for Compress-Raw-Zlib-2.019...done
Updating files in site area...done
169 files installed
8 files unchanged
22 files updated
Last, for $ENV{PATH} move C:\Perl5.8.8\site\bin to the front of C:\Perl5.8.8\bin
So I need to add tcool.org PPM repository:
> ppm repo add http://ppm.tcool.org/archives/package.xml
Researching the module again:
>ppm search ppm-make
1: PPM-Make
Make a ppm package from a CPAN distribution
Version: 0.940
Repo: theoryx5.uwinnipeg.ca
2: PPM-Make
Make a ppm package from a CPAN distribution
Version: 0.96
Repo: ppm.tcool.org
Remedy:
>ppm install 2 --force
Downloading PPM-Make-0.96...done
Downloading libwww-perl-5.826...done
Downloading version-0.76...done
Downloading IO-Compress-2.019...done
Downloading Compress-Raw-Bzip2-2.019...done
Downloading Compress-Raw-Zlib-2.019...done
Unpacking PPM-Make-0.96...done
Unpacking libwww-perl-5.826...done
Unpacking version-0.76...done
Unpacking IO-Compress-2.019...done
Unpacking Compress-Raw-Bzip2-2.019...done
Unpacking Compress-Raw-Zlib-2.019...done
Generating HTML for PPM-Make-0.96...done
Generating HTML for libwww-perl-5.826...done
Generating HTML for version-0.76...done
Generating HTML for IO-Compress-2.019...done
Generating HTML for Compress-Raw-Bzip2-2.019...done
Generating HTML for Compress-Raw-Zlib-2.019...done
Updating files in site area...done
169 files installed
8 files unchanged
22 files updated
Last, for $ENV{PATH} move C:\Perl5.8.8\site\bin to the front of C:\Perl5.8.8\bin
Friday, May 29, 2009
PPM-Make Is Goodz
Last night, I half jokingly installed PPM::Make and MinGW for Perl 5.8.8 on the laptop and built ORM 0.95. It worked. What was going on with my desktop?
Tuesday, October 28, 2008
Syndicating Website Updates
Several good websites just don't have the latest technology, e.g.: News Releases page of National Ignition Facility web page doesn't have RSS feed. Yet, they have the biggest laser gun that you want to pay attention to.
Kephra is another editor written in Perl and wxPerl, it is very promising project, but it still doesn't have the major functionality that I want: folding. I need to monitor the updates from time to time.
Knowing me, I'll forget to visit them later in the future.
Enter getNews.pl.
Currently the script downloads those two web pages, parse the news section for updates and send it to my GMail account. There are several reasons why it has to go to GMail:
Kephra is another editor written in Perl and wxPerl, it is very promising project, but it still doesn't have the major functionality that I want: folding. I need to monitor the updates from time to time.
Knowing me, I'll forget to visit them later in the future.
Enter getNews.pl.
Currently the script downloads those two web pages, parse the news section for updates and send it to my GMail account. There are several reasons why it has to go to GMail:
- Google Reader for Mobile (GRfM) on BlackBerry is web based application, extremely slow to skip junks.
- GRfM is build on GWT framework: the URL of all anchors begins with http://www.google.com/gwt/n?u=[URL encoded URL]. It is extremely messy and unusable when I want to email it and save the URL to delicious later.
- GMail client on BlackBerry is well suited for quick feed browsing (it supports short cuts), except it suffers at displaying web content: it doesn't display format, image and anchor (let along embedded web content), but it does recognize URL in plain text and anchor it.
- GMail has been my premier to do list, I just star the item as a reminder to delicious it - yumm.
Saturday, July 5, 2008
Ticket #34 Of googleappengine
It is now counting 900 against Ruby (1159) and PHP (1218). It is very good growth considering it is half that of Ruby two months ago.
googleappengine issue page.
googleappengine issue page.
Tuesday, June 10, 2008
Net::SMTP::TLS
For no apparent reason, I poked around mail client setup for gmail last night and I found it mentioned STARTTLS on their SMTP setup. Several month ago I didn't find any working Perl module to send email via google, so I decided to conduct a little search again using that keyword.
Enter Net::SMTP::TLS.
Enter Net::SMTP::TLS.
use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
'smtp.gmail.com',
Hello => 'gmail.com',
Port => 587,
User => 'tracelogger@gmail.com',
Password=> 'pwd',
Timeout => 10,
Debug => 1,
);
$mailer->mail('tracelogger@gmail.com');
$mailer->to('anybody@world.com');
$mailer->data;
$mailer->datasend("To: anybody\@world.com\n");
$mailer->datasend("\n");
$mailer->datasend("Sent thru TLS!");
$mailer->dataend;
$mailer->quit;
Thursday, February 7, 2008
Wednesday, January 23, 2008
Why Convert XML Data To Hash Structure Using XML::SAX?
Instead of using XML::Simple? The structure, generated by XML::Simple, is not consistent since it recognizes an empty tag as empty hash structure, instead of null string.
- Consider this XML data:
<Order>
<Number>01234</Number>
<Status />
</Order> - Using XML::Simple produces:
$VAR1 = {
'Order' => {
'Status' => {},
'Number' => '01234'
}
}; - Utilizing XML::SAX, we could insert a null string instead of an empty hash structure:
$VAR1 = {
'Order' => {
'Status' => '',
'Number' => '01234'
}
};
Tuesday, January 22, 2008
How To Slow Cook A Piglet
This is how the pieces are glued together:
- Consider the original XML data:
<Order>
<Number>01234</Number>
<Status>OPEN</Status>
</Order> - The XML data is translated into Perl data structure, utilizing XML::SAX(why?):
The unordered hash index will not mangle the report anymore since:$VAR1 = {
'Order' => {
'Status' => 'OPEN',
'Number' => '01234'
}
}; - Along the way (of parsing XML data using XML::SAX), a report template is created with references at the right places.
Status Notes <Order> <Number>01234</Number> ${$REPORT[0]}{'RESULT'} ${$REPORT[0]}{'NOTES'} <Status>OPEN</Status> ${$REPORT[1]}{'RESULT'} ${$REPORT[1]}{'NOTES'} </Order> - To the bridge the result of comparison and the report template, another data structure is created (will be called: bridge) and it has an exact hash structure as the XML data, but it is holding references to the report template.
$BRIDGE1 = {
'Order' => {
'Status' => '$REPORT[1]',
'Number' => '$REPORT[0]'
}
}; - Consider the check data for the XML data above:
Readability is the main reason the check/validation is written in XML format.<Order>
<Number><SQL>'SELECT Status FROM Order WHERE ORDER_ID = <value>'</SQL></Number>
<Status><SQL>'SELECT OrdNum FROM Order WHERE ORDER_ID = <value>'</SQL></Status>
</Order> - Converted to Perl data structure using XML::Simple
$CHECK1 = {
'Order' => {
'Status' => { SQL => 'SELECT Status FROM Order WHERE ORDER_ID = <value>'},
'Number' => { SQL => 'SELECT OrdNum FROM Order WHERE ORDER_ID = <value>'},
}
}; - Iterating through the XML hash structure, while maintaining same path of traversal with the bridge and check hash structure:
$XML{'Order'}
-> $BRIDGE1{'Order'}
-> $CHECK1{'Order'}
$XML{'Order'}{'Status'}
-> $BRIDGE1{'Order'}{'Status'}
-> $CHECK1{'Order'}{'Status'} - Find the end of XML hash structure branch to extract the value.
if (ref($XML{'Order'}{'Status'}) eq "") {
$XMLValue = $XML{'Order'}{'Status'};
} - Get the SQL syntax from check hash and get the content from database.
if (exists $CHECK1{'Order'}{'Status'}{'SQL'}) {
$SQL = $CHECK1{'Order'}{'Status'}{'SQL'};
}
else {
# bitch later: no SQL defined.
}
$DBVALUE = getValue($SQL); - Compare the content from XML hash structure and database and write the result out to $REPORT[$index], which provided by bridge hash.
if ($XMLValue eq $DBVALUE) {
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'RESULT'} = 'PASSED';";
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'NOTES'} = '$NOTE';";
}
else {
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'RESULT'} = 'FAILED';";
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'NOTES'} = '$NOTE';";
} - After traversing all of the branches of XML hash structure, open the report template and evaluate template, producing:
Status Notes <Order> <Number>01234</Number> PASSED <Status>OPEN</Status> PASSED </Order>
Monday, January 21, 2008
Need To Glue All of The Pieces Together
These items are created:
- Data - contentRef.conf (PDS)
- Report.Template.html (HTML)
- Bridge - reportRef.conf (PDS)
- Report.html (HTML)
Saturday, January 19, 2008
Convert XML to Perl Hash Using XML::SAX
Finally, the XML is converted to Perl data structure through XML::SAX.
The content of contentRef.conf is equal to XML::Simple.
The content of contentRef.conf is equal to XML::Simple.
Friday, January 18, 2008
Diagram
Data(XML)
|
|XML::SAX ---
| |s|
|-> Data - contentRef.conf (PDS) -->|c|
|-> Report.Template.html (HTML) --->|r|
|-> Bridge - reportRef.conf (PDS) ->|i|-> Report.html (HTML)
|p|
|-> Validation (PDS) -------------->|t|
| ---
|XML::Simple |
| |
Validation - CHECK.XML (XML) Database
Thursday, January 17, 2008
XML::SAX for Comparison Report
Toying with XML::SAX again since the comparison report has to reflect the original XML.
[Insert sample here]
Currently I am writing a script to mimic XML::Tidy.
[Insert sample here]
Currently I am writing a script to mimic XML::Tidy.
Wednesday, January 16, 2008
See The Concept Takes Flight!
Yes, the concept works.
But it flops badly when the comparison report is generated. The regenerated XML is different from the original one, since standard Perl hash doesn't have the index ordered by insertion.
Thinking...
But it flops badly when the comparison report is generated. The regenerated XML is different from the original one, since standard Perl hash doesn't have the index ordered by insertion.
Thinking...
Subscribe to:
Posts (Atom)