Walter asked: > How to find out, if the data from STDIN comes from a pipe or > from the keyboard? > > My script is called in two modes: > echo "[TEXT]" | smtp_send.pl ... > or > smtp_send.pl -message "[TEXT]" > > Inside the script, I read with: > while( $zeile = <> ) { > .... > } > > I need to check, if data comes from a pipe before enter the loop ...
1) The following works, but I would _not_ recommend it: use strict; use warnings; my $zeile = ARGV[1]; if(!$zeile) { while( $zeile = <> ) { .... } } 2) I would prefer to have the user use - to indicate input via pipe. So usage would be: [echo text] | smtp_send.pl - smtp_send.pl [-message=text] [echo some text] | smtp_send.pl - [-message=even more text] my @lines; for my $v (@ARGV) { if($v =~ /^-$/) { my @foo = <STDIN>; push @lines, @foo; } if($v =~ /-message=(.*)/) { push @lines, $1; } } chomp @lines; #process @lines; --Suresh _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs