use strict; # Warns about mistakes (important) my @data; # Data storage variable my $filename = "data.dat"; # Filename constant # Open a handle to the specified file, or die with a # warning that it could not be done. open (DAT, $filename) || die "Could not open $filename\n"; # Now read through the contents of the file while () { chomp; # Removes trailing linefeed from input if ($_ eq "block") { # Put "block" into the two columns push (@{$data[0]}, $_); push (@{$data[1]}, $_); } elsif (/^\s*(\d+),(\d+)/) # Look for " nn,nn" { # The first group of digits, expressed as "\d+", # is 'memorized' as $1, with the second group as # $2 (and so on). \s* means "0 or more spaces" # and is not memorized (ignored) push (@{$data[0]}, $1); push (@{$data[1]}, $2); } else { # $. is the current input line (perldoc perlvar) print "Invalid input line $.\n"; } } close (DAT); #### for (my $i = 0; $i < @{$data[0]}; $i++) { print "$data[0][$i],$data[1][$i]\n"; }