ThirtySecondNoob has asked for the wisdom of the Perl Monks concerning the following question:
I've been having some trouble managing with filehandlers - specifically with an if statement and putting in a line of data into files. I want to dynamically name my files with date stamps from the data lines I'm getting. So far, I've been trying to use *typeglob variables with filehandlers.
I know there's an error in the code, but what I want is to find a better way of dynamically naming my files. I found some information on dereferencing filehandlers, but I don't know how to implement that in this case. Does anyone have any suggestions?
while(1) { #get line of code $new_line #get line's date stamp $line_time #if file doesnt exist create it if (! -e $DATA_DIRECTORY.$filename.".ascii") { if (tell(CURRENT_FILE) != -1) {$file = $fileholder[0]; close CURRENT_FILE; } else {print "File cant be closed bc hasnt been made yet\n";} #open this file open(CURRENT_FILE, ">>$DATA_DIRECTORY".$line_time.".ascii") || print "$line_time.ascii could not be created\n"; $fileholder[0] = *CURRENT_FILE; $file = $fileholder[0]; #add line to $NEW_FILE print $file $new_line."\n" || print "data COULDNT be printed to CURR +ENT_FILE\n"; } else { #write to file and send $file = $fileholder[0]; print $file $new_line; #need a typeglob or it wont print b/c CURRENT +_FILE is local } } #end of while loop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamic filehandlers - how to deal?
by jethro (Monsignor) on Oct 08, 2010 at 01:12 UTC | |
by ThirtySecondNoob (Novice) on Oct 08, 2010 at 17:12 UTC | |
|
Re: dynamic filehandlers - how to deal?
by aquarium (Curate) on Oct 08, 2010 at 03:38 UTC | |
|
Re: dynamic filehandlers - how to deal?
by roboticus (Chancellor) on Oct 08, 2010 at 12:26 UTC |