View Single Post
  #1 (permalink)  
Old November 17th, 2006, 08:37 AM
crmpicco crmpicco is offline
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default passing parameter to a perl subroutine

This is my script, i am having problems with the line
Code:
$resortid = $func->getresortid($resortname);
- i am trying to write out the resortid to the screen, with no luck however.

Code:
#!/usr/bin/perl

# Craig R Morton
# Last_Edit: 16-Nov-2006

use ready::Sql;
use ready::DataInterface::Locations;

$sql = new ready::Sql;
$newsql = new ready::Sql;
$func = new ready::DataInterfaces::Locations;

open(IN, "/usr/local/search/currenttables");
while(<IN>) {
    chomp;
    (undef, $table) = split(/:/);
    if ($table =~ /^package/) {
        push(@tables, $table);
    }
}
close(IN);

@cursor = $sql->query(q{SELECT DISTINCT(name) FROM `location`.`resorts`});
while ($returned = $cursor[0]->fetchrow_hashref) {

    $resortname = $returned->{name};
    $resortname =~ s/'/\\\'/;        
    $resortid = $func->getresortid($resortname); 
    print "Resort ID: $resortid\n";
}
Locations.pm - module inside '/usr/lib/perl5/ready/DataInterface'
shown is just one subroutine from the module
Code:
sub getresortid {

    my $self                = shift;
    my $parameters            = shift;

    my (@cursor, $returned, @cursor2, $returned2, $resortid);

    # First try a basic name match
    @cursor = $self->{SQL}->query("select id from location.resorts where name = ?", $parameters->{name});
    if ($returned = $cursor[0]->fetchrow_hashref) {
        $resortid = $returned->{"id"};
    } else {
        # Try and see if we've got an alternate spelling
        @cursor2 = $self->{SQL}->query("select attachedtoid from location.altspellings where name = ? and attachedto = 'resort'", $parameters->{name});
        if ($returned2 = $cursor2[0]->fetchrow_hashref) {
            $resortid = $returned2->{"attachedtoid"};
        }
    }

    if ($resortid) {
        return $resortid;
    } else {
        return undef;
    }

}
www.crmpicco.co.uk
www.ie7.com
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote