Solved

Setting all fields in a hash to name/value from sql...

Posted on 2004-09-13
1
172 Views
Last Modified: 2013-12-25
Hi there,

I am just moving code from one server to another, where my current code uses the following syntax to get all the variables returning from the sql output (saves defining each time)....

                while( $hash =  $sth->fetchrow_hashref() )
                          {
                                           foreach( keys %$hash ){
                             $$_ = $hash->{$_}
                                 }

However now the server uses the folowing syntax, and I am not sure how to convert the statement above to "catch all" the output ......

      while (%hash = $sth->fetchhash)
      {
            $pagetemplate=$hash{'pagetemplate'};
            $fulltitledisplay=$hash{'fulltitle'};
            $pageviews=$hash{'pageviews'};
      }

can someone help me out please!
0
Comment
Question by:dreamshockDesign
1 Comment
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 50 total points
ID: 12044500
You're looking for:

while (%hash = $sth->fetchhash) {
  foreach (keys %hash) {
    $$_ = $hash{$_};
  }
}

The only difference here is that you're working with a hash and not a hash reference as in your first example.

Note that neither this nor your code above will work under strict, because you're creating variable variables on-the-fly as it were.

Hope this helps,

Tom
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article will show, step by step, how to integrate R code into a R Sweave document
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now