Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Do you know where your variables are?
 
PerlMonks  

Re: Automatic generation of textfiles

by idle (Friar)
on Feb 03, 2006 at 08:31 UTC ( [id://527628]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 08: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 08: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 ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527628]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.