0

Could someone explain how to correctly reference the arrays @names and @numbers. Currently I am getting warnings saying that using @names->[$count] is deprecated. I've looked around and people said to do $names->[$count] however when I do this it says that $names / $numbers does not exist.

my $ldap = Lib::Phonebook->new();

my (@names, @numbers, $count, $name_number_count);

    @names             = $ldap->list_telephone_account_names();

    @numbers           = $ldap->list_telephone_account_numbers();

    $name_number_count = @names;

    $count = 0;

    for $count (0 .. $name_number_count) {
        print @names->[$count] . " -> " . @numbers->[$count] . "\n";
    }

1 Answer 1

2

@names is an array, so to access an element you would use $names[$index].

Also, iterating from 0 .. $name_number_count will take you over the end of the array. You want 0 through "the last element index in @names" which would be @names - 1 or $#names. So:

for my $count (0 .. $#names) {
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect thanks! just noticed I'm now getting this: Use of uninitialized value within @names in concatenation (.) is this as a result of using this or something unrelated? Just seen your edit, thanks a lot that's sorted it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.