Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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: (8)
As of 2014-12-26 05:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (165 votes), past polls