in reply to URL Redirect

Thank you! I am about to try it.

Question: what does the () in "my ($redirect) = $res->redirects;" do?

Replies are listed 'Best First'.
Re^2: URL Redirect
by Corion (Patriarch) on Sep 06, 2016 at 11:47 UTC

    HTTP::Response->redirects returns a list of redirects. You can either assign that list to an array or another list. The parentheses around $redirect tell Perl that you want $redirect to be seen as list as you in fact are only interested in the first redirect.

      I am still confused as to what
      my ( $NewUrl ) = $res->header('Location');
      exactly is.

      What exactly is "$res->header('Location')"? Is it a reference pointing to an array inside LWP?

      If I wanted to see the whole potato, why does
      my @Headres = @$res->header('Location')
      not work?

      How would I assign the whole potato to @Headers?

      I am confused.

      Many thanks,
      -T

        Maybe now is a good time to learn about Perl? See perlsyn for a basic overview of the syntax.

        $res->header('Location') is a call to the header method of whatever class $res is in. It passes one parameter with the value Location.

        While Perl has sigils and often these can be used in interesting ways, there are some restrictions on their use as you can't make things up and expect Perl to infer what you mean. Putting a @ before a reference, as in @$res tells Perl that you want to treat $res as an array. But, as Perl certainly has told you when you tried to run your code, $res does not behave like an array reference and hence Perl refused to do what you told it.