in reply to split function

Just a typo?

my $view = (split(/:/ , $setView))[1];

How about

use strict; use warnings;

Replies are listed 'Best First'.
Re^2: split function
by gimcdan (Acolyte) on Apr 28, 2015 at 13:44 UTC

    Not sure what "typo" but here is the entire subroutine. The perl program uses strict and warnings. Code runs produces desired output, I just don't understand why. Not my code just trying to understand the reference to and array element when I don't see an array element available?

    sub get_cc_view{ my @ccView = (); @ccView = (grep /Set view:/, @ccView)[0]; my $view = (split(/:/ , $setView))[1]; $view =~ s/\s//g; $CC_View = $view; $CC_View = "View: $CC_View"; }

    I understand all code except my $view = (split(/:/ , $setView))1

      I understand all code except my $view = (split(/:/ , $setView))1

      split returns a list, and a list, properly parenthesized, can be subscripted:

      c:\@Work\Perl\monks>perl -wMstrict -le "my $one = ('zero', 'uno', 'two')[1]; print qq{'$one'}; " 'uno'


      Give a man a fish:  <%-(-(-(-<

        Thanx Anamalous! Now it's perfectly clear. I am very new to perl and it's multitude of ways to accomplish tasks. And if I listen to co-workes, I should be learning javascript because perl is so passe`.