SirDonkeyPunch has asked for the wisdom of the Perl Monks concerning the following question:
so what im trying to do is open up 4 files, whether they exist or not, and put in a scalar string into each. i encounter the error "Can't use string (">poo.txt") as a subroutine ref while "strict refs" in use at ./2.pl line 12. " i have tried to call on to qw() with the FILE1, FILE2, etc etc within and calling the array index to the filename but then i get the same error only instead of >poo.txt its FILE1
#!/usr/bin/perl use strict; my $scalar = "We Be Killing Zombies Tonite"; my @array = (">poo.txt", ">moo.txt", ">doo.txt". ">goo.txt"); open(FILE1, $array[0]) or die "uno problemo"; open(FILE2, $array[1]); open(FILE3, $array[2]); open(FILE4, $array[3]); foreach(@array){ print $array[$_] ("$scalar"); }
im not looking for a blunt answer to just fix the problem and move on with my programming exercises, id like to learn why this doesnt work, so i can better understand how i can fix a problem like this in the future.. thanks for all your help guys!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Output To File with Array help
by ikegami (Patriarch) on Aug 19, 2009 at 18:06 UTC | |
by SirDonkeyPunch (Novice) on Aug 19, 2009 at 18:11 UTC | |
by markkawika (Monk) on Aug 19, 2009 at 18:26 UTC | |
| |
by ikegami (Patriarch) on Aug 19, 2009 at 18:13 UTC | |
|
Re: Output To File with Array help
by jwkrahn (Abbot) on Aug 19, 2009 at 18:09 UTC | |
|
Re: Output To File with Array help
by markkawika (Monk) on Aug 19, 2009 at 18:24 UTC |