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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-09-18 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls