Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day Steve, Welcome to the Monastery. Using the strict pragma is good; use it in all of your Perl code. You should also use the warnings pragma in all code. In this instance, I would also use the autodie pragma. Hand-crafting your own I/O exception messages is tedious and notoriously error-prone. In your code, the message won't tell you which file had a problem; compare with the output from my example code below, which I wrote to intentionally fail, but I didn't need to add 'or die "some message: $!"'. You need to start your variables with a sigil; e.g. $X_info instead of X_info. If you'd run your posted code, you would have been alerted to this. For future reference, please do basic checks on code before posting. From your question, I get the impression that you want to open different files based on the supplied variables. Use a subroutine to do this. See my code below for an example of this; the open function explains the preferred 3-argument form and use of a lexical filehandle. I wasn't certain exactly what replacements in the filename you wanted. I've just shown an example; modify to suit your needs. Also, I've used a single hash instead of three separate variables; that's just to show an alternative method which may, or may not, be useful for you.
For future use, consider creating an account. This is very easy to do and doesn't require you to provide lots of personal information; see "Create A New User". You gain a number of benefits and it differentiates your posts from all of the other anonymous posts (currently >100,000). — Ken In reply to Re: file open with variables
by kcott
|
|