PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "Scott Zetlan" <scottzetlan at aol dot com>
Subject: RE: Syb perl question
Date: Jan 16 2002 9:22PM

Also, depending on your Perl version (perl -v), the line:
print "$row->{$kv}\n";
will not do what you expect.  You'll see something like:
HASH=0xafde9f->{keyname}

where keyname is the value of $kv.  Instead, you need to do something tricky
like:
$rsds = $row->{$kv}; # no quotes in this line, so no interpolation problems
print "$rsds\n";

or (even trickier):

print "@{ [$row->{$kv}] }\n";

to get what you're after.

Scott

> -----Original Message-----
> From: owner-SYBPERL-L@list.cren.net
> [mailto:owner-SYBPERL-L@list.cren.net]On Behalf Of Michael Peppler
> Sent: Wednesday, January 16, 2002 4:04 PM
> To: SybPerl Discussion List
> Subject: Re: Syb perl question
>
>
> Sabherwal, Balvinder (MBS) writes:
>  > I have a code as
>  >
>  > foreach my $row (@$sysdb) {
>  >  my @cols = keys(%$row);
>  >  foreach my $kv (@cols) {
>  >      print "$kv";
>  >      if($kv eq "RSSD Dataserver"){
>  >          $rsds="$row->{$_}";
>  >          print "$row->{$_}";
>  >      }
>  >      else
>  >      {
>  >          $rsdb="$row->{$_}";
>  >          print "$row->{$_}";
>  >      }
>  >
>  >  }
>  > }
>  >
>  > after execution I am not getting the data values for the
> columns i.e. print
>  > "$row->{$_}"; returns blank. Am I missing something??
>
> Yeah :-)
>
> Use $row->{$kv} - $_ never gets set in your loop.
>
> Michael
> --
> Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
> mpeppler@peppler.org - mpeppler@mbay.net
> International Sybase User Group - http://www.isug.com
>
>