in reply to Pass an object, a variable in an Array
$screenshots as depicted in $screenshots{$browser} is not an array, it's a hash. So you want to create a hash that contains all of the objects; is that correct?
Here's a very basic example of how you could do this, using a dummy package for testing (I know nothing of Selenium::Screenshot).
use warnings; use strict; use Data::Dumper; package Blah; sub new { my ($class, $browser) = @_; return bless {browser => $browser}, $class; } package main; # the example you're interested in is below my %screenshots; for my $browser ('ie', 'ff', 'chrome'){ $screenshots{$browser} = Blah->new($browser); } print Dumper \%screenshots;
Output:
$VAR1 = { 'ie' => bless( { 'browser' => 'ie' }, 'Blah' ), 'ff' => bless( { 'browser' => 'ff' }, 'Blah' ), 'chrome' => bless( { 'browser' => 'chrome' }, 'Blah' ) };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pass an object, a variable in an Array
by Chaoui05 (Scribe) on May 26, 2016 at 15:42 UTC |