Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 meditating upon the Monastery: (3)
As of 2015-03-01 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    On my keyboard, Caps lock is:








    Results (466 votes), past polls