CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Cryptic error message

 



TheDragonReborn
Novice

Oct 30, 2008, 5:20 PM

Post #1 of 5 (360 views)
Cryptic error message Can't Post

Hello to all,

I am getting an error message and I am not sure what is creating it.
The message is:

"Can't locate object method "YOR229W" via package "CCSB" (perhaps you forgot to load "CCSB"?) at test.txt line 1."

The reason I am unsure about the error is because I am not using any packages and I am not using any objects. Here is my code:


Code
    #!/usr/bin/perl 
# A program to get the value ID after running JProNet

# Input file (Interactome data set)
# YLR291C YNL229C CCSB-Y2H
# YLR291C YCR086W CCSB-Y2H
# YLR291C YPR062W CCSB-Y2H
# YJL085W YBR057C CCSB-Y2H
# YLR227C YDR208W CCSB-Y2H

# Get Interactome input file to use to create hash array
print "Enter Interactome data file: " ;
$InteractomeDataFile = <STDIN> ;
chomp $InteractomeDataFile ;


# Does file exist?
unless( -e $InteractomeDataFile)
{
print "File \"$InteractomeDataFile\" does not seem to exist in this Director!!\n";
exit ;
}

# Can it open?
unless(open(INPUT1, $InteractomeDataFile))
{
print "Error !! Did not read file.\n" ;
exit ;
}

# Variables
$i = 1 ;

# Create hash array from InteractomeDataFile (A1234 => 1, B1234 => 2)
while($line = <INPUT1>)
{
# Eliminate white space and break into tokens
@tokens = split(/\s+/, $line) ;

# Get first and secont token (nodes)
$node1 = $tokens[0] ;
$node2 = $tokens[1] ;

# Create key/value pairs between nodes and integers
if($KeyMap{"$node1"})
{
# Keep value
}
else
{
$KeyMap{$node1} = $i ;
++$i ;
}

if($KeyMap{"$node2"})
{
# Keep value
}
else
{
$KeyMap{$node2} = $i ;
++$i ;
}

# Go to next iteration
++$x ;
}

# Reverse the hash array (1 => A1234, 2 => B1234)
%RevKeyMap = reverse %KeyMap ;

print "\n" ;

# LOOP THROUGH IT
while (($key, $value) = each(%RevKeyMap))
{
print $key.", ".$value."\n";
}

close INPUT1 ;

exit ;


Any suggestions?


FishMonger
Veteran / Moderator

Oct 30, 2008, 5:57 PM

Post #2 of 5 (358 views)
Re: [TheDragonReborn] Cryptic error message [In reply to] Can't Post

The code you posted would not generate that error message. Can you post the actual code you ran that generated that error?


FishMonger
Veteran / Moderator

Oct 30, 2008, 6:01 PM

Post #3 of 5 (357 views)
Re: [TheDragonReborn] Cryptic error message [In reply to] Can't Post

Every Perl script you write should include the following 2 lines
at the beginning of the script.

Code
use warnings; 
use strict;



Code
unless( -e $InteractomeDataFile)  
{
print "File \"$InteractomeDataFile\" does not seem to exist in this Director!!\n";
exit ;
}

# Can it open?
unless(open(INPUT1, $InteractomeDataFile))
{
print "Error !! Did not read file.\n" ;
exit ;
}

Could be reduced to:

Code
open INPUT1, $InteractomeDataFile or die "Error !! Did not read file. $!\n"; 


(This post was edited by FishMonger on Oct 30, 2008, 6:03 PM)


KevinR
Veteran


Oct 30, 2008, 7:03 PM

Post #4 of 5 (354 views)
Re: [FishMonger] Cryptic error message [In reply to] Can't Post


In Reply To
The code you posted would not generate that error message. Can you post the actual code you ran that generated that error?


I gotta agree, I can't see where that error would be caused by the code that was posted.
-------------------------------------------------


KevinR
Veteran


Oct 30, 2008, 7:08 PM

Post #5 of 5 (352 views)
Re: [FishMonger] Cryptic error message [In reply to] Can't Post


In Reply To
Every Perl script you write should include the following 2 lines
at the beginning of the script.

Code
use warnings; 
use strict;



In addition to FishMongers advise above, as a general practice you should avoid quoting scalars unless really really necessary, like here for example:

if($KeyMap{"$node2"})

$node2 does not need quoting and is better written without them:

if($KeyMap{$node2})

using quotes unnecessarily not only slows down your code it can lead to very hard to find bugs since quotes can mask sytnax errors like:

if($KeyMap{"node2"})

and can stringify some data you may not want stringified, like a reference.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives