in reply to Automatic generation of textfiles

You can use exec or system: exec(':> $filename'); But be careful.

Replies are listed 'Best First'.
Re^2: Automatic generation of textfiles
by Fletch (Bishop) on Feb 03, 2006 at 13:35 UTC

    While it's possible in shells to use exec to reopen descriptors, Perl's exec is a different beast. You'll either replace your running program with a very short lived shell, or you'll spawn a child shell which won't affect the parent process' file descriptors in any way.

      Maybe I get it wrong, but it seems to me that tamaguchi asked how to create files, not open.

        The example he gave was using shell redirection to capture the output of his script. And even so, it's overkill to spawn another shell when a simple { open( my $fh, ">", $newfile ) or die "open $newfile: $!\n" } would suffice.

        $ mkdir foo $ cd foo/ $ perl -e 'open F, ">bar"' $ ls bar
Re^2: Automatic generation of textfiles
by blazar (Canon) on Feb 03, 2006 at 13:47 UTC

    Huh?!? Low and behold I'd just point him to

    my %fh; open $fh{$_}, '>', $_ or die "Can't open `$_': $!\n" for @many_files; # if they're not TOO many ;-)