Sponsored Content
Full Discussion: perl limitations vs. bash?
Top Forums Shell Programming and Scripting perl limitations vs. bash? Post 302421177 by deindorfer on Thursday 13th of May 2010 04:21:39 PM
Old 05-13-2010
Perl: XKCD Geohash Generator

Ever Read XKCD? Check this out: xkcd: Geohashing

here's a Perl Script that implements the algorithm in the comic:

Code:
#! /usr/bin/perl

use strict;
use warnings;

use LWP::Simple;
use URI::Escape;

use Finance::Quote;
use Digest::MD5;
use Math::BigInt;

my $begin_from = join '', @ARGV if @ARGV;

my $q = Finance::Quote->new;
my %dow = $q->fetch( 'nyse', '^DJI' );
my $hashthis = $dow{'^DJI', 'isodate'} . '-' . $dow{'^DJI', 'open'};
printf "DOWDATE: %s\n", $hashthis;

my $o = Digest::MD5->new;
$o->add( $hashthis );
my $hash = $o->hexdigest;
printf "MD5: %s\n", $hash;

my $x = '.' . substr ( Math::BigInt->from_hex ( '0x' . substr $hash, 0, 16), 0, 6);
my $y = '.' . substr ( Math::BigInt->from_hex ( '0x' . substr $hash, 16, 16), 0, 6);
my $addr = $begin_from || '100 S. Market St., Frederick MD';
$addr = uri_escape( $addr );
my $str = get( "http://rpc.geocoder.us/service/csv?address=$addr" );
( my $start_lat, my $start_long ) = split /,/, $str;
printf "START COORDS: %s %s\n", $start_lat, $start_long;

$start_lat =~ /(.+?)\..+$/; my $new_lat_pref = $1;
$start_long =~ /(.+?)\..+$/; my $new_long_pref = $1;
my $geohash = $new_lat_pref . $x . ' ' . $new_long_pref . $y;
printf "GEOHASH: %s\n", $geohash;

In addition to getting Lat-Long Coords, it also fetchs Real-Time Stock quotes, and runs some fairly solid crytpographic hashing algorithms....
This User Gave Thanks to deindorfer For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mkdir limitations

What characters can't be used with a mkdir? Any limits on length of name? Thank you, Randy M. Zeitman http://www.StoneRoseDesign.com (12 Replies)
Discussion started by: flignar
12 Replies

2. UNIX for Dummies Questions & Answers

Unix Sort - Limitations

Hi All, I want to sort a flat file which will contain millions of records based on a key/field. For this I want to use unix sort command and before that I want to make sure that unix sort command has any file size limitations. And also please let me know whether I have to change any... (2 Replies)
Discussion started by: chprvkmr
2 Replies

3. AIX

SORT Command Limitations

Hi every body, On AIX 4.3.3 what is the maximum file size that can be used with sort command? (0 Replies)
Discussion started by: aldowsary
0 Replies

4. UNIX for Dummies Questions & Answers

csplit limitations

I am trying to use the csplit file on a file that contains records that have more than 2048 characters on a line. The resultant split file seems to ignore the rest of the line and I lose the data. Is there any way that csplit can handle record lengths greater than 2048? Thanks (0 Replies)
Discussion started by: ravagga
0 Replies

5. UNIX for Dummies Questions & Answers

Password limitations.

I would like to set my minimum password length to on Linux and AIX. However, doing this normally would only make it so newly added users will be affected by this. I would like for when I make this change, it either truncates everyone elses password, or prompts them to change it to 8+ characters.... (2 Replies)
Discussion started by: syndex
2 Replies

6. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

7. UNIX and Linux Applications

gnuplot limitations

I'm running a simulation (programmed in C) which makes calls to gnuplot periodically to plot data I have stored. First I open a pipe to gnuplot and set it to multiplot: FILE * pipe = popen("gnuplot", "w"); fprintf(pipe, "set multiplot\n"); fflush(pipe); (this pipe stays open until the... (0 Replies)
Discussion started by: sedavidw
0 Replies

8. Red Hat

Eth0 Limitations

Hi, I have noticed some performance issues on my RHEL5 server but the memory and CPU utilization on the box is fine. I have a 1G full duplexed eth0 card and I am suspicious that this may be causing the problem. My eth0 settings are as follows: Settings for eth0: Supported ports: ... (12 Replies)
Discussion started by: Duffs22
12 Replies

9. Solaris

Solaris limitations

Hi, I recently started working with Solaris, and what I noticed is that a lot of commands I used to regularly use don't work, like sed -i and grep -r. I have found work arounds for these problems though but it's a pain in the ass. I'm just wondering why they decided not to include these handy... (4 Replies)
Discussion started by: Subbeh
4 Replies

10. Linux

Linux partitions and limitations

In recently reading an article on linux basics before I embark and my personal installation project I came across this passage - IDE drives have three types of partition: primary, logical, and extended. The partition table is located in the master boot record (MBR) of a disk. The MBR is the... (12 Replies)
Discussion started by: Synchlavier
12 Replies
Math::BigInt::FastCalc(3pm)				 Perl Programmers Reference Guide			       Math::BigInt::FastCalc(3pm)

NAME
Math::BigInt::FastCalc - Math::BigInt::Calc with some XS for more speed SYNOPSIS
Provides support for big integer calculations. Not intended to be used by other modules. Other modules which sport the same functions can also be used to support Math::BigInt, like Math::BigInt::GMP or Math::BigInt::Pari. DESCRIPTION
In order to allow for multiple big integer libraries, Math::BigInt was rewritten to use library modules for core math routines. Any module which follows the same API as this can be used instead by using the following: use Math::BigInt lib => 'libname'; 'libname' is either the long name ('Math::BigInt::Pari'), or only the short version like 'Pari'. To use this library: use Math::BigInt lib => 'FastCalc'; Note that from Math::BigInt v1.76 onwards, FastCalc will be loaded automatically, if possible. STORAGE
FastCalc works exactly like Calc, in stores the numbers in decimal form, chopped into parts. METHODS
The following functions are now implemented in FastCalc.xs: _is_odd _is_even _is_one _is_zero _is_two _is_ten _zero _one _two _ten _acmp _len _num _inc _dec __strip_zeros _copy LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. AUTHORS
Original math code by Mark Biggar, rewritten by Tels <http://bloodgate.com/> in late 2000. Seperated from BigInt and shaped API with the help of John Peacock. Fixed, sped-up and enhanced by Tels http://bloodgate.com 2001-2003. Further streamlining (api_version 1 etc.) by Tels 2004-2007. SEE ALSO
Math::BigInt, Math::BigFloat, Math::BigInt::GMP, Math::BigInt::FastCalc and Math::BigInt::Pari. perl v5.12.1 2010-04-26 Math::BigInt::FastCalc(3pm)
All times are GMT -4. The time now is 09:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy