in reply to Help with argument to a subroutine

while (<STDIN>) { will always return true, since even if the line entered is empty, you will still get a \n from STDIN. So you need a different form of loop. Also, parse_header() needs the entire header passed to it - passing each line one at a time will just make many calls to parse_header(), only the last of which will have the full header.

What you need is something more like the following (assuming your data is coming in through STDIN - I haven't tested that part):

use strict; use warnings; my $header; while (1) { chomp($_ = <STDIN>); last if !$_; $header .= "$_\n"; } parse_header($header); sub parse_header { my $header = $_[0]; print $header; ## Do necessary $header processing }

Replies are listed 'Best First'.
Re^2: Help with argument to a subroutine
by unixhome (Novice) on May 15, 2006 at 19:22 UTC
    Ted: Sorry about that. I did not put it on my first posting but the first while loop already knows when to execute the sub (when $_ =~ /^$?/). You see, if I run both of those loops independantly from each other (piping the output of one to the second) as in: # cat header.eml | ./first_loop.pl | ./second_loop.pl It works. This is an excersise in Perl programming (with a real purpose...) and I cannot even say (Perl modules) out loud...
Re^2: Help with argument to a subroutine
by GrandFather (Saint) on May 15, 2006 at 19:11 UTC

    Or

    while (<STDIN>) { chomp; last if !$_; # or other suitable termination test $header .= "$_\n"; }

    DWIM is Perl's answer to Gödel