First off, check out 'perldoc -f split'.  That will get you the man page.
This works for all built-in functions.  But here goes:

split() is used to split up a string using a delimiter that you specify.
The basic syntax is this:

   split(/patternToMatch/,$stringToSplit,$numberOfElements);

The first argument is the pattern to look for, the second argument is the
string to split, and the third, optional argument is the maximum number of
elements in the list you will be returning.  It returns the list created by
splitting on your delimiter.  For example, lets say you have a simple list
stored in memory that you want to append the letter 'Z' to.  You can't use
the list in its current format, though, because it is stored in the scalar
$string that looks like this:  "letter,word,file,apple".  You can use split
to create an array out of the elements.

  use strict;
  my($string,@list,$item);
  $string = "letter,word,file,apple";
  @list = split(/,/,$string); #split by commas
  foreach $item(@list){
    $item .= 'Z';
  }

Now we have an array, @list, that contains "letterZ","wordZ","fileZ",and
"appleZ", one per element.  Play with it a little and you'll see how it can
be very useful.  


-----Original Message-----
From: Teresa Raymond
To: Perl Beginners List
Sent: 6/14/02 7:21 PM
Subject: Re: SPLIT - What is it?

>Can someone explain to me what the purpose of split is?   I am assuming
you
>can take like a text file or something and separate it out?
>
>Thanks
>Mike
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]


-- 
-------------------------------
-  Teresa Raymond             -
-  Mariposa Net               -
-  http://www.mariposanet.com -
-------------------------------

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to