perl (word by word check if a hash key)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl (word by word check if a hash key)
# 1  
Old 01-08-2010
perl (word by word check if a hash key)

Hi,
Now i work in a code that
1-get data stored in the database in the form of hash table with a key
field which is the " Name"
2-in the same time i open a txt file and loop through it word by word
3- which i have a problem in is that :

I need to loop word by word and check if it is a hash key or not if a hash key print it .

Code:
#!/usr/bin/perl
 
 use DBI; 
 
       $sqlstatement= "select Name from Protein;"; 
 
    #open connection to Access database 
    $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=C:\Perl\eg\db1.mdb'); 
 
    #prepare and execute SQL statement 
 
    $sth = $dbh->prepare($sqlstatement); 
    $sth->execute || 
    die "Could not execute SQL statement ... maybe invalid?"; 
 
 
    #output database results 
 
    while ( $ref = $sth->fetchrow_hashref($Name) ) 
{
    print "$$ref{'Name'} \n";
}
 
 
$filename= 'C:/Perl/eg/members.txt';
open (FILE,$filename) or die $!;
while (<FILE>){
# split each input line; words are separated by whitespace
  for $word (split)
  {
   print $word . "\n";
  }
}
close (FILE);

The code now can only print the hash returned from the database
and split the txt into words.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

3. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

4. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Shell Programming and Scripting

extract whole thing in word, leaving behind last word. - perl

Hi, i've a string /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD/TESi T_11_HD_120/hd-12 i need to get string, like /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD the words from HD should get deleted, i need only a string till HD, i dont want to use any built in... (4 Replies)
Discussion started by: asak
4 Replies

7. Shell Programming and Scripting

perl hash - using a range as a hash key.

Hi, In Perl, is it possible to use a range of numbers with '..' as a key in a hash? Something in like: %hash = ( '768..1536' => '1G', '1537..2560' => '2G' ); That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies

8. UNIX for Advanced & Expert Users

Perl loop txt and check if a hash key

Hi, The task i have to do is to 1- create a database contains the Names .run the query and store results in hash make the Name field is the hash key 2- in the same time i have a txt which i will loop through it word by word and check for each word if a hash key ( compare it with the Names in... (0 Replies)
Discussion started by: eng_shimaa
0 Replies

9. Shell Programming and Scripting

key word parameter

cat shell_script.ksh x=$A y=$B export x export y echo $x echo $y when i am running this with a command ksh shell_script.ksh -A 10 -B 20 its not showing anything .... could you let me know how i can use key word type paramter (2 Replies)
Discussion started by: dr46014
2 Replies

10. Shell Programming and Scripting

Spell Check in MS Word using PERL OLE

Hi, I am trying automate couting number of spell and typo errors in MS Word document using perl script. In perl script, i am using Win32::OLE module of perl to read MS word document. Can anybody tell me are there any modules available in perl which can be imported into my script to... (0 Replies)
Discussion started by: 123an
0 Replies
Login or Register to Ask a Question
Tangram::Type::Hash::Scalar(3pm)			User Contributed Perl Documentation			  Tangram::Type::Hash::Scalar(3pm)

NAME
Tangram::Type/Hash/Scalar - map Perl hash of scalar keys and values SYNOPSIS
use Tangram::Core; use Tangram::Type/Hash/Scalar; # always $schema = Tangram::Schema->new( classes => { NaturalPerson => { fields => { flat_hash => { opinions => { table => 'NP_ops', key_sql => 'VARCHAR(10)', type => 'int', sql => 'NUMERIC(1)', }, lucky_numbers => 'int', # use defaults } DESCRIPTION
Maps references to a Perl hash. The persistent fields are grouped in a hash under the "flat_hash" key in the field hash. The hash may contain as keys and values only 'simple' scalars like integers, strings or real numbers. It may not contain references. For hashs of objects, see Tangram::Type::Hash::FromMany and Tangram::Type::Hash::FromOne. Tangram uses a table to save the state of the collection. The table has three columns, which contain * the id of the container object * the key of the element in the hash * the value of the element The field names are passed in a hash that associates a field name with a field descriptor. The field descriptor may be either a hash or a string. The hash uses the following fields: * key_type * key_sql * type * sql * table The optional fields "key_type" and "type" specify the key and value types of the hash. If the type is "string" Tangram quotes the values as they are passed to the database. Not specifying a "type" is exactly equivalent to specifying "string". Optional field "table" sets the name of the table that contains the elements. This defaults to 'C_F', where C is the class of the contain- ing object and F is the field name. The optional fields "key_sql" and "sql" specify the type that deploy() (see Tangram::Deploy) should use for the column containing the key and value of the hash. If this field is not present, the SQL type is derived from the "type" field: if "type" is "string" (or is absent) VARCHAR(255) is used; otherwise, the "type" field is interpreted as a SQL type. If the descriptor is a string, it is interpreted as the value of the "type" field and all the other fields take the default value. AUTHOR
This mapping was contributed by Gabor Herr <herr@iti.informatik.tu-darmstadt.de> perl v5.8.8 2006-03-29 Tangram::Type::Hash::Scalar(3pm)