Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Pass an object, a variable in an Array

by Chaoui05 (Scribe)
on May 26, 2016 at 14:21 UTC ( [id://1164197]=perlquestion: print w/replies, xml ) Need Help??

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

Hi everybody, I have a beginner question : How to add an object or a variable in an Array with Perl. I'am using Selenium::Screenshot package I have my Object here ..
my $white = Selenium::Screenshot->new( png => $driver->screenshot, exclude => [{ size => { width => 100, height => 100 }, # s +ize => $elem->get_size, location => { x => 5, y => 5 }, #location => $el +em->get_element_location, }] ); $white->save( file => "snapScreenshot-$browser" );
That i would like to retrieve in this Array. But i'am not sure it's well done ..?
$screenshots{$browser} = new Selenium::Screenshot;
Thanks
Lost in translation

Replies are listed 'Best First'.
Re: Pass an object, a variable in an Array
by stevieb (Canon) on May 26, 2016 at 14:50 UTC

    $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' ) };
      Thanks a lot ! Your approach is pretty good !
      Lost in translation

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found