On Wed, Nov 29, 2006 at 01:37:29PM -0800, Ravi Malghan wrote: > Hi: I have a variable called $agent_id and want to create a string with the > value of $agent_id followed by "-str". The following does not seem to work. > The following example I want to create a variable called $35-str. > > $agent_id = 25; > $agent_id."-str" = "This is test\n"; > > I get the following error. > bash-2.05$ ./test.1.pl > Can't modify concatenation (.) or string in scalar assignment at ./test.1.pl > line 14, near ""This is test\n";" > Execution of ./test.1.pl aborted due to compilation errors. > > Anyone have comments on how I can accomplish this?
Oops. Now you've gone and done it. Here are some comments for you: 1. Use a hash instead. 2. You can't start a variable name with a digit. 3. perl -e '$agent_id = 25; ${"$agent_id-str"} = "This is test\n"; print ${"25-str"}' 4. See http://perl.plover.com/varvarname.html 5. $agent_id += 10; -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>