Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

help on hashes

by Anonymous Monk
on May 12, 2003 at 13:28 UTC ( [id://257420]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hey everyone , I would need some of ur expertise on hash arrays , this is what i anm doing below ,
my @rows; foreach $Old_URL (@Old_URL) { chomp $Old_URL; @rows = ED::database->execute_query("select new_url from convertedUR +L where old_url = 'http://www.ed.gov/PressReleases/01-20 03/index.html'"); $rowcount = @rows; } print "\n"; foreach $row (%rows) { print keys($row); } print "\n"; print "\n";
can someone help me how to print out the array , thank you

edited: Mon May 12 13:34:19 2003 by jeffa - code tags

Replies are listed 'Best First'.
Re: help on hashes
by dragonchild (Archbishop) on May 12, 2003 at 13:46 UTC
    First off, put use strict; at the top of your script and try again. You'll immediately find out that the hash %rows is not defined. You also never assign to it. Please read the Llama or Camel book and do their examples. That will help you out tremendously.

    Note - $rows, @rows, %rows - they are all separate variables. For all practical purposes, all they share is a name.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: help on hashes
by George_Sherston (Vicar) on May 12, 2003 at 14:44 UTC
    For printing out the contents of any data structure you'll find Data::Dumper a delight. Feed it your data structure as a reference and you're off to the races:
    use Data::Dumper; print Dumper(\@rows);


    § George Sherston
Re: help on hashes
by zby (Vicar) on May 12, 2003 at 13:48 UTC
    It all depends on what the ED::database->execute_query subroutine returns. If it does really return a list of hashes than to print it you can do following:
    for $row (@rows){ for $key (keys %{$row}){ print "$key: $row->{$key}\n"; } }
    The hash %rows in your code is undefined when you use it so your code does not print enything (if you don't define it somewhere else).

    Update Added keys for extracting keys - thanks to edoc.

      You might want to test your code before posting.. try this instead..

      foreach my $row (@rows){ foreach my $key (keys %$row){ print "$key: $row->{$key}\n"; } }
        thanks a bunch , this did it work , great help , the code that i pasted was a very quick one and i was playing around with the last three lines in my code ,and i just pasted what i had so that you guys could get a idea of where i was heading , but really thanks alot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://257420]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found