Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Re: packing/unpacking/split/join confusion

by pfaut (Priest)
on Jan 01, 2003 at 17:13 UTC ( #223593=note: print w/replies, xml ) Need Help??


in reply to Re: Re: packing/unpacking/split/join confusion
in thread packing/unpacking/split/join confusion

The first argument to split is a regex that describes the delimiters in the second argument. By specifying a space, you are telling split to break the string apart wherever it sees a space. So, split ' ',"A B C D" returns ('A','B','C','D'). If instead of space there were commas in your string, you could split ',',"A,B,C,D" instead. This would produce the same result.

--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Replies are listed 'Best First'.
Re: Re: Re: Re: packing/unpacking/split/join confusion
by sauoq (Abbot) on Jan 12, 2003 at 00:07 UTC
    By specifying a space, you are telling split to break the string apart wherever it sees a space.

    Almost. A literal space is a special case. It splits on whitespace like /\s+/ but it doesn't return a null field when there is leading whitespace. So, it is just like split with no arguments but it allows you to specify the variable instead of using $_.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://223593]
help
Chatterbox?
[marto]: Corion, pretty much. How are things? You were at LPW?
[Corion]: marto: Yep, but I didn't make it up north, sorry ;)
[Corion]: But LPW was enjoyable, even though it's always a bit hectic due to cramming everything into one day
[Corion]: I have no feeling about how my talk was received, but I'm happy with it, which counts the most to me ;-D
[Corion]: Also, London is always a nice visit, as I got to meet a friend there, and spent some time offline, working on "minor" features of the shadertoy thing ;)
[marto]: maybe next year when the kids are a little older I'll have time to attend perl events in Europe

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2016-12-07 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.