topical media & game development

talk show tell print

basic-regex-26-SplitDemo.pl / pl



  #!/usr/bin/perl -w
  use strict;
  my myTestString = "A, B, C, D";
  print "The original string was 'myTestString'.\n";
  my @myArray = split/,\s?/, myTestString;
  print "The string has been split into four array elements:\n";
  print "myArray[0]\n";
  print "myArray[1]\n";
  print "myArray[2]\n";
  print "myArray[3]\n";
  print "Displaying array elements using the 'foreach' statement:\n";
  foreach my mySplit (split/,\s?/, myTestString)
  {
   print "mySplit\n";
  }


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.