codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Help with key/value pairs  TheDragonReborn at 18:40 on Monday, October 20, 2008
 

Hello to all,

I am a newbie to Perl and am having problems with the use of key/value pairs. Below is my code. What am I doing wrong with my assignment of key/value pairs?
My output is empty (no matrix).

################################ CODE #######################################

#!/usr/bin/perl
use strict ;
use warnings ;

## A program to take an Interactome data set and convert to unicon format for JProNet

# Example input (Disregard the 3rd and 4th columns)
# YLR291C YNL229C CCSB-Y2H
# YLR291C YCR086W CCSB-Y2H
# YLR291C YPR062W CCSB-Y2H
# YJL085W YBR057C CCSB-Y2H


# Example assignment of nodes to integer values
# YLR291C => 1
# YNL229C => 2
# YCR086W => 3
# YPR062W => 4
# YJL085W => 5
# YBR057C => 6


# Example Output for matrix part

# Counter Node Node Weight
# 1 1 2 1
# 2 1 3 1
# 3 1 4 1
# 4 5 6 1


print "Please type the file to be converted: " ;

$input = <STDIN> ;

chomp $input ;

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

# Can we open the file?
unless( open(INPUT, $input))
{
print "Cannot open file \"$input\"\n\n" ;
exit ;
}

#counter for nodes
$i = 1 ;

#counter for output file (iteration)
$count = 0 ;

#weight value for edge
$weight = 1 ;

#array for lines (collect so that we can print after header part of fiile
@lines ;

# $endvertex is the last node iterated ( not neccessarily the last node because of multiple links)
$endvertex = 0 ;

#hash for key/value pairs between nodes ( Y12345 => 1)
%KeyMap ;

while(INPUT)
{
foreach ($line (INPUT))
{
chomp($line) ;
@tokens = split(/\s+/, $line) ;

$node1 = $tokens[0] ;
$node2 = $tokens[1] ;

# MAP THE NODES TO VALUES

if(exists $KeyMap{"$node1"})
{
}
else
{
$KeyMap({"$node1"} = $i) ;

# Record the highest value node (Last increment will be highest node)
$endvertex = $KeyMap{$node1} ;

++$i ;
}

if(exists $KeyMap{"$node2"})
{
}
else
{
$KeyMap({"$node2"} = $i) ;

# Record the highest value node (Last increment will be highest node)
$endvertex = $KeyMap{$node2} ;

++$i ;
}

# MATRIX PART !!!
# Collect output lines (exp. 1 1 2 1)
# Print nodes in ascending order (1 1 2 1) NOT (1 2 1 1) !!!
if($KeyMap{$node1} < $KeyMap{$node2})
{
$lines[$count] = "$count+1 $KeyMap{$node1} $KeyMap{$node2} $weight" ;
$count = $count + 1 ;
}
else
{
$lines[$count] = "$count+1 $KeyMap{$node2} $KeyMap{$node1} $weight" ;
$count = $count + 1 ;
}
}
}

#############################################################################
##################### OUTPUT FOR PROGRAM ##################################
#############################################################################

# Print out header to .unicon file
print "Chain\n\n" ;

print "Vertexnumber= $endvertex\n" ; # The number for the last vertex will be total
print "Startvertex=1\n" ;
print "endvertex = $endvertex\n";
print "vertexadd=0\n" ;
print "sarig=0\n\n" ; # Extra line

print "chained\n" ;

print "contact\n\n" ; # Extra line

# Print out lines (Matrix part)
foreach($row @lines)
{
print "$row\n" ;
}

print "contactend\n\n" ;

close INPUT ;

exit ;

########################### END CODE ######################################

Any help would be great.
Thanks.

  Re: Help with key/value pairs  hermanningjaldsson at 07:52 on Tuesday, October 21, 2008
 

run it in your debugger and then you can narrow the problem down.










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Change what user is looking at
•  Re: shut down computer
•  Re: Help with key/value pairs
•  how to create a paying sytem in 7 eleven using java
•  populating frames from a pop up window
•  Need a code
•  Help in Textarea !!!
•  Re: Cursor position line number in firefox.
•  Re: text field multiple


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008