in reply to Formatting variables

>
crmr_5 Read access to business unit 5 crmw_3 Write access to business unit 3 crmn_1 Read and write notes access...

looks like a nested structure to me, TIMTOWTDI

either

$cmr_access{r}[5]

or

$cmr_access[5]{r}

or

use constant { NOTE=>0,READ=>1,WRITE=>2 }; $cmr_access[5][READ]

it really depends on the use case

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Formatting variables
by Bod (Parson) on Nov 29, 2020 at 13:46 UTC

    looks like a nested structure to me, TIMTOWTDI

    These are actually HTML form element names, not Perl variables but they are dynamically generated by a Perl script like so:

    $query=$dbh->prepare("SELECT idBusiness,emaillist,private,name,title,d +escription FROM Business ORDER BY metric"); $query->execute(); while (($id,$em,$private,$text,$title,$desc)=$query->fetchrow_array()) + { $list_color=$em?'black':'slategray'; ($chk, $sub, $crm, $warmth)=$dbh->selectrow_array("SELECT Business +_idBusiness, subscribe, CRMaccess, warmth FROM Business_has_Contact W +HERE Business_idBusiness = $id AND Contact_idContact = $data{'contact +'}"); if ($chk) { $check=' checked'; $dis=''; } else { $check=''; $dis=' disabled'; } $warmth = 0 unless $warmth; $crmr_chk = $crmw_chk = ''; $crmr_chk = ' checked' if $crm; $crmw_chk = ' checked' if $crm eq 'W'; $subscribe=$sub?' checked':''; $text="<i>$text</i> <span class=\"privatelist\">[private]</span>" +if $private; print "<tr>\n<td><input type=\"checkbox\" name=\"bus_$id\" onChang +e=\"subscribe(this,$id);\"$check>\n"; print "<input type=\"checkbox\" name=\"sub_$id\"$subscribe$dis></t +d>\n"; print "<td title=\"$title\" style=\"color:$list_color\">$text</td> +\n"; print "<td style=\"text-align:center\"><input type=\"checkbox\" na +me=\"crmr_$id\" onClick=\"crmAccess(this, $id);\"$crmr_chk>\n"; print "<input type=\"checkbox\" name=\"crmw_$id\" onClick=\"crmAcc +ess(this, $id);\"$crmw_chk></td>\n"; print "<td><img src=\"/images/site/warmth$warmth.png\" style=\"wid +th:28px\"> </td>\n" if $chk; print "</tr>"; }
    This is part of a 4500+ line script that was originally written a long time ago and has been added to and modified lots over the years. Hence lack of white space and other poor legibility on some of the older bits of code. Nowadays I insert spaces either side of = and a space after a comma.

      Please don't be offended, but after looking at your code I'd really appreciate if you stopped complaining about the way this site was implemented.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Please don't be offended

        I'm not :)

        The bulk of that code sample was written somewhere between 8 and 10 years ago...perhaps I should really go back and tidy/improve it so that is closer to my current standards. I am sure current standards are nothing like the quality of many here but coding for me is a sideline - it is not my profession. I code partly for enjoyment but mostly to create tools for the company I run which has nothing to do with IT.

        I was once told that everyone should look back at code they wrote years ago and see something poor - that way they know they are making progress...kind of makes sense to me...