Dear monks,
I am still struggling with sub routines. I have used a dummy variable again to see where my code is failing and it seems to fail at the end of my sub routine events. Why is it doing this? I tried using last, next, and until functions but these do not seem to fix the error
use strict; use warnings; my $fin = "SELECTDAT2"; my $fout = "myfile"; open my $ih, '<', $fin or die "cannot open $fin for reading, $!"; open my $oh, '>', $fout or die "cannot open $fout for writing, $!"; sub events { my @tokens = split; my @list = @tokens[0,3,4,7,8]; push @list; } while (<$ih>) { chomp; my @tokens = split; my @records = @tokens [3,4,5,6,10,11]; push @records; my $y = $tokens[0]; my $m = $tokens[1]; my $d = $tokens[2]; my $h = $tokens[3]; events; last; } print $oh events, "\n", @$_ for sort {$a->[3] <=> $b->[3]} @records; close ($oh); close ($ih);
In reply to Sub routines by velocitymodel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |