develooper Front page | perl.beginners | Postings from January 2002

piping versus backticks

Thread Next
From:
Harvey Quamen
Date:
January 8, 2002 23:24
Subject:
piping versus backticks
Message ID:
a05100306b8619169eb73@[24.70.235.44]
Hello all:

I'm working my way through "Learning Perl" (3rd ed) and got stuck in 
ch 14 (Process Management, pages 201-202 actually, to be specific) 
where the "date" command is is opened through a filehandle with a 
piped open.  Just toying around to see how it worked, I put it in a 
loop and was surprised to see that it worked perfectly for the first 
iteration but then I got an error on every subsequent iteration:

Use of uninitialized value in concatenation (.) at line 11, <DATE> line 1.

Line 11 is the print line, but if I swap the filehandle with $now = 
`date` everything works great.


#!/usr/bin/perl -w
use strict;

my $now;

open DATE, "date|"
	or die "Darth Vader prevents me from piping from date: $!";

foreach (1..4) {
	$now = <DATE>;
	print "It's now $now\n";
	sleep (1 + rand 10);
}

close DATE;



I'm sure this is probably a simple, commonsensical thing but I got 
swamped in 'perldoc perlopentut' and 'man perlipc' and wasn't quite 
sure what keywords might help me find an answer.  By the way, I'm 
using Perl 5.6.0 on Mac OS 10.0.3.  And this is a great list, too, I 
should add.  I've learned a lot by lurking even though I haven't 
posted before.

Harvey Quamen

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About