Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Non-regex Methods of Extracting the Last Field from a Record

by AnomalousMonk (Archbishop)
on May 08, 2009 at 00:20 UTC ( [id://762727]=note: print w/replies, xml ) Need Help??


in reply to Non-regex Methods of Extracting the Last Field from a Record

How about:
>perl -wMstrict -le "my $str = 'a b c d e 96'; my $last_field = (split / /, $str)[-1]; print qq{'$last_field'}; " '96'
... the primary question is why doesn't the following construct work:
 (@junk, $ads) = (split(/\s+/, $rec));
Because the  @junk array 'consumes' all elements of the list produced by the split built-in, leaving nothing but undefinedness for the  $ads scalar.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-24 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found