Feed on
Posts
Comments

Archive for the 'Perl' Category

run unix commands in perl

to run a unix command in a perl script, use backticks. for example to call curl in perl: `curl -o file.out “http://stinkpot.afraid.org:8080″`

write a switch statement in perl

i’m still new to perl, but it appears that the language lacks a built-in switch capability. and, i’ve had bad luck with getting the bundled switch module working. after some poking around online, i’ve finally gotten something resembling a switch statement working: # pull down input $choice = ; chomp($choice); for ($choice) { /i/ && [...]

flush perl’s print buffer

sometimes, if you put a print statement inside of a loop that runs really really quickly, you won’t see the output of your print statement until the program terminates. sometimes, you don’t even see the output at all. the solution to this problem is to “flush” the output buffer after each print statement; this can [...]

how to install the DBI module

the perl DBI module allows perl to talk with mySQL. to install: >>perl -MCPAN -e ‘install Bundle::DBI’ you’ll then need to install the mysql driver for perl: >>perl -MCPAN -e ‘install DBD::mysql’

get the median of an array in perl

to get the median of an array of numbers, first install the numbercruncher module. then, use the following code: my($medianValue) = Math::NumberCruncher::Median(\@numArray);

install the numbercruncher module

the math::numbercruncher module has a bunch of useful array functions, like “mean” and “median.” to install, type the following at the command prompt: >> perl -MCPAN -e ‘install Math::NumberCruncher’

install the lwp module

lwp has a bunch of useful perl modules for interacting with webpages. here’s how to install: at the prompt, go with: >> perl -MCPAN -e ‘install Bundle::LWP’

word racer program

during an undergrad winter break, i was into yahoo’s word racer and experimenting with perl and shell-scripting. i thought it would be a nice little exercise to try and combine the two. the zip file linked here is the product of this learning experience. enclosed within it is a program that will exhaustively solve each [...]

read an excel file in unix or perl

argh, i wasted about an hour the other day trying to parse an excel file in perl. i thought i could just save the file as a “tab-delimited” file and load the .txt file in perl. things didn’t work out however, as perl (and the unix command line) thought the .txt file was just one [...]

« Prev

More blogs about http://desk.stinkpot.org:8080/tricks.