BlueLines has asked for the wisdom of the Perl Monks concerning the following question:
This code produces no output untill i add a close FOO; in &foo. However, the following code does work:#!/usr/bin/perl -wT use strict; sub foo { open(FOO, '>/tmp/foo') or die "$!\n"; print FOO "this is a test\n"; } sub bar { open (BAR, '/tmp/foo') or die "$!\n"; while (<BAR>) { print; } } foo(); bar();
So what's going on here? Why can't I open the same file with two different modes when I can open the same file in the same mode? And why doesn't the second open barf? I tried this in linux under both 5.00053 and 5.6 and got the same results.#!/usr/bin/perl -Tw use strict; sub foo { open(FOO, '/tmp/foo') or die "$!\n"; while (<FOO>) { print; } } sub bar { open (BAR, '/tmp/foo') or die "$!\n"; while (<BAR>) { print; } } foo(); bar();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected behavior with open
by merlyn (Sage) on Apr 14, 2001 at 06:02 UTC | |
by Anonymous Monk on Apr 14, 2001 at 06:23 UTC | |
by merlyn (Sage) on Apr 14, 2001 at 07:54 UTC | |
|
Re: Unexpected behavior with open
by Dominus (Parson) on Apr 14, 2001 at 09:28 UTC | |
|
Re: Unexpected behavior with open
by BlueLines (Hermit) on Apr 14, 2001 at 07:39 UTC | |
|
Re: Unexpected behavior with open
by kha0z (Scribe) on Apr 14, 2001 at 08:06 UTC | |
by tilly (Archbishop) on Apr 16, 2001 at 04:37 UTC |