Thursday, August 03, 2006

Yaakov rewrote my little script to be more generic so it will pull out any set of variables with something[stuff]

for $key (keys %param) {
next unless $key =~ /^(.+)\[(\S+)]$/;
$named_parameter_hashes->{$1}{$2} = $param{$key};

Here's a one liner with sample data you can try also

perl -MData::Dumper -wle '%h=("data\[first\]","Bob","data\[last\]","Smith","cost\[retail\]",12034,"cost[wholesale]",10344); for $k (keys %h) {next unless $k=~ /^(.+)\[(\S+)]$/; $hh->{$1}{$2}=$h{$k}}; print Dumper $hh'

Wednesday, August 02, 2006

I'm still alive.

I have had a bunch of things going on... incuding my grandma breaking both wrists, my sister getting severe heatstroke and on dialysis for 5 days (a few days as critical!) .. my dad having surgery.... all within the span of about 5 weeks. Talk about crazy. Everybody is pretty much better now, so hopefully we just had all our issues at once.

I've been sort of in hermit mode the past month since YAPC. I even skipped Ruby Meeting!!

I've been doing Perl at my new job and after 6 years of PHP, I find it rather challenging at times as I take different approaches to things probably then the average perl programmer. I'm always saying to my boss.. now I would do it like this or that in ruby/ that the same in perl? ... And in most cases, with a few variations...its about the same and I've been able to function pretty much as normal.

Until today.. whenI suddenly thought... if I had a form like

<input name="data[first]" type="text">
<input name="data[last]" type="text">

will it come into my variable namespace as an array ...err Hash? In PHP, it would come in as an associative array. I was most certainly not looking forward to grabbing a ton of variables from my form (and I know there are larger forms to come in my system!) and passing each one.. blah blah. My head started to hurt. I emailed a friend and he said oh yeah many modules will parse that including ... well thats what I am using (actually Mason) ... I hunt high and low, google and ask the non-serious folks in irc (who weren't too interested in the cause of my headache) ... Hmmm ...

So as my dad always says, if you want it done right, do it yourself. Or in my case, if you can't find it, write it yourself.

sub grab_hash {
my ($hash_ref, $name) = @_;
my %real_hash;
for my $key (keys %$hash_ref) {
if ($key =~ /^($name)\[(\S+)\]$/) {
$real_hash{$2} = $hash_ref->{$key};
return \%real_hash;

I wrote this to sort through the param hash, pull out those items with data[ \S+ ] and build another hash. It works, i pass it the all the vars and it returns me a neat little hash.

I know some of you are thinking I'm insane, and its already there in or some other module, but I can't find it. So if you could please point it out to me, I'd appreciate it. If you have some improvements to my little function, let me know that too!

Weird, in mason the params are supposed to be available as %ARGS .. but when I tried to use \%ARGS to pass to my function the screen was full of a crapload of errors.

Friday, June 09, 2006


Intermediate Perl

In case you are like me... going through the book, doing the exercises at the end of the chapters... and one of them says use file from code download (pg 49) finding that there is no link on the book page to download source says the link is on the page of the FIRST VERSION of the book (which is named: Learning Perl Objects, References, and Modules)

*smack forehead*

But of course! why didn't I think of that... :)

Thursday, June 01, 2006

Welcome to my non php blog. I've used php for 6 years, so I think I know what I am talking about when I say I can write more brief, concise code in ruby or perl.

Flame me, see if I care.

I'm moving on...

This page is powered by Blogger. Isn't yours?