?
Solved

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

Posted on 2004-09-13
1
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 200 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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

771 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