danmcb has asked for the wisdom of the Perl Monks concerning the following question:
I am using Net::Google::Analytics to grab stats from the goog.
The names of object accessors in the Row object are generated at runtime according to the parameters requested. So if you request the ga:pageviews metric, the row will have a method called get_pageview.
My code:
my @dimensions = qw/ page_path /; my @metrics = qw/ pageviews unique_pageviews avg_time_on_page entrance +s exits /; . . . (get the data into $res, this works fine) foreach my $r (@{ $res->rows }){ my @line; foreach my $get ( @dimensions, @metrics ){ my $get_method = "get_$get"; push @line, $r->{$get_method}->(); # this is wrong } push @report, join( "\t", @line); }
The difficulty I have is calling the method name. I get a "Not a HASH reference at ..." error.
Can you help please, oh holy ones? ;-)
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object get method as variable name
by blue_cowdawg (Monsignor) on Jan 09, 2013 at 19:39 UTC | |
|
Re: Object get method as variable name
by roboticus (Chancellor) on Jan 09, 2013 at 19:34 UTC |