Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Printing Last Element of a line using perl memory?

by LanX (Canon)
on Feb 15, 2013 at 09:42 UTC ( #1018871=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: Printing Last Element of a line using perl memory?
Download Code
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018871]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-07-06 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls