Hi Tassilo, In article <[EMAIL PROTECTED]>, Tassilo Von Parseval wrote: > 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 ...;
I was so close! (I quoted the '>' but I left out the comma following.) > 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. This seems too confusing here for me (but I will add it to my save file for future reference.) > 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. I almost asked about this earlier - if a script can also write to itself. I wrote something to test it, but haven't had time to look up the seek functions, etc. I suppose this only makes sense in very limited situations (if at all)? Thanks! -K -- Kevin Pfeiffer International University Bremen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]