Very fortunately some people have a penchant/ inclination to open every odd can of worms that happen to be on this planet. It greatly helps to get rid of one's ignorance.
I would use the code Larry posted if it is three values being stored in three scalars, to me that seems like the "best" way for that particular requirement.
Fair enough but what is the reason to initialize three separate variables $first, $mid and $last; especially when we can use special variables $1, $2 and $3 ----.
Further, the code posted by ichi appears to be more general than Larry's code and hence you should have preferred it; if you say you prefer Larry's code sure you must be having some strong reasons for that What are they?
Regular expressions or used to look for patterns. Patterns could be something like:
several digits followed by several lower-case characters then several upper-case characters. But the pattern could vary although it sticks to that basic formula. For that you would use a regexp:
but in this situation were are not looking for patterns, we are splitting a string/line into tokens (a list or array) using an established delimiter. For that you use the split() function. If the fields are fixed-length you would want to use unpack() which is more efficient than split().
I appreciate that you want to understand the "why" of things. But it is also very time consuming to try and explain all the reason why some code is better than other code, and sometimes I frankly don't know why. I often defer to people that I get information from, like Damien Conway, or Brian Defoy, two very respected perl people, and if they say one way is better than another I take their word for it until its proved otherwise.
(This post was edited by KevinR on Jun 30, 2009, 11:23 AM)