![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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++;
}
|
|
||||
|
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};
e.g. Code:
my ($field_2, $field_7, $field_3) = @{$hash_ref}{qw(field_2 field_7 field_3)};
and referencing like this gave Perl the reputation of line noise and obfuscation. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|