http://www.perlmonks.org?node_id=1018871


in reply to Re: Printing Last Element of a line using perl memory?
in thread Printing Last Element of a line using perl memory?

> The pop takes the last word

Version warning! =)

not with < 5.14

DB<100> $_=join " ",a..z => "a b c d e f g h i j k l m n o p q r s t u v w x y z" DB<101> $x= pop [ split / / ] ;; Type of arg 1 to pop must be array (not anonymous list ([])) at (eval +20)[multi_perl5db.pl:644] line 2, at EOF DB<102> $x= pop @{[ split / / ]} # Workaround => "z"

Cheers Rolf

Replies are listed 'Best First'.
Re^3: Printing Last Element of a line using perl memory?
by pemungkah (Priest) on Mar 11, 2013 at 19:59 UTC
    Thanks! Filing that one.
      here a way to avoid a temp array

      DB<100> $_=join " ",a..z => "a b c d e f g h i j k l m n o p q r s t u v w x y z" DB<101> $x = (split / /)[-1] => "z"

      Cheers Rolf