Perl
Catalyst Framework PDF Print E-mail
Programming Portfolio - Perl
Written by Administrator   
Sunday, 13 September 2009 10:47

http://www.catalystframework.org

http://perl.apache.org/

 

http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/Tutorial.pod

The Catalyst framework is a flexible and comprehensive environment for quickly building high-functionality web applications.

Last Updated ( Sunday, 13 September 2009 15:19 )
 
Modifying Each Element In An Array PDF Print E-mail
Programming Portfolio - Perl
Written by Jeremy P. McKay   
Tuesday, 14 July 2009 18:23

I  have an array called @data.  I want to check each element in the array for a value, and if that value exist, I wan to delete it

 

I could try

@data =~ ~ s/$postalCode//;

### creates an error about private arrays

Maybe this

for my $dat(@data){
$dat=~ s/$postalCode//;
}

 

The above code does not modify the array at all.  We could create a temporary array and then pop puch and reassign upon going through each element.  That could be time consumming especially if I have 250,000 arrays.  So let's look at map. Charles Galpin has written a pretty simple tutorial on using map here http://articles.techrepublic.com.com/5100-10878_11-1044685.html.

 

So after reading Charles' article,  I try .

map {s/$postalCode//} @data;

 

Just to a make sure it works I ran the a line of data through it.  You should always check yoru code on small sets of data. The test and results are below.

 

my $data = "Beijing Normal University    Beijing 100875    China";

my @data = split/\t/, $data;
$postalCode = 100875;
for my $d(@data){
print "$postalCode $d\n";

}

print  "Postal Code Removed\n";

map {s/$postalCode// } @data;
# just checking
for my $d(@data){
print "$postalCode $d\n";

}   
exit;

 

100875 Beijing Normal University
100875 Beijing 100875
100875 China
Postal Code Removed
100875 Beijing Normal University
100875 Beijing
100875 China

 

Hope this helps in your data munging

 

 

Last Updated ( Tuesday, 14 July 2009 19:19 )
 
An Interesting Foolish Error PDF Print E-mail
Programming Portfolio - Perl
Written by Jeremy P. McKay   
Wednesday, 04 March 2009 21:19

I had several mdb files that required the same update to one field.  So I use the following is a snippet of the code I was using.

 

my $sql = "update [Contact] set Contact.Source ='BioCRM'";
 my $sth = $dbh->prepare($sql) or die(
 "Can't prepare SQL statement. Perl
 + says $!, DBI says ". $dbh->errstr. "\n");
 $sth->execute($sql) or die "Couldn't execute statement: " . $sth->errstr;

 

Kept getting the following error

DBD::ADO::st execute failed: Bind Parameter 1 outside current range of 0. at
Z:\UpdateAllContactSource.pl line 33, <> line 1.
Couldn't execute statement: Bind Parameter 1 outside current range of 0. at
Z:\UpdateAllContactSource.pl line 33, <> line 1.

 

At first I searched the Internet for a solution, I updated all my DBD drivers and it still did not work.  It is funny the number of articles you can find when you search for DBD::ADO::st execute failed:

488 on Google.

None of them helped.  My error is in this line:

$sth->execute($sql) or die "Couldn't execute statement: " . $sth->errstr;

When execute is used in this way it does not take any parameters

The fix

$sth->execute() or die "Couldn't execute statement: " . $sth->errstr;

 

Hope this helps someone else

 If not try using the do syntax for updates and inserts

 

$dbh->do($sql) or die(
 "Can't execute SQL statement. Perl
+ says $!, DBI says ", $DBI::errstr, "\n"
);

 

Keep Coding

-

Jeremy

 

 

 

 

Last Updated ( Tuesday, 17 March 2009 17:29 )
 
QC checklist for Lone Ranger (PERL) PDF Print E-mail
Programming Portfolio - Perl
Written by Jeremy P. McKay   
Monday, 16 February 2009 17:18

QC checklist for 'The Lone Ranger' PERL Programmers (true)

 

1.  Use strict pragmas, set warning flags, write comments

 

2.  CLOSE files as soon as you are done using them.  The files will close when your program closes, but you should take control in you scripts.

3. Remove all warnings even if they are not fatal errors do not remove warnings by removing -w.

 

4.  If you are porting files build in DOS or Mac to Unix/Linux, use dos2unix on all files ported in this manner.  Using the Unix utility dos2unix, will keep you line endings easily identifiable and parseable in UNIX.

 

5. Seek code reviews from other coders, even if they do not know Perl.  If you can not tell another programmer what each line of your code is doing,  then what is each line of your code doing?

 

If you code with these thoughts in mind, follow these processes, write decent comments, you will find your code is more maintainable, and maybe even beautiful in some places.

 

Keep On Coding!

 

 

 

Last Updated ( Friday, 25 September 2009 21:19 )
 
Webservices WIth Perl PDF Print E-mail
Programming Portfolio - Perl
Written by Jeremy P. McKay   
Monday, 01 September 2008 14:02

Programming Webservices With Perl  Book

http://www.soaplite.com/

Last Updated ( Monday, 15 September 2008 03:48 )
 


Copyright © 2012 Jeremy P. McKay. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 

 

Jeremy's Artist Blog

Jeremy P. McKay, Artist
"Creative work is not a selfish act or a bid for attention on the part of the actor. It is a gift to the world and every being in it. Don't cheat us of your contribution. Give us what you've got" -- The War of Art: Break Through the Blocks and Win Your Inner Creative Battles by Steven Pressfield.

Mark Joyner

Mark Joyner's Blog: Atomic Mind Bombs (Personal Development Brain Puzzle Cartoons)