Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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

by sulfericacid (Deacon)
on Jan 01, 2003 at 17:04 UTC ( #223591=note: print w/replies, xml ) Need Help??

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

Thanks, I pretty much understand all of that now :) You made everything seem a lot easier, thanks! I have a question though. Are you saying split ' ',$secret; somehow breaks a scalar into an array of different values? If that's what it is, I understand that part of it, but what does ' ' have anything to do with it?


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

  • Comment on Re: Re: packing/unpacking/split/join confusion

Replies are listed 'Best First'.
Re: Re: Re: packing/unpacking/split/join confusion
by pfaut (Priest) on Jan 01, 2003 at 17:13 UTC

    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';
      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 $_.

      "My two cents aren't worth a dime.";
Re: Re: Re: packing/unpacking/split/join confusion
by poj (Parson) on Jan 01, 2003 at 17:39 UTC
    I think what is confusing you is "Where are the spaces coming from ?"
    # If this is an array @a = ("A","B","C"); # then print "@a"; # result =A B C ie. all spaced out # # because as the Camel book says # Array variables are interpolated into double # quoted strings by joining all the elements # of the array with the delimiter specified # in the $" variable (which is space by default) # #This however print join ('',@a); # result =ABC


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://223591]
Discipulus fears to ears this in German..
[LanX]: missing for month
[LanX]: D : Oberbefehlshaber
[GotToBTru]: yeah, thats the story I remember. some card the President is supposed to carry around at all times
[GotToBTru]: I suppose the actual details about what is necessary to actually do something is kept fuzzy deliberately
[LanX]: the interview was with the guy who designed the process
[LanX]: in the 70s
[GotToBTru]: so the font on the card is probably NOT Comic Sans
[GotToBTru]: that's a relief

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-01-20 12:52 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.