in reply to file open with variables
open(DLOG, '<', "D:\\PROJ\\N12${X_info}_X$X_info\\dataInfo_X${Y_info}_ +Y${Z_info}_decode.csv") or die "we have a problem: $!"; # ^
Note that I needed to add the comma after the mode, it's not optional.
Also, a backslash is special in double quotes, so it needs to be backslashed to keep its literal meaning.
Moreover, a variable name can't be followed by an underscore (or any other character valid in a variable name) in double quotes, e.g. "$x_" means the variable named $x_, not $x followed by an underscore; you might need to use the curly braces syntax "${x}_".
Even better, use sprintf:
open(DLOG, '<', sprintf 'D:\PROJ\N12%s_X%s\dataInfo_X%s_Y%s_decode.csv +', $X_info, $X_info, $Y_info, $Z_info) or die "we have a problem: $!" +; # ~~ ~~ ~~ ~~
The usual rant about using lexical filehandles will come shortly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: file open with variables
by afoken (Chancellor) on Sep 27, 2022 at 17:15 UTC | |
|
Re^2: file open with variables
by eyepopslikeamosquito (Archbishop) on Sep 28, 2022 at 07:49 UTC |