princepawn has asked for the wisdom of the Perl Monks concerning the following question:

[tbone@horse1 200716-007]$ perl ../delivered-list.pl > delivered-list. +dat UNIX at ../delivered-list.pl line 12. WIN32 at ../delivered-list.pl line 16. IMP_6.rpt at ../delivered-list.pl line 20. Syn5.rpt at ../delivered-list.pl line 20, <M> line 8554. SynOne.rpt at ../delivered-list.pl line 20, <M> line 40689. [tbone@horse1 200716-007]$
The warn at line 20 in my program prints  <M> on its last 2 invocations, but not its first... why did this happen. Here is my program:
use diagnostics; use String::Strip; my @unix_file = 'churn-list.dat'; my @ms_file = <*.rpt>; warn "UNIX"; `cat $_` for (@unix_file); warn "WIN32"; for (@ms_file) { warn $_; proc_ms($_); } sub proc_ms { my $file = shift; open (M, "tail +3 $_ |") or die $!; while (<M>) { last if /^\s*$/; # the line before X rows affected my ($id, $email) = split; StripTSpace($email); print "$id\t$email\n"; } }

Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Replies are listed 'Best First'.
Re: A slight variation in warn output... why?
by mpeppler (Vicar) on Jul 30, 2003 at 17:59 UTC
    To add a little to the previous comment - in proc_ms() you open the M file handle, but you never close it.

    If you have an open file handle when calling warn (or die) you will get this extra information (i.e. which was the last line read from the file).

    Michael

Re: A slight variation in warn output... why?
by dreadpiratepeter (Priest) on Jul 30, 2003 at 17:44 UTC
    It looks to me like the file hadn't been opened yet in the first invocation, so M doesn't exist.

    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
      open (M, "tail +3 $_ |") or die $!; # Do you mean $file instead of $_ here?
      Update: I know it doesn't look like it should make much difference, but might as well rule out a possible scoping issue with $_ first. Speaking of scoping, I meant to reply to the OP. Oh well.

      --isotope