G'day gayu_justin,

Firstly, this code is highly confusing and a potential source of errors:

my $check_ = "chck"; my $chck_ = "check";

Regarding the code generating the error, instead of:

foreach $usr( @ #print $usr . "\n"; #print $check_.$usr; my $check_.$usr = $cgi->param("$chck_.$usr"); print $chck_.$usr; }

I suspect you want something closer to this (untested):

for my $user_id (@userchecklist_id) { my $checkbox_name = "check_$user_id"; my $checkbox_value = $cgi->param($checkbox_name); print "Checkbox name: $checkbox_name\n"; print "Checkbox value: $checkbox_value\n"; }

By using meaningful variable names and taking a little care when laying out your code, you'll improve readability and maintainability. Take a look at perlstyle for some tips on the latter.

As a final point, note how you've reused $usr:

my $usr = $user->id; ... foreach $usr( @userchecklist_id) {

This, again, is a potential source of errors. Consider what might happen if you wanted to use the $user->id version of $usr after the loop. By using my when you start the loop (as I did) you get a different variable (scoped to the loop) and avoid possible future problems. [In case you didn't know, for and foreach are synonymous so you can save yourself some typing (see perlsyn - Foreach Loops).]

-- Ken


In reply to Re: showing the error ,Can't modify concatenation (.) or string in scalar assignment by kcott
in thread showing the error ,Can't modify concatenation (.) or string in scalar assignment by gayu_justin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.