How to initialize a referenced array?

How to initialize a referenced array?

am 25.09.2010 11:00:50 von feltra

Hi,

Am using arrays with only references in a sub-routine. While I got
the hang of how to access an element of the array using the '->'
operator, I do not know how to intialize this array. I.e. I want to
be able to do something like

@myarr=(); $#myarr = -1;

inside the subroutine, but myarr is only a reference to an array not
the actual array...

Hope the above problem description is clear.

If anyone knows how to do this, kindly help by posting the answer or
tell me where to look...

Thanks & Best Regards,
-feltra


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: How to initialize a referenced array?

am 26.09.2010 14:46:32 von Shlomi Fish

On Saturday 25 September 2010 11:00:50 feltra wrote:
> Hi,
>
> Am using arrays with only references in a sub-routine. While I got
> the hang of how to access an element of the array using the '->'
> operator, I do not know how to intialize this array. I.e. I want to
> be able to do something like
>
> @myarr=(); $#myarr = -1;
>
> inside the subroutine, but myarr is only a reference to an array not
> the actual array...

You can do something like:

sub my_subroutine
{
my ($array_ref) = @_;

@$array_ref = ();
$#{$array_ref} = -1;
}

Assuming this is what you meant by array reference. For more information see:

http://perl-begin.org/topics/references/

Regards,

Shlomi Fish

>
> Hope the above problem description is clear.
>
> If anyone knows how to do this, kindly help by posting the answer or
> tell me where to look...
>
> Thanks & Best Regards,
> -feltra

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
What does "Zionism" mean? - http://shlom.in/def-zionism

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: How to initialize a referenced array?

am 26.09.2010 19:14:37 von Jim Gibson

At 2:00 AM -0700 9/25/10, feltra wrote:
>Hi,
>
>Am using arrays with only references in a sub-routine. While I got
>the hang of how to access an element of the array using the '->'
>operator, I do not know how to intialize this array. I.e. I want to
>be able to do something like
>
>@myarr=(); $#myarr = -1;
>
>inside the subroutine, but myarr is only a reference to an array not
>the actual array...

[] is the notation for a reference to an array.

For example, if you want to initialize a scalar variable so that it
contains a reference to an anonymous, empty array, you would do this:

my $myarr = [];

You can initialize the array to contain data:

my $myarr = [ 'a', 'b', 'c' ];

or

my $myarr = [ qw( a b c) ];

To copy the contents of an array into an anonymous array and save a
reference to the anonymous array:

my $myarr = [ @other_array ];

Does that help?

--
Jim Gibson
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: How to initialize a referenced array?

am 26.09.2010 19:22:21 von Shlomi Fish

On Sunday 26 September 2010 19:14:37 Jim Gibson wrote:
> At 2:00 AM -0700 9/25/10, feltra wrote:
> >Hi,
> >
> >Am using arrays with only references in a sub-routine. While I got
> >the hang of how to access an element of the array using the '->'
> >operator, I do not know how to intialize this array. I.e. I want to
> >be able to do something like
> >
> >@myarr=(); $#myarr = -1;
> >
> >inside the subroutine, but myarr is only a reference to an array not
> >the actual array...
>
> [] is the notation for a reference to an array.
>
> For example, if you want to initialize a scalar variable so that it
> contains a reference to an anonymous, empty array, you would do this:
>
> my $myarr = [];
>

There is a difference between saying:

sub my_sub
{
my ($array_ref) = @_;

$array_ref = [];
}

And:

sub my_sub
{
my ($array_ref) = @_;

@{$array_ref} = ();
}

The first code does not modify the array referenced by the original reference
(which may be an anonymous one) while the second version does. I don't know
what the original poster wants, though.

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: How to initialize a referenced array?

am 26.09.2010 23:16:07 von jwkrahn

Jim Gibson wrote:
> At 2:00 AM -0700 9/25/10, feltra wrote:
>>
>> Am using arrays with only references in a sub-routine. While I got
>> the hang of how to access an element of the array using the '->'
>> operator, I do not know how to intialize this array. I.e. I want to
>> be able to do something like
>>
>> @myarr=(); $#myarr = -1;
>>
>> inside the subroutine, but myarr is only a reference to an array not
>> the actual array...
>
> [] is the notation for a reference to an array.

\@ is the notation for a reference to an array, [] is an anonymous array.


> For example, if you want to initialize a scalar variable so that it
> contains a reference to an anonymous, empty array, you would do this:
>
> my $myarr = [];
>
> You can initialize the array to contain data:
>
> my $myarr = [ 'a', 'b', 'c' ];
>
> or
>
> my $myarr = [ qw( a b c) ];
>
> To copy the contents of an array into an anonymous array and save a
> reference to the anonymous array:
>
> my $myarr = [ @other_array ];
>
> Does that help?

That is not relevant to the OP's question.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

WWW::selenium moudle function get_all_window_names return undef

am 27.09.2010 04:25:44 von JYang

--=====003_Dragon657766410763_=====
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit


Hi :


I have a testing project UI, and now click a hyperlink pop up new window ,so I want to operate the pop up window,I want to get the IE browser window's names or ids.But I use WWW:: selenium's function named get_all_window_names or get_all_window_ids ,they return array is null ,so I don't select pop-up new window using function select_window.
I need your help!
Thanks a lot!

2010-09-27



Best Regards!

-Yang

--=====003_Dragon657766410763_=====--