Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!csn!boulder!spot.Colorado.EDU!knodel From: knodel@news.colorado.edu (KNODEL DAVID) Newsgroups: comp.lang.perl Subject: using contents of a scalar variable as a variable name Summary: what's the best way to use a scalar's contents as a variable name? Message-ID: Date: 11 Apr 91 23:32:57 GMT Sender: news@colorado.edu (The Daily Planet) Reply-To: knodel@spot.Colorado.EDU Organization: University of Colorado, Boulder Lines: 21 Nntp-Posting-Host: spot.colorado.edu In a perl application I am writing, I would find it extremely useful to reference variables whose names are stored in an array. The only way which consistently worked was to use an eval statement. For example, if I have an array: @names=("john","joe","paul"); and I want to assign values to the variables whose names appear in the array (in this case, $john, $joe, and $paul). I found that I could reference them via an eval statement, like: print eval("\$$names[0]"); but assigning to them via this method was a little gross: eval("\$$names[0] = \"something\"); Is there a better way to reference these variables? Thanks, David (knodel@spot.Colorado.EDU)