$line="Bart Lisa Maggie Marge Homer";
@simpsons=split(/\s/, $line); #splits $line and uses a piece of whitespace as a delimiter.
#@simpsons now contains ("Bart","","Lisa","Maggie","Marge","Homer");
#notice there is an extra space between Bart and Lisa so we get an empty element in the array there.
#lets try a better delimiter that will eliminate that from happening
@simpsons=split(/\s+/ $line); #now splits $line on 1 or more whitespace characters
#@simpsons now containts ("Bart","Lisa","Maggie","Marge","Homer");
####
open FILE, "data.txt";
while()
chomp;
($name,$phone,$address)=split(/\|/); #splits the default variable $_ on |
#notice we have to put \| since | is a metacharacter
#that represents or. Otherwise we'd be matching
#empty string or empty string
#then we place the results in variables instead of a list
#the parentheses around the variable names need
#to be there for this to work properly
print "Name: $name\n"; #Now we print out the information in a more readable form
print "Phone Number: $phone\n";
print "Address: $address\n\n";
}
close FILE;
##
##
$string=join(" ",@simpsons);
#string now equals "Bart Lisa Maggie Marge Homer";
$name="Bob";
$phone="555-5555";
$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, 49423"