Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: while (scalar()

by Happy-the-monk (Canon)
on Mar 12, 2004 at 21:58 UTC ( [id://336275]=note: print w/replies, xml ) Need Help??


in reply to while (scalar()

this is a "blind" answer: I see your parentheses aren't equally weighted.
Keep counting them for every instruction. Open one, close one. Open two, close two.
Finish each instruction with a semicolon ";" or closing "}" if there was an opening"{" before.

When you've put that right, and the errors persist, tell us what the errors actually say. Most times, they are worth being read.

Sören

Replies are listed 'Best First'.
Re: Re: while (scalar()
by cdherold (Monk) on Mar 12, 2004 at 22:02 UTC
    while (scalar(@ra)) while (scalar(@rb)) while (scalar(@rc))
    After I put in the parentheses, the error is: syntax error at local_align.cgi line 89, near ") while"

    I am not totally new to perl, but this construction makes NO sense to me at all. I was curious if it was some PERL shorthand or something.

      for, while, do, if, until, unless all operate on BLOCKS of code. If you come from C you will be safe to assume that you always need  { .... } and you always need ; Anyway the general sysntax is

      KEYWORD ( CONDITION ) { # begining of block of code to exec marked by { # stuff you want to do goes in here } # end of block of code to exec marked by }

      So in short your code is a syntax error(s). Your indentation is also shot. It should look like:

      if ( $some_condition ) { # some_condition is true while( @something && @something_else ) { shift @something; pop @something_else; } } else { print "Some condition is false!\n"; }

      Code like my second example will compile and is easy to read. Your insistence that nothing has changed means either it never worked, someone rediefined the perl languague while we were not looking or you have changed stuff.

      It looks to me as if you are trying to maintain a piece of code written by someone else. I would suggest for a start you google for perltidy and install it, then run it on your code to clean the indentation into something reasonable. That will make your life a lot easier.

      cheers

      tachyon

      it makes no sense. It is wrong.

      As to see what makes sense:
      scalar(@ra)   counts the elements of array @ra.
      while ( scalar( @ra ) )   does a while condition around the counting. In this case, you would normally just leave out the counting and write   while ( @ra )
      Anyway, there needs to be a { } block as to which the while condition belongs. It is missing, that's an error I can't make any sense of.

      Sören

        You wouldn't be leaving out the counting, you'd be leaving out the redundancy of providing scalar context where while() already provides one.

        The PerlMonk tr/// Advocate

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://336275]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found