#!/usr/bin/perl $input_data = "john:mary:jenny:steve"; @my_list = split /:/, $input_data; foreach (@my_list) { print "$_\n"; } while (<>) { @my_list = split; # equivalent to: @my_list = split /\s+/ $_; foreach (@my_list) { print "$_\n"; } } @new_list = split//, $input_data; foreach (@new_list) { print "$_\n"; } # ----- $long = "this is a great discussion"; $location = index($long,"great"); # 10 print "Location is: $location\n"; $where = 0; while ($where != -1) { $where = index($long,"is", $where + 1); print "Locations are: $where\n"; } # ----- $middle = substr($long,5,8); print "$middle\n"; # replace a substring substr($long,5,2) = "used to be"; print "$long\n"; # ----- # store names pointing to ages my %this_hash = ("arnold", 8, "willis", 10, "kimberly", 12); # alternate, "Big Arrow" notation: %this_hash = ( "arnold" => 8, "willis" => 10, "kimberly" => 12, # trailing comma not needed, but uniform ); # ----- # Note that the value is a scalar, necessitating the $ print "The age of Willis is $this_hash{'willis'}\n"; $housekeeper = 'edna'; # adding element $this_hash{$housekeeper} = 50; # kimberly's age changed: $this_hash{'kimberly'} = 13; # ----- print "\nNew (unsorted) looping method\n"; while ( ($key, $value) = each %this_hash ) { print "$key is $value years old\n"; }