in reply to creating a text file at run time and writing to it.
Notice the differences:#!/usr/bin/perl use strict; use warnings; open( NAMES, "<", "name.txt") or die $!; my @list = <NAMES>; close(NAMES); print "list = @list\n"; for my $name (@list) { open(OUT, ">", $name) or die $!; print OUT "hello"; close(OUT); }
Start with "use strict" and "use warnings" and that will be very helpful!1. use strict and use warnings; 2. use the "$!" so you get the explicit error when there is one 3. you didn't define $y - and it looks to be unnecessary for this 4. you didn't close the FILE handles 5. you need to specify the FILE handle you want to write to
Update: Oops, forgot the .txt part - see madtoperl's node.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: creating a text file at run time and writing to it.
by Anonymous Monk on Jul 20, 2006 at 11:33 UTC | |
|