in reply to Blank File

Maybe it's just me, but your use of split() is a little unusual:      ... = split(m#\|# => $_, -1); It's not entirely clear why you're using the arrow '=>' operator in there when a comma should do just fine. Also, including a negative number as a parameter seems to request the default behaviour, so it seems redundant and misleading.      ... = split(m#\|#); Since you're using $_ anyway, and the default behaviour, you should be able to reference split as such.

With respect to your curious problem, it's not clear why reorganizing the statements would cause the program to start "working" all of a sudden, but you could certainly avoid using concatenation and use the list method of print instead:     print THIRD $_->[0],$id,"|",$key,"|",$cols[0],"|",$_->[0],"\n"; That would seem to be functionally equivalent, and more presentable.

Replies are listed 'Best First'.
split,,-1 (Re: Blank File)
by tye (Sage) on Jan 25, 2001 at 23:47 UTC

    Specifying -1 as the third argument to split causes it to not discard trailing empty results, which is not the default behavior.

            - tye (but my friends call me "Tye")
      True, but the presence or absence of '-1' as a paremeter as used in that program would have no effect, correct? If I understand the documentation correctly, the '-1' is important in very specific circumstances, such as using pop():
      my ($a) = "the|sneaky|camel||"; my (@b, $nil); # Try different parameters with split and report for my $p (undef, -1) { @b = split (/\|/, $a, $p); ($nil) = pop (@b); print "split() with '$p': '$nil' should be empty, ", (length($nil)?" but isn't":"and is"),".\n"; }
      You learn something new every day, it seems.