Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Scaler found where opeartor expected Error

by mipatel (Novice)
on May 29, 2012 at 18:29 UTC ( #973086=perlquestion: print w/ replies, xml ) Need Help??
mipatel has asked for the wisdom of the Perl Monks concerning the following question:

hello, i am having trouble debugging this program could someone help me please

foreach $Author2 ( @author_order ) { $auth = $author_books{ $Author2 }; my $books = $auth->{order}; push @body, "<tr><td rowspan="${\scalar, @$books}"$Author2</td>\n" +; my $line = 0; foreach my $book ( @$books ) { push @body, '<tr><td></td>' if ++$line; push @body , ( "<td>$book</td><td>" . join( "<br/>\n", @{ $auth->{books}{ $book } } ) . "</td><tr>\n" ); } }

The error says Scalar found where operator expected at rough.pl line 43, near

<tr><td rowspan="$" (Missing operator before $?) String found where operator expected at rough.pl line 43, near "}"$Aut +hor2</td>\n"" (Missing operator before "$Author2</td>\n"?) syntax error at rough.pl line 43, near ""<tr><td rowspan="$"

Comment on Scaler found where opeartor expected Error
Select or Download Code
Re: Scaler found where opeartor expected Error
by muba (Priest) on May 29, 2012 at 18:36 UTC

    Does it say scaler found, scalar found, or string found?

    Let's pick that line apart, though, and see what's happening.

    push @body, # So far so good. We're gonna push something o +nto the array. "<tr><td rowspan=" # Push a string onto the array. ${\scalar, @$books} # What *IS* this, anyway? "$Author2</td>\n" # Another string ; # Done. But with what?

    Not to mention the missing > in the HTML.

      i am not suppose to use double quotes around the scalar
Re: Scaler found where opeartor expected Error
by NetWallah (Abbot) on May 29, 2012 at 21:22 UTC
    It appears that you are attempting Bash shell style expression evaluation in perl.

    Change that to:

    push @body, "<tr><td rowspan='" . scalar( @$books ) . "'>$Author2</td>\n";

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

Re: Scaler found where opeartor expected Error
by poj (Priest) on May 29, 2012 at 21:24 UTC
    push @body,"<tr><td rowspan=\"${\scalar @$books}\">$Author2</td>\n"; # add \ \ > ^ ^ ^ # remove , ^
    poj

      This fixes the immediate problem and leaves behind, IMHO, a little nightmare for the poor shlub who has to maintain this code six months or a year from now; better make sure he or she does not know your name or where you live – unless the maintainer is you, in which case justice may be said to have been served! Much better, I think, to use an sprintf statement instead.

      >perl -wMstrict -le "my $books = [ qw(a b c) ]; my @body = qw(x y); my $Author2 = 'defoe'; ;; push @body, qq{<td rowspan=${\scalar @$books}>$Author2</td>}; push @body, sprintf qq{<td rowspan=%d>$Author2</td>}, scalar @$books; print qq{'$_'} for @body; " 'x' 'y' '<td rowspan=3>defoe</td>' '<td rowspan=3>defoe</td>'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://973086]
Approved by muba
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-09-22 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (180 votes), past polls