Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

Help with Perl operators Please!


This is part of a script
Can someone please tell me what operations are being performed
on the value t

for (my $N = 0; $N <= $Count; $N++) {
        my $t = $N * $N
        $d += ($t ? $t : 1)  

}

Also

my @ii = unpack("V8", $chunk);

if $chunk is 32 bytes how will the bytes be unpacked into the array
@ii?

Thank you for any help

"scrarymary" <scraryma@hotmail.com> wrote in message

news:oa8863dp0clia7rtdfflqerg073286vfgj@4ax.com...

> This is part of a script
> Can someone please tell me what operations are being performed
> on the value t

> for (my $N = 0; $N <= $Count; $N++) {
> my $t = $N * $N

I think that should be:

my $t = $N * $N;

At the first iteration, $t is 0 (0 squared)
At the second iteration, $t is 1 (1 squared)
At the third iteration, $t is 4 (2 squared)
At the fourth iteration, $t is 9 (3 squared)
and so on ....

After $Count + 1 iterations, the loop terminates, and $t has the value
$count * $Count ($Count squared).

> $d += ($t ? $t : 1)

I think that should be:

$d += ($t ? $t : 1);

That line just assigns $d + $t to $d ... unless $t is zero (or numerically
equivalent to zero) - in which case it assigns $d + 1 to $d.

> }

> Also

> my @ii = unpack("V8", $chunk);

> if $chunk is 32 bytes how will the bytes be unpacked into the array
> @ii?

You can see by running:

print "@ii\n";

(The individual elements of @ii will be separated by a space.)

See 'perldoc perlop'.

Cheers,
Rob

scrarymary wrote:
> This is part of a script

Looks a bit like homework.
http://www.catb.org/~esr/faqs/smart-questions.html#homework

> Can someone please tell me what operations are being performed
> on the value t

There isn't a value t, there is a scalar variable named $t.

> for (my $N = 0; $N <= $Count; $N++) {
>    my $t = $N * $N

A scalar value is assigned to the variable $t

>    $d += ($t ? $t : 1)  

This is equivalent to

   if ($t) {
     $d += $t;
   } else {
     $d += 1;
   }

The boolean value of $t is false if it is undefined or zero.

$foo += $bar;
is equivalent to
$foo = $foo + $bar;

> }

> Also

> my @ii = unpack("V8", $chunk);

> if $chunk is 32 bytes how will the bytes be unpacked into the array
> @ii?

Since I don't know, I'd either read the documentation (start at `perldoc
-f unpack`) or write a short program to find out by assigning a
carefully chosen value to $chunk and printing @ii.

scrarymary wrote:
> This is part of a script
> Can someone please tell me what operations are being performed
> on the value t

That's a trick question.  The answer is None.. it's a syntax error.

If it was correct.. You can answer the questions yourself by adding
a few print statements.

> for (my $N = 0; $N <= $Count; $N++) {
>    my $t = $N * $N

print "t is set to $N * $N which is: $t\n";

print "before d = $d\n";

>    $d += ($t ? $t : 1)  

print "after d = $d\n";

> }

> Also

> my @ii = unpack("V8", $chunk);

> if $chunk is 32 bytes how will the bytes be unpacked into the array
> @ii?

Instead of asking what will happen, why not try it and see for yourself?
On Tue, 5 Jun 2007 01:33:37 +1000, "Sisyphus"

<sisyph@nomail.afraid.org> wrote:
>Cheers,
>Rob

Thank you
On Mon, 04 Jun 2007 16:45:10 +0100, Ian Wilson

<scoblo@infotop.co.uk> wrote:

thanks
On Mon, 04 Jun 2007 10:50:48 -0500, "J. Gleixner"

<glex_no-s@qwest-spam-no.invalid> wrote:
>Instead of asking what will happen, why not try it and see for yourself?

Normally I would but had trouble getting things to run

Thanks for your help

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc