The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 4 03-28-2009 04:10 PM
Perl Newbie - help! Khoomfire Shell Programming and Scripting 1 04-24-2008 03:43 PM
perl newbie: how to extract an unknown word from a string wolwy_pete Shell Programming and Scripting 3 03-23-2008 10:41 AM
Newbie question peeyush_23 Shell Programming and Scripting 9 02-18-2005 06:39 PM
newbie question ninja UNIX for Dummies Questions & Answers 3 07-11-2001 05:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-05-2006
ssmiths001 ssmiths001 is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 41
Perl newbie question

Can someone tell me what this is doing? I know it is reading records from a table and puts them in a hash. How do I print out, let's say, the first 5 columns of data (assuming columns are named col1, col2, ...)?

Code:
    $sth = $dbh->prepare("select *
                          from stsc.loc
                          where p_loclevel = 4 and rownum < 11");
    $sth->execute();
    while (my $hash_ref = $sth->fetchrow_hashref('NAME_lc'))
    {
        $dlrinfo{$hash_ref->{loc}} = \%$hash_ref;
        $dlrcount++;
    }
  #2 (permalink)  
Old 05-05-2006
buffoonix buffoonix is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 145
perldoc DBI
will tell you ;-)
But to be of little more help,
it's been quite a while since I last have written Perl code that used the DBI.
Thus it's likely I forgotten most of DBI.
But if I remember correctly,
the fetched hash'es keys are the field names of the table items
that you prepared in your select statement.
Since NAME_lc is passed you can safely reference the keys all lower case.
Hint, in Oracle's sqlplus you could issue a desc on the table you select
to see the field names.
Once the result set is fetched in your hashref it's very easy to refer to the fields
thanks to Perl's arrow operator.
Since I don't know you table's fields I use field_N here.
e.g.
Code:
my $field_1 = $hash_ref->{field_1};
my $field_5 = $hash_ref->{field_5};
But you could also reference them collectively by a hash slice.
e.g.
Code:
my ($field_2, $field_7, $field_3) = @{$hash_ref}{qw(field_2 field_7 field_3)};
But admittedly, this looks rather ugly,
and referencing like this gave Perl the reputation of line noise and obfuscation.
  #3 (permalink)  
Old 05-08-2006
ssmiths001 ssmiths001 is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 41
Thanks for the info
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0