scot's Journal scot's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:38:00+00:00 pudge Technology hourly 1 1970-01-01T00:00+00:00 scot's Journal Automated downloading of NOAA radar images Inspired by <a href="">Develop your own weather maps and alerts with Perl and GD</a>, I have put together a script which downloads the base radar image from a specific site at a specified interval.<blockquote><div><blockquote><div><p> <tt>use strict;<br>use LWP::Simple;<br>use POSIX;<br>my $refresh = 1800;<br>do {<br>&nbsp; &nbsp;my $base="";<br>my $timestring = strftime( "%Y%m%d_%H%M%S", gmtime() );<br>my $savefilename = "SLCRadar_".$timestring.".gif"; my $status = getstore($base,$savefilename);<br>print $status."\n"<nobr> <wbr></nobr>;<br>sleep $refresh;<br> } while ($refresh);<br>&lt;blockquote&gt;</tt></p></div> </blockquote><p>See my <a href="">Standard Code Disclaimer</a></p></div></blockquote> scot 2007-06-13T21:47:15+00:00 internet Automated extraction of NOAA weather satellite images <blockquote><div><p>NOAA updates its weather satellite images on the GOES website every 30 minutes, with images in infrared, visible light, and water vapor wavelengths; for both the eastern and western halves of the US. The script below grabs those images and saves them to a local file with a timestamp. Could prove useful for doing your own weather forecasting or whatever....I have updated the script to use the "strftime" function from the POSIX module,and the filenames now are very precise (for example "eastconusir20070530_074348.jpg"). I also updated the script to timestamp the images with Greenwich Mean Time...thanks to graff and jasonk over at Perlmonks for their feedback...</p></div></blockquote><blockquote><div><p> <tt>use strict;<br>use LWP::Simple;<br>use POSIX;<br> <br>my $image;<br>my $url;<br>my %images = (<br>"eastconusir" =&gt; "",<br>"eastconusvis" =&gt; "",<br>"eastconuswv" =&gt; "",<br>"westconusir" =&gt; "",<br>"westconusvis" =&gt; "",<br>"westconusvwv" =&gt; "",<br>);<br> <br>foreach my $key (keys %images) {<br>print $key."\n";<br>my $epoch = ( head( $images{$key} ) )[ 2 ] || next;<br>my $timestring = strftime( "%Y%m%d_%H%M%S", gmtime( $epoch ) );<br>print $timestring."\n";<br>print $images{$key}."\n";<br>my $status = getstore($images{$key},$key.$timestring.".jpg");<br>print $status."\n"<nobr> <wbr></nobr>;<br>};</tt></p></div> </blockquote> scot 2007-05-29T22:45:27+00:00 journal Sun's Java Web Server superior to Apache? <a href="">Serverwatch</a> has posted a review of Sun's Java Web Server which is very positive. My summary of the review is <a href="">here</a>. scot 2007-04-23T18:42:03+00:00 internet Method for extracting urls for filetypes + auto-retrieval <p> <a href="">This post</a> reminded me of a problem which I have been trying to solve involving extracting URL's pointing to a specific filetype (say a gz archive) from a web page. It turns out that at <a href="">CPAN</a> there is a <a href="">page </a>which contains an alphabetical list of all modules, with a hyperlink to the tar.gz file of each module.</p><p>The following code (given appropriate substitution of the command line input; ie gz for pdf) will create a text file with all of the URL's for the tar.gz files:</p><blockquote><div><p> <tt>use strict;<br>use LWP::Simple;<br>use HTML::SimpleLinkExtor;<br>#usage getfileoftype pdf &gt; urllist.txt<br>my $url = shift;<br>my $filetype = shift;<br>my $filetypelen = length($filetype);<br>my $offset = -$filetypelen;<br>#print $filetypelen."\n";<br>#print $offset."\n";<br>my $fileget = getstore($url,"tempfile.html");<br>my $extor = HTML::SimpleLinkExtor-&gt;new(); $extor-&gt;parse_file("tempfile.html");<br>my @a_hrefs = $extor-&gt;a;<br>for my $element (@a_hrefs) {<br># print $element;<br># print "\n";<br>my $suffix = substr($element,$offset,$filetypelen);<br># print $suffix;<br># print "\n"; if ($suffix =~ m/$filetype/){<br>print $element;<br>print "\n";<br>}<br>}</tt></p></div> </blockquote><p>Once you have that, you can then use the following code to automatically download all of the modules if you so choose, or whatever subset of the modules you wish to extract from the text file created by the above code:</p><blockquote><div><p> <tt>use strict;<br>use LWP::Simple;<br>use File::Basename;<br>open (DATA, "urllist.txt") || die "File open failure!";<br>while (my $downloadurl = &lt;DATA&gt;){<br>(my $name, my $path, my $suffix) = fileparse($downloadurl);<br>my $finurl = $downloadurl;<br>print $finurl."\n";<br>my $savefilename = $name.$suffix;<br>print $savefilename;<br>print "\n";<br>my $status = getstore($finurl,$savefilename); print $status."\n"<br>}</tt></p></div> </blockquote><p>Both pieces of code work nicely on my WinXP box. Yes, I know that "tempfile.html" gets clobbered, but I was just glad to get this code working, and WinXP doesn't seem to care. In any case, one can now generate a local repository of modules. Suggestions for improvement in my code are welcome!</p> scot 2007-04-04T22:51:12+00:00 tools use.perl posts hit google quickly use.perl posts frequently make it into the top hits of a google search. scot 2007-04-03T19:11:12+00:00 journal Remote computing with a Linux app server farm IBM Developerworks writes up a <a href="">slick setup</a> at the University of California where they replaced Windows XP boxes with ITX Mini-boxes in a couple of computer labs and got positive feedback from the endusers plus significant cost savings. scot 2007-02-13T16:44:01+00:00 linux Script to calculate digits of pi Introducing my blog on Perl, <a href="">Red Cloud Research</a>, with this <a href="">entry</a>. scot 2007-01-24T21:31:51+00:00 journal Dev language poll From <a href="">here:</a> Developers Embrace Java, Drop Visual Basic<br> <br> By Gregg Keizer<br> <br> Use of Visual Basic has dropped 35% since the spring, says a poll of more than 430 North American developers done by research company Evans Data Corp. Developers have abandoned Microsoft's Visual Basic in droves during the last six months, and they're using Java more than any other development language, according to a recently published survey.<br> Use of Visual Basic has dropped 35% since the spring, says a poll of more than 430 North American developers done by research company Evans Data. "Microsoft has dominated languages since the early 90s, but we are seeing much more parity now," said John Andrews, president of Evans Data, in a statement. "The use of scripting languages, as well as Java, appears to have limited VB's future market potential."<br> Developers aren't only leaving Visual Basic, they're also less likely to work in the Visual Basic.Net environment; VB.Net use is down 26%, the survey shows.<br> Java now holds the top spot, with 45% of the polled developers saying they used Java during some part of the last six months. C/C++, meanwhile, was used by 40% of the coders, and C# was used by 32%.<br> The survey also indicates that use of Ajax, short for Asynchronous JavaScript and XML, is up 10% since the spring 2006 poll, with 28% of the developers involved in Ajax-style Web interface development at some point during the last six months. scot 2007-01-11T21:11:09+00:00 news "A Java Front-End To CGI/Perl " <p>Found this <a href="">JavaCGI Bridge Presentation</a> which based on a cursory read looks like an alternative to AJAX. The gist is this:<br> &nbsp; <br> &nbsp; </p><p><div class="quote"><p>JavaCGIBridge Solution</p><p> &nbsp; &nbsp; &nbsp; &nbsp; CGI/Perl advantages</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * CGI/Perl can provide database connectivity more easily<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Application related "business-rules" are centrally maintained and executed in CGI/Perl scripts<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Browsers that don't support Java can still use the application<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Leverage existing "legacy" CGI/Perl code<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Many Internet Service Providers only allow CGI/Perl access (no daemons)</p><p> &nbsp; &nbsp; &nbsp; &nbsp; Java advantages</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Java applet becomes a truly thin client<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - only requires GUI code and GUI logic<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - JavaCGIBridge class adds ~5k overhead<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - No need to learn the entire Java class library.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - You can get by with AWT (Forms) and some utility classes<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Java applet can maintain state between all CGI script calls<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * Java applet can cache retrieved data<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - eliminates the need to constantly get redundant data from the server</p></div><p>Check the date of the presentation: 1997<nobr> <wbr></nobr>:) !!</p> scot 2007-01-09T18:48:28+00:00 java Simple extraction of links from web page <p>It took me far longer than I thought it would to come up with this code that grabs a web page and stuffs all the page's hyperlinks into a text file.<br> &nbsp; <br>Updated...</p><p><code><br>use strict;<br>use WWW::Mechanize;<br>#usage perl &gt; output.txt<br> &nbsp; &nbsp; &nbsp; &nbsp; my $url = shift;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; my $mech = WWW::Mechanize-&gt;new();<br> &nbsp; &nbsp; &nbsp; &nbsp; $mech-&gt;get($url);<br> &nbsp; &nbsp; &nbsp; &nbsp; my $status=$mech-&gt;status();<br> &nbsp; &nbsp; &nbsp; &nbsp; print $status." OK-URL request succeeded."."\n";<br> &nbsp; &nbsp; &nbsp; &nbsp; my @links = $mech-&gt;links;<br> &nbsp; &nbsp; &nbsp; &nbsp; print STDOUT ($_-&gt;url, $/) foreach $mech-&gt;links;</code></p> scot 2007-01-02T21:35:02+00:00 tools Simple automated file retriever <p>I whipped this together to grab web pages on a daily basis:</p><p><code><br>use strict;<br>use LWP::Simple;<br>use Time::localtime;<br>use File::Basename;</code></p><p><code>open (DATA, "urllist.txt") || die "File open failure!";<br>while (my $downloadurl = &lt;DATA&gt;){<br> &nbsp; &nbsp; &nbsp; &nbsp; (my $name, my $path, my $suffix) = fileparse($downloadurl);<br> &nbsp; &nbsp; &nbsp; &nbsp; my $finurl = $downloadurl;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $finurl."\n";<br> &nbsp; &nbsp; &nbsp; &nbsp; my $lt = localtime();<br> &nbsp; &nbsp; &nbsp; &nbsp; my $now_string = $lt-&gt;mon." ".$lt-&gt;mday;</code></p><p><code> &nbsp; &nbsp; &nbsp; &nbsp; my $savefilename = $now_string.$name.$suffix;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $savefilename;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print "\n";<br> &nbsp; &nbsp; &nbsp; &nbsp; my $status = getstore($finurl,$savefilename);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $status."\n"<br>}</code></p> scot 2007-01-02T18:27:24+00:00 tools Java + Perl = Good stuff This <a href="">article</a> is definitely worth a look. From the article: "The key to using JCR from Perl is Inline::Java. This library allows a Perl program to call Java methods with very little effort." scot 2006-12-22T23:37:43+00:00 java Today's quote from St. Larry Much as I hate to say it, the Computer Science view of language design has gotten too inbred in recent years. The Computer Scientists should pay more attention to the Linguists, who have a much better handle on how people prefer to communicate. --Larry Wall<br> <br> Amen! scot 2006-12-14T18:17:37+00:00 others Pugs-Perl6 on Windows is impressive I've been meaning to take a look at Perl 6 and Pugs and found <a href="">Jonathon Worthington's site</a>. Installing and running Perl6-Pugs on my Windows box from Jonathan's binary was astoundingly quick and easy. He's got a nice "Quick Start" tutorial as well. ++JW. scot 2006-12-14T18:09:26+00:00 perl6 Review of "Perl in a Nutshell" 2nd edition This journal entry is my working draft for eventually submitting a review as a story. My thesis is that this book is a solid addition for any Perl coder's bookshelf. Why?<br> -someone with experience in another language could pick this book and be productive fairly quickly<br> -plenty of useful code snippets<br> -section with usage summary for all of the standard modules<br> -sections on CGI gives you more than just what's in but form a good intro to CGI in general<br> Book details<br> Title: Perl in a Nutshell<br> by Stephen Spainhour, Ellen Siever, Nathan Patwardhan Second Edition: June 2002<br> Series: In a Nutshell<br> ISBN 10: 0-596-00241-6<br> ISBN 13: 9780596002411<br> Pages: 760<br> Current price at $39.95 scot 2006-12-13T19:49:19+00:00 books This site's daily Wall quote This morning's quote from Larry got me chuckling: "Let's say the docs present a simplified view of reality...<nobr> <wbr></nobr>:-)". I created myself a little file to paste these quotes into for future enjoyment. Nice site feature! scot 2006-11-30T16:15:34+00:00 useperl Smart move by Sun Microsystems The <a href="">following </a> popped up on the Sun Developer Network RSS feed a few days ago:<br> <br> "For a limited time, Sun is offering a free DVD media kit which includes the Solaris 10 Operating System for both SPARC and x86 platforms as well as Sun Studio 11 software.<br> Take this opportunity to get familiar with the most advanced operating system on the planet and the tools which enable the highest optimizations and best runtime performance on the Solaris Operating System, bar-none.<br> Sun Studio software provides optimizing C, C++ and Fortan compilers, visual performance tools, and high performance libraries to enhance your Solaris development environment."<br> <br> The cost to Sun to distribute DVD's will be minimal compared to the potential increase in market share for/usage of Solaris. There's no question that Solaris has always been a rock-solid *nix, and if Sun can get the open source community using Solaris the benefits to Sun are obvious. scot 2006-11-29T21:55:53+00:00 unix EnterpriseDB-PostGreSQL rebranded I stumbled onto the website of <a href="">EnterpriseDB</a> which markets a product called EnterpriseDB which appears to be essentially a re-branded PostGreSQL. I will be very interested to see if CPAN modules targeted to PostGreSQL work out of the box with this database. Presumably, they would. My super search of turned up exactly zero references to EnterpriseDB, which was mildly surprising.<br> <br> The biggest roadblock to more widespread adoption of PostGreSQL in my opinion has been its horrible name. Any branding or marketing consultant worth their salt would blanch in horror if a client suggested giving a product such a hard to spell, difficult to pronounce name. I don't know how any CIO could sell switching to PostGreSQL; you can just imagine the CEO saying "you want us to switch to Post-what? post-grrsklll? post grease-kill? Forget it." scot 2006-11-29T19:47:15+00:00 others