in reply to Re: Re: parsing/munging problems
in thread parsing/munging problems

It's good that you have a working version now. There are some things you could improve, though:

So an improved version of your sub would look like this:

sub indextime { my ($infile, $outfile) = @_; open my $in, '<', $infile or die "Couldn't open $infile for reading: + $!"; open my $out, '>', $outfile or die "Couldn't open $outfile for writi +ng: $!"; my @matrix; local $_; push @matrix, [split] while <$in>; my ($storenum, $date) = @{$matrix[0]}[0,1]; print $out "@{$matrix[$_]} $storenum $date\n" for 6..$#matrix-1; close $in or die $!; close $out or die $!; }

-- Hofmator

Replies are listed 'Best First'.
Re: parsing/munging problems
by nadadogg (Acolyte) on Feb 26, 2003 at 18:38 UTC
    The hard-coded filenames were only for the proof of concept so that i knew i could make it work. i am now using use:strict, and filenames pulled out of a separate array. I'm still using select statements for now because that's what I'm most comfortable with. Nadadogg
Re: Re: Re: Re: parsing/munging problems
by nadadogg (Acolyte) on Mar 04, 2003 at 22:52 UTC
    code looks good, ill probably use it a bit next subroutine rewrite. Of course, i wont use or die because the file may not exist in some directories if the polling doesnt go through for some stores.
      Of course, i wont use or die because the file may not exist in some directories
      The 'or die' idiom is just a reminder that the open might fail, something which should always be taken into account. The appropriate action, e.g. die-ing or ignoring, depends completely on your context ...

      -- Hofmator