Home

Jul. 22nd, 2008

Pidgin Identica Status Plugin

To go along with this post, I finished the first working version of my pidgin-identica-status plugin today. It pulls an RSS feed from identi.ca, and sets the latest entry as your status in Pidgin.
It feels like a hack to me; the Perl API for Pidgin is poorly documented. I set up a Google Code project for it, and would welcome contributors to clean up the code, ad functionality, etc...
http://code.google.com/p/pidgin-identica-status/

May. 29th, 2008

Geek Dad, or using Perl to do math

Yesterday [info]littlemeridian came to me and said she knew the sum of 1+2+3... etc to 100. She had figured out a way to solve the problem without adding all the numbers.
"I can bang out a perl program that can do the math," I said, not convinced she was right (she was right, btw). So we sat at my computer and I wrote this easy program that adds consecutive numbers up to a limit you specify from <STDIN>. It took us a little while to get the math right but we eventually got it.
see the code )

Apr. 26th, 2008

Version 1.0

To go along with this post.


 

Apr. 25th, 2008

question for you perl programmers...

I wrote a script that will post to twitter. It takes a command line argument or reads a random line from a text file, and posts the result. I've got it working, but I think code could be a little cleaner.
Basically, I want to know if there is a way to put each element in an array ( like @ARGV) into a string.
For instance, if I run perl post-to-twitter.pl here is a tweet, I'd like to turn "here is a tweet" into a string so I can put it in a scalar like $post.
I think I could use a reference, but I have a hard time wrapping my head around the concept. I really want to turn the last 4 or 5 lines into one.

Thanks...

here's my code )

Oh yeah, if the command line argument has an apostrophe, the script breaks... Why is that?

Mar. 5th, 2008

Perl and regular expressions

I'm doing what my boss calls "professional development," aka learning more Perl and prgramming skills. Today I was doing an exercise that was pretty simple. Calculate an employee's gross pay based on their rate of pay, hours worked and overtime hours worked. The math is easy.

$pay_rate * ( $reg_hours + ( $ot_hours * 1.5 ) )

But then I wanted to validate input, so my program wouldn't break when the user input wasn't non-numeric. I came up with (what I think is) a unique test. I created a regex that matched only digits and an optional decimal point.

/(\d+\.?\d*)/

Problem was it let through input like 7.h. I didn't want that. So I just compared what the regex matched to the string I was putting throught the regex! If they matched, input was valid!

if ( $_[0] =~ m/(\d+\.?\d*)/ and $_[0] eq $1 ) {
$is_valid=1;
}


I'm giving myself a self congratualory high-five.
mangavatar

July 2009

S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Advertisement

Syndicate

RSS Atom
Powered by LiveJournal.com