Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to cut strings from the end

by izut (Chaplain)
on May 30, 2006 at 13:25 UTC ( [id://552485]=note: print w/replies, xml ) Need Help??


in reply to Re: How to cut strings from the end
in thread How to cut strings from the end

Could you explain how this works? I was trying these days to dismiss the first element of an anonymous list, then I got this code:

(undef, @list) = split /\s+/, $str;
I was wondering if something like that could work, but it doesn't:
@list = (split /\s+/, $str)[1..$#a];
Thanks in advance.

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^3: How to cut strings from the end
by japhy (Canon) on May 30, 2006 at 14:05 UTC
    His code assumes @a is empty, which means $#a returns -1, so he's doing (...)[-1 - 2 .. -1] which is just (...)[-3 .. -1]. Your case cannot be handled in a similar manner -- you'd need to know the size of the list being returned by split(). Your first approach is fine.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found