Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Output To File with Array help

by markkawika (Monk)
on Aug 19, 2009 at 18:24 UTC ( [id://789908]=note: print w/replies, xml ) Need Help??


in reply to Output To File with Array help

One of your problems is that you're attempting to print to a scalar value containing a string instead of a scalar value containing a file handle.

The first argument to print should be a file handle, not a string.

If you wanted to loop over an array of file handles and print the same output to each, you could try this:

use strict; my $scalar = "We Be Killing Zombies Tonite"; my @array = (">poo.txt", ">moo.txt", ">doo.txt", ">goo.txt"); my @filehandle; open($filehandle[0], $array[0]); open($filehandle[1], $array[1]); open($filehandle[2], $array[2]); open($filehandle[3], $array[3]); for my $fh (@filehandle) { print $fh "$scalar"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://789908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-09-18 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (24 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.