Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

split and join

by root (Monk)
on Nov 12, 1999 at 02:46 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found