in reply to Interpolation in a hash key

So, every place you have a '1' in a hash key, simply substitute this (untested):

${count}

For example:

print<<"CONNECTION1"; <td valign="middle" align="center" width="78">$$hashRecordPtr{'connect +ion1_size1'} </td> CONNECTION1

... becomes ...

print<<"CONNECTION1"; <td valign="middle" align="center" width="78">$$hashRecordPtr{'connect +ion${count}_size${count}'} </td> CONNECTION1

That should do it, no? At a glance, it looks like all your $$hashRecordPtr references are inside double-quoted strings or HERE docs ...


No good deed goes unpunished. -- (attributed to) Oscar Wilde

Replies are listed 'Best First'.
Re^2: Interpolation in a hash key
by pickledegg (Novice) on Jun 13, 2006 at 16:26 UTC
    Right, the bits in HERE docs, work fine as shown:
    print<<"CONNECTION2"; <td width="78" align="center" valign="middle">$$hashRecordPtr{"connect +ion2_size$count"}</td> CONNECTION2

    But its just these bits now:(just a standard double quoted print statement)
    print "<td width=\"78\" align=\"center\" valign=\"middle\">$$hashRecordPtr{'part_number1'}</td>"; Any ideas on this last bit?

    Nearly there, thanks guys.

      So, in this last case, you've got a double-quoted string with a single-quoted substring. Interpolation rules indicate that a variable name inside the overall double-quoted string will still be resolved, so this should work (although it makes me nervous with all those backslashed double-quote characters):

      print "<td width=\"78\" align=\"center\" valign=\"middle\">$$hashRecor +dPtr{'part_number${count}'}</td>";

      Of course, I could be wrong -- you should try it out. :) When in doubt, I use the curly braces, because I think it makes it more readable and it has saved my bacon once or twice.


      No good deed goes unpunished. -- (attributed to) Oscar Wilde
        This doesn't work ptum, at least not for me
        I'll just put it in a HERE doc for now until I figure it out.