velocitymodel has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sub routines
by davido (Cardinal) on Mar 30, 2011 at 05:41 UTC | |
by velocitymodel (Acolyte) on Mar 31, 2011 at 14:20 UTC | |
|
Re: Sub routines
by JavaFan (Canon) on Mar 30, 2011 at 08:13 UTC | |
|
Re: Sub routines
by wind (Priest) on Mar 30, 2011 at 05:56 UTC | |
by velocitymodel (Acolyte) on Mar 31, 2011 at 14:44 UTC | |
by wind (Priest) on Mar 31, 2011 at 15:16 UTC | |
by velocitymodel (Acolyte) on Mar 31, 2011 at 19:40 UTC | |
|
Re: Sub routines
by choroba (Cardinal) on Mar 31, 2011 at 08:48 UTC |