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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.