Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

split and join

by root (Scribe)
on Nov 12, 1999 at 02:46 UTC ( #970=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $line="Bart  Lisa Maggie Marge Homer";
    @simpsons=split(/\s/, $line); #splits $line and uses a piece of whites
    +pace as a delimiter.
    ...
    
    @simpsons=split(/\s+/ $line); #now splits $line on 1 or more whitespac
    +e characters
    #@simpsons now containts ("Bart","Lisa","Maggie","Marge","Homer");
    
  2. or download this
    open FILE, "data.txt";
    while(<FILE>)
    ...
       print "Address: $address\n\n";
    }
    close FILE;
    
  3. or download this
    $string=join(" ",@simpsons);
      #string now equals "Bart Lisa Maggie Marge Homer";
    ...
    $address="42 Tulip Lane, Holland MI, 49423";
    $string=join("|",$name,$phone,$address);
    #$string is now equal to "Bob|555-5555|42 Tulip Lane, Holland MI, 4942
    +3"
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://970]
help
Chatterbox?
[shmem]: hmm.. which makes emerge the question: is there a way to attach a subroutine to a variable, which is run as soon as that variable changes?
[moritz]: through a tie?
[shmem]: moritz: of course!
shmem slaps forehead m(
[shmem]: consider, then, @CBMonks as a tied variable which triggers withdrawing empty cups and serving new ones
[GotToBTru]: it's always teatime somewhere

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-04-24 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (439 votes). Check out past polls.