Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: (dkubb) Re: (2) Split

by sierrathedog04 (Hermit)
on Feb 14, 2001 at 15:30 UTC ( #58324=note: print w/replies, xml ) Need Help??

in reply to (dkubb) Re: (2) Split
in thread How do I use Split

I ran this and it works, but I am not sure I understand why.
  1. 'd+' is one or more digits. The 'g' option causes the regex to find all greedy matches of d+, which is, say, '2001', '02' and '14'.
  2. The regex returns a list of these finds.
  3. 'shift =~' causes the regex to read as input the first parameter sent to the changedate function.
  4. join and reverse are as usual.
  5. Finally, even though there is no explicit return in the sub, it by default returns the last value calculated, which is the the value returned by join.
Wow! Is Perl powerful or what? I am in awe of Larry and the Perl 5 Porters who wrote it.

Replies are listed 'Best First'.
Re: Re: (dkubb) Re: (2) Split
by mikfire (Deacon) on Feb 14, 2001 at 19:57 UTC
    I promise this will be the last "clarification" I make in this thread.

    You are close. You are very close. I would make these notes

    1. The 'g' option causes a global match - ie, find them all
    2. The regex, in this case, returns the list of all matches. In other cases, it will return how many matches were found. The difference is the context in which it is used. Since reverse() expects a list, it forces the regex to be evaluated in list context and, hence, returns the list.
    In a clarifying mood,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-06-05 19:55 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (40 votes). Check out past polls.