On Sun, Jun 01, 2003 at 11:22:32AM +0200 Kevin Pfeiffer wrote: > More problems trying to use constants... > > I have: > > use constant CFG => qq|$ENV{'HOME'}/.get_quiz|; > > > But I can't see how to make this work: > > open DATA, "> CFG" or die "Couldn't open ", CFG, " for writing: $!\n"; > > With quote marks it creates a new file in the pwd called "CFG". (Maybe it's > time to get the Programming Perl book?)
A constant neither has the $ nor @ sigil in front so it wont interpolate in strings. Oddly enough you did the right thing in the 'or die' string. The second argument to open() is not different: It's just a string. To get around that, you can use the three-argument form of open(): open DATA, ">", CFG or die ...; if your Perl is recent enough (>= 5.6.0). Or you use the interpolate-anything trick: open DATA, ">@{[ CFG ]}" or die ...; The part between @{[ ]} is arbitry Perl-code that is executed in list context and the last expression evaluated in this Perl code is what gets eventually printed. Btw: You probably shouldn't use the DATA handle. It's special in that it refers to anything that follows the __DATA__ or __END__ token in your scripts. It even is seekable so you can write a script that prints itself with the help of this filehandle. Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]