group

2003-12-25 Thread dave
I've made a group called everyone.  It has its own Sub-directory, 
"/home/everyone".  I have 3 users in the group.  Do I have to do 
anything else so everyone can share that Sub-directory?  Mandrake 9.2. 
Thanks in advance.

--
Dave Pomeroy K7DNP South Eastern Washington


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



wrong group

2003-12-25 Thread dave
Sorry for my last post I thought I'd sent that to Linux-newbie.

--
Dave Pomeroy K7DNP South Eastern Washington


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Perl Help: Array Manipulation

2003-12-25 Thread u235sentinel
I'm a newbie to perl also.  Been workign with it for a whole 2 weeks 
now.  Actually.. make that 3 ::grinz::

Warning.. lengthy email below.. I beg forgiveness in advance :-)

Ok.  Here is what I did.

#!/usr/bin/perl

@array1[0..5] = 1;
@total[0] = 0;
for($i=0; $i<4; $i++)
{
if($i == 0)
{
 @total[$i] = @array1[$i];
   print "First group";
 print @total[$i];
}
else
{
 $j = $i - 1;
   print "Second group";
 @total[$i] = @total[$j] + @array1[$i];
 print @total[$i];
}
}
When I run it I get the following:

First group1Second group1Second group1Second group1

So technically it's not even printing the total of your array.  The 
array is fine.  Every container is populated with the #1.  You are 
basically printing each container entry in the array.  If you are 
looking for a total of all containers in the @total array you need to 
add them together in the array.  You will need to add them to a scalar 
variable or a particular container (total[5] perhaps?).  Here is what I 
did.  Warning.. not a clean bit of code but it get's the idea across.. I 
think:

#!/usr/bin/perl

@array1[0..5] = 1;
@total[0] = 0;
for($i=0; $i<4; $i++)
{
if($i == 0)
{
 @total[$i] = @array1[$i];
   print "First group";
 print @total[$i];
   $total = $total + @total[$i];
   print "\n";
   print $total;
}
else
{
 $j = $i - 1;
   print "Second group";
 @total[$i] = @total[$j] + @array1[$i];
   $total = $total + @total[$i];
 print @total[$i];
   print "\n";
   print $total;
}
}
So now you see on the left the sum of each container in the array. 

Ok.. I away the flogging.  Someone is bound to have done a better job 
explaining this.  At least I can blame it on being up after midnight ;-)

Speaking of which... MERRY CHRISTMAS TO ALL!!!

Night.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Perl Help: Array Manipulation

2003-12-25 Thread Randy W. Sims
On 12/25/2003 12:59 AM, Duong Nguyen wrote:
Hello everyone,

Sorry for the spam, I am new to Perl and am having a hard time manipulating arrays.  Below is the sample code that I am working on:

@array1[0..5] = 1;
@total[0] = 0;
for($i=0; $i<4; $i++)
{
 if($i == 0)
 {
  @total[$i] = @array1[$i];
  print @total[$i];
 }
 else
 {
  $j = $i - 1;
  @total[$i] = @total[$j] + @array1[$i];
  print @total[$i];
 }
 }
This code would work in C/C++, but with Perl, instead of adding up the previous values, the array "Total" seems to treat the integer value as a string and join them together.  So instead of ending up with 4 as my resulting total, I instead get .  I know this is a rather dumb question, but any help would be GREATLY appreciated.  Thanks in advance.
hint #1: Add the following to the beginning of your program

use strict;
use warnings;
hint #2: Do you know the difference between '@total[$i]' and '$total[$i]' ?

Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Perl Help: Array Manipulation

2003-12-25 Thread Duong Nguyen
Thanks for the response.  I discovered that it was my @array1[0..5] =1; initialization.
So I manually allocated values to the array to see if it would work, much to my 
surprise, the correct "total" was being printed.  Here's what I did:

change @array1[0..5] to @array1[0] = 1;
  @array1[1] = 1;
  @array1[2] = 1;

This works well.   
  - Original Message - 
  From: u235sentinel 
  To: Duong Nguyen ; [EMAIL PROTECTED] 
  Sent: Thursday, December 25, 2003 2:40 AM
  Subject: Re: Perl Help: Array Manipulation


  I'm a newbie to perl also.  Been workign with it for a whole 2 weeks 
  now.  Actually.. make that 3 ::grinz::

  Warning.. lengthy email below.. I beg forgiveness in advance :-)

  Ok.  Here is what I did.

  #!/usr/bin/perl

  @array1[0..5] = 1;
  @total[0] = 0;

  for($i=0; $i<4; $i++)
  {
   if($i == 0)
   {
@total[$i] = @array1[$i];
  print "First group";
print @total[$i];
   }
   else
   {
$j = $i - 1;
  print "Second group";
@total[$i] = @total[$j] + @array1[$i];
print @total[$i];
   }
   }


  When I run it I get the following:

  First group1Second group1Second group1Second group1

  So technically it's not even printing the total of your array.  The 
  array is fine.  Every container is populated with the #1.  You are 
  basically printing each container entry in the array.  If you are 
  looking for a total of all containers in the @total array you need to 
  add them together in the array.  You will need to add them to a scalar 
  variable or a particular container (total[5] perhaps?).  Here is what I 
  did.  Warning.. not a clean bit of code but it get's the idea across.. I 
  think:

  #!/usr/bin/perl

  @array1[0..5] = 1;
  @total[0] = 0;

  for($i=0; $i<4; $i++)
  {
   if($i == 0)
   {
@total[$i] = @array1[$i];
  print "First group";
print @total[$i];
  $total = $total + @total[$i];
  print "\n";
  print $total;
   }
   else
   {
$j = $i - 1;
  print "Second group";
@total[$i] = @total[$j] + @array1[$i];
  $total = $total + @total[$i];
print @total[$i];
  print "\n";
  print $total;
   }
   }

  So now you see on the left the sum of each container in the array. 

  Ok.. I away the flogging.  Someone is bound to have done a better job 
  explaining this.  At least I can blame it on being up after midnight ;-)

  Speaking of which... MERRY CHRISTMAS TO ALL!!!

  Night.



Re: Perl Help: Array Manipulation

2003-12-25 Thread Randy W. Sims
On 12/25/2003 2:51 AM, Duong Nguyen wrote:

  From: Randy W. Sims 
 >
  On 12/25/2003 12:59 AM, Duong Nguyen wrote:
  > Hello everyone,
  > 
  > Sorry for the spam, I am new to Perl and am having a hard time manipulating arrays.  Below is the sample code that I am working on:
  > 
  > @array1[0..5] = 1;
  > @total[0] = 0;
  > 
  > for($i=0; $i<4; $i++)
  > {
  >  if($i == 0)
  >  {
  >   @total[$i] = @array1[$i];
  >   print @total[$i];
  >  }
  >  else
  >  {
  >   $j = $i - 1;
  >   @total[$i] = @total[$j] + @array1[$i];
  >   print @total[$i];
  >  }
  >  }
  > 
  > This code would work in C/C++, but with Perl, instead of adding up the previous values, the array "Total" seems to treat the integer value as a string and join them together.  So instead of ending up with 4 as my resulting total, I instead get .  I know this is a rather dumb question, but any help would be GREATLY appreciated.  Thanks in advance.

  hint #1: Add the following to the beginning of your program

  use strict;
  use warnings;
  hint #2: Do you know the difference between '@total[$i]' and '$total[$i]' ?

>
> Every time I use "strict" my program goes all crazy on me with the 
global and local variables.  So instead, I just comment that out.

That craziness suggests opportunities to learn. It really is easier to 
debug when you get in the habit of using those pragmas. It prevents a 
lot of headache.

> The difference between '@total[$i]' and "@total[$i]" is that with the 
single quote, what u have there is what gets printed out.  With double 
quote, the element of the array gets printed out.

No, look at the first character '@total[0]' vs '$total[0]' (@ vs $).
The first refers to an array (slice) with one element. The second refers 
to one element of an array.

BTW, wrt your other reply to the group, the initialization syntax you 
want is:

@array[0..5] = (1) x 6;

Regards,
Randy.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Perl Help: Array Manipulation

2003-12-25 Thread Charles K. Clarkson
Duong Nguyen <[EMAIL PROTECTED]> wrote:
: 
: Thanks for the response.  I discovered that it was my 
: @array1[0..5] =1; initialization.
: So I manually allocated values to the array to see if it 
: would work, much to my surprise, the correct "total" was 
: being printed.  Here's what I did:
: 
: change @array1[0..5] to @array1[0] = 1;
: @array1[1] = 1;
: @array1[2] = 1;
: 
: This works well.

Looks like a lot of Jscript I have been recently
unraveling. I'd hate to see that used to initialize
10,000 elements.

 my @array;
 @array[ 0 .. 5 ] = (1) x 6;
 my @totals = 0;


:   for($i=0; $i<4; $i++)
:   {

In perl, is it rare that you would need to use
indexes to iterate through a single array. I don't care
much for $i and $j, either. I didn't come from a C
background, so the idiom above tends to confuse me.

 foreach $amount ( @array[ 0 .. 3 ] ) {


:if($i == 0)
:{
: @total[$i] = @array1[$i];
:   print "First group";
: print @total[$i];
:}

My first reaction was why not place this outside
the loop? In perl both @total[$1] and $total[$1] will
both work, but the second form is preferred. You will
also catch a lot less grief from this list.


:else
:{
: $j = $i - 1;
:   print "Second group";
: @total[$i] = @total[$j] + @array1[$i];
: print @total[$i];
:}
:}

Since we are not using an $i index, $j won't help
much. We can grab values from an array by using a
negative index. -1 is the last element in an array:

 push @totals, $totals[ -1 ] + $amount;
 print $totals[ -1 ];
 }

Let's review that. I am pushing onto @totals the
sum of the last value on @totals ( $totals[-1] ) and
the current amount. Then I print the new last total
on @totals. Notice that this algorithm will allow
any range in $amounts to be totaled, not just
consecutive amounts starting from the beginning.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328

As tested:

#!/usr/bin/perl

use strict;
use warnings;

my @array;
@array[ 0 .. 5 ] = (1) x 6;

my @totals = 0;
foreach my $amount ( @array[ 0 .. 3 ] ) {
push @totals, $totals[ -1 ] + $amount;
}

shift @totals;
print @totals;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Perl Help: Array Manipulation

2003-12-25 Thread Charles K. Clarkson

u235sentinel <[EMAIL PROTECTED]> wrote:
[snipped valiant attempt]
: 
: So now you see on the left the sum of each container in the array. 
: 
: Ok.. I await the flogging.  Someone is bound to have done a better job 
: explaining this.  At least I can blame it on being up after 
: midnight ;-)

Test your solution with:

 @array1[0..5] = ( 1, 4, -200, 8, 15, 0 );



HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Help: Array Manipulation

2003-12-25 Thread John W. Krahn
Duong Nguyen wrote:
> 
> Hello everyone,

Hello,

> Sorry for the spam,

Why do you think that this is spam?

> I am new to Perl and am having a hard time manipulating
> arrays.  Below is the sample code that I am working on:

You should have warnings and strictures enabled while you are developing
your program.

use warnings;
use strict;


> @array1[0..5] = 1;

You are assigning a single value to an array slice.  This means that
$array[0] gets the value 1 and $array[1] through $array[5] get the value
undef.  It also means that the values in $array[6] through
$array[$#array] are not affected by the assignment.  If this is the
first time that you are using @array then you need to assign a list of
six ones to the varaible @array.

my @array = ( 1, 1, 1, 1, 1, 1 );

Or, less error prone:

my @array = ( 1 ) x 6;

Or even (ick):

my @array = map 1, 0 .. 5;


> @total[0] = 0;

An array slice again!  Perhaps you meant:

my $total = 0;


> for($i=0; $i<4; $i++)

In perl, that is usually written as:

for my $i ( 0 .. 3 )

But you are only totaling the first four elements of @array and the
array has at least six elements.


> {
>  if($i == 0)

You don't need a special case for the zero element as perl uses
autovivification.


>  {
>   @total[$i] = @array1[$i];
>   print @total[$i];

You are using array slices where you should be using scalars.

   $total[$i] = $array1[$i];
   print $total[$i];


>  }
>  else
>  {
>   $j = $i - 1;
>   @total[$i] = @total[$j] + @array1[$i];
>   print @total[$i];

Again, you are using array slices where you should be using scalars.

   $total[$i] = $total[$j] + $array1[$i];
   print $total[$i];


>  }
>  }
> 
> This code would work in C/C++,

No, the algorithm is wrong.

> but with Perl, instead of adding up the
> previous values, the array "Total" seems to treat the integer value as
> a string and join them together.

No, it is just printing '1' each time through the loop.

> So instead of ending up with 4 as my
> resulting total, I instead get .

That is because you are printing '1' four times.

> I know this is a rather dumb
> question, but any help would be GREATLY appreciated.  Thanks in advance.


my @array = ( 1 ) x 6;

my $total = 0;

$total += $_ for @array[ 0 .. 3 ]; # now is a GOOD time for an array
slice

print "$total\n";




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




compile to CGI

2003-12-25 Thread Stijn DM
Hi,

I installed a script called "megauploader" successfully and did some layout
work in the php documents
to fit it to my own needs.

Now I also would like to change the layout in the progress bar window. The
problem
is that this is a CGI document and I am somewhat inexperienced in Perl.

Each time I make a modification in the CGI file (using a text editor) and I
save it, I get a Internal
Server Error. I think because of the fact that I didn't compile the original
script to a new cgi file.

Is there any way that I can modify the cgi files or that I can compile the
perl
files to cgi again? This might seem a really dumb question, but as I said,
I'm new on the issue.

Thanks for your help,
Stijn





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to send O/P to file?

2003-12-25 Thread Tushar Gokhale
Thanks a lot for all of you for helping and sorry for creating confusion by
not including code. I have ssh connection and I'm sending commands on CLI.
I just managed to fix the problem.

open ( OUTPUT , ">single.log" ) || genError ( 0, "Unable to open log file");
select ( OUTPUT );

This solved my problem.

Any one knows any good link on perl threading [FORK] ? Which can give me
detail info with example. How to create thread and use multiple threads?



Tushar Gokhale wrote:

> I've opened a connection to remote machine through perl script and sending
> commands and can see the output on screen but I want to put that output in
> File along with the commands that were send. how do I do that?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: compile to CGI

2003-12-25 Thread Owen Cook

On Thu, 25 Dec 2003, Stijn DM wrote:

> I installed a script called "megauploader" successfully and did some layout
> work in the php documents
> to fit it to my own needs.
> 
> Now I also would like to change the layout in the progress bar window. The
> problem
> is that this is a CGI document and I am somewhat inexperienced in Perl.
> 
> Each time I make a modification in the CGI file (using a text editor) and I
> save it, I get a Internal
> Server Error. I think because of the fact that I didn't compile the original
> script to a new cgi file.
> 
> Is there any way that I can modify the cgi files or that I can compile the
> perl
> files to cgi again? This might seem a really dumb question, but as I said,
> I'm new on the issue.



When you modify a program, you have to modify it so that the
"Perl" recompiles correctly.

I suggest that you are making an incorrect "Perl" statement when you
change the script.

Why don't you post the lines you want to change, and the lines after you
changed them. maybe someone can tell you the error of your ways.

Also it would be helpful if you had Perl installed on your computer for
testing or even learning perl.

If you had perl you could say
"perl -c megauploader.cgi" to see if it will still compile before
you put it on the server.

Good luck



Owen



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to extract the full URL from a relative link using WWW:: Mecha nize

2003-12-25 Thread Rob Dixon
Rajesh Dorairajan wrote:
>
> I am using WWW::Mechanize to create a configuration file from a website and
> my script needs to go through a web-page and copy a specific links into a
> configuration file. I am using $m->links method that returns the list of
> links from a page. However, I am not able to get the fully qualified URL
> such as http://www.domain.com/dir1/dir12/file1.html. Instead I get
> /dir1/dir12/file.html. Please forgive me if this doesn't make sense. I am
> giving the code below for more clarity:
>
> my $obj = WWW::Mechanize->new();
> my $url = "http://www.domain.com/dir1";;
> .
> .
>
> for my $link ( @links ) {
> my $url = $link->url;
> $obj->get ( $url );
> my @urls = $obj->links;
>
>
> $obj->get( $urls[1]->url, ":content_file"=>"$dir/tmp/tmpfile.cert" );
> .
> .
>
> print CRL "[INPUT_SECTION_$count]\n";
> print CRL "LOCATION=".$urls[2]->url."\n\n"; #This is where I need the
> fully qualified URL instead of the relative URL that I get currently
> $count++;
> }
>
> I looked up a lot on the web before sending this mail. I am not able to find
> any documentation that points to this. Any help will be deeply appreciated.

Hi Rajesh.

I'm puzzled by your code. What's in your @links array that has a 'url' method?
And I don't know of a WWW::Mechanize::get method that takes two parameters.
I have the latest WWW::Mechanize from CPAN. Are you doing something
inscrutably clever?

Anyway, the answer is to use the URI::URL module (already 'require'd by
WWW::Mechanize) to build the absolute URL from the href= field of the anchors
like this:

  use strict;
  use warnings;

  use WWW::Mechanize;

  my $mech = new WWW::Mechanize;

  $mech->get('http://search.cpan.org/');

  foreach (@{$mech->links}) {
print URI::URL->new_abs($_->[0], $mech->base), "\n";
  }

I hope this helps.

Happy Christmas!

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




anon ref to scalar?

2003-12-25 Thread mcdavis941
I'm working on a clone method for an object (which makes a deep copy of the data 
structure and all other data structures 'contained' by it).  I'm trying to create a 
new reference that refers to the same thing an existing reference points to, but is 
actually a separate reference, so that you get two separately-valued references 
pointing to the same underlying value.  

It's not going as planned.

Here's the code which I expected to work, but doesn't.  I'm expecting \$$orig to 
result in a new reference, but instead it's reusing the original reference that I 
started with.

So:

$s = "some string";
$orig = \$s;
$new = \$$orig;
print "orig:$orig, new:$new\n";

Results in these values:

orig:SCALAR(0x17753dc), new:SCALAR(0x17753dc)

Is there a way to force it to create a new reference to a scalar (in the same way that 
[] and {}, when used as anon ref constructors, create new references), such that new 
!= orig?  And what is the underlying property of Perl that makes it give you the same 
hex value for the reference?

TIA and Merry Christmas

__
New! Unlimited Access from the Netscape Internet Service.
Beta test the new Netscape Internet Service for only $1.00 per month until 3/1/04.
Sign up today at http://isp.netscape.com/register
Act now to get a personalized email address!

Netscape. Just the Net You Need.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: anon ref to scalar?

2003-12-25 Thread James Edward Gray II
On Dec 25, 2003, at 7:02 AM, [EMAIL PROTECTED] wrote:

I'm working on a clone method for an object (which makes a deep copy 
of the data structure and all other data structures 'contained' by 
it).
The standard module Storable will do a deep copy for you with one 
subroutine call.  Might want to check that out.

I'm trying to create a new reference that refers to the same thing an 
existing reference points to, but is actually a separate reference, so 
that you get two separately-valued references pointing to the same 
underlying value.

It's not going as planned.

Here's the code which I expected to work, but doesn't.  I'm expecting 
\$$orig to result in a new reference, but instead it's reusing the 
original reference that I started with.

So:

$s = "some string";
$orig = \$s;
$new = \$$orig;
I believe you just want:

$new = $orig;

You're trying to copy the reference and = generally means copy.

print "orig:$orig, new:$new\n";
James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: anon ref to scalar?

2003-12-25 Thread mcdavis941
James Edward Gray II <[EMAIL PROTECTED]> wrote:

>I believe you just want:
>
>$new = $orig;
>
>You're trying to copy the reference and = generally means copy.
>
>> print "orig:$orig, new:$new\n";


True, but ... (1) the requirement for a deep copy is that you can modify anything in 
the original data structure and not have the change reflected in the copy, which means 
that (2) any references in the copy have to refer to something other than what was 
refered to in the original while (3) preserving any literal values at the leaf nodes 
of the entire data structure, which I take to mean that (4) when duplicating refs to 
scalars, I have to create another copy of the literal value and then create a ref to 
that new copy (which is what I was trying but failing to do in my code).  Right?

I'll admit I'm not real clear on what I need to be doing, especially since I'm not at 
all clear about Perl internal data structures and how Perl represents literal values 
and whether you can actually have two separate copies of the same literal value or not 
... oy vey.

I'll check out storable, thx for the redirection.

__
New! Unlimited Access from the Netscape Internet Service.
Beta test the new Netscape Internet Service for only $1.00 per month until 3/1/04.
Sign up today at http://isp.netscape.com/register
Act now to get a personalized email address!

Netscape. Just the Net You Need.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: anon ref to scalar?

2003-12-25 Thread drieux
On Dec 25, 2003, at 5:02 AM, [EMAIL PROTECTED] wrote:

Here's the code which I expected to work, but doesn't.
I'm expecting \$$orig to result in a new reference, but
instead it's reusing the original reference that I started with.
So:

$s = "some string";
$orig = \$s;
$new = \$$orig;
print "orig:$orig, new:$new\n";
Results in these values:

orig:SCALAR(0x17753dc), new:SCALAR(0x17753dc)
bear with me, I am slow this morning.

if you went with "$new = $$orig" then your new
holds the value that $s holds. Hence it would
not be a 'reference' to that string...
Plan A: would seem to be the simple

my $bob = $$orig; #copy the substance of $orig
my $new = \$bob;  #take a reference to the new memory
Plan B: would be to make a function like:

#
#
sub clone_me
{
my ($me,$item) = @_;

my $ref_type = ref($item);

return $item unless $ref_type;

if ( $ref_type eq 'SCALAR' )
{
my $new_item = $$item;
return(\$new_item);
}elsif ($ref_type eq 'ARRAY' )
{
my $count = 0;
my @array;
$array[$count++] = $me->clone_me($_)
foreach(@$item);

return([EMAIL PROTECTED]);
}
# solve the case for a hash ref

} # end of clone_me
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Perl Help: Array Manipulation

2003-12-25 Thread u235sentinel
But wouldn't the original initilization also work?

@array1[0..5] = 1;

This seemed to populate the array just fine. 

Randy W. Sims wrote:

On 12/25/2003 2:51 AM, Duong Nguyen wrote:

  From: Randy W. Sims 
 >

  On 12/25/2003 12:59 AM, Duong Nguyen wrote:
  > Hello everyone,
  >   > Sorry for the spam, I am new to Perl and am having a hard 
time manipulating arrays.  Below is the sample code that I am working 
on:
  >   > @array1[0..5] = 1;
  > @total[0] = 0;
  >   > for($i=0; $i<4; $i++)
  > {
  >  if($i == 0)
  >  {
  >   @total[$i] = @array1[$i];
  >   print @total[$i];
  >  }
  >  else
  >  {
  >   $j = $i - 1;
  >   @total[$i] = @total[$j] + @array1[$i];
  >   print @total[$i];
  >  }
  >  }
  >   > This code would work in C/C++, but with Perl, instead of 
adding up the previous values, the array "Total" seems to treat the 
integer value as a string and join them together.  So instead of 
ending up with 4 as my resulting total, I instead get .  I know 
this is a rather dumb question, but any help would be GREATLY 
appreciated.  Thanks in advance.

  hint #1: Add the following to the beginning of your program

  use strict;
  use warnings;
  hint #2: Do you know the difference between '@total[$i]' and 
'$total[$i]' ?

>
> Every time I use "strict" my program goes all crazy on me with the 
global and local variables.  So instead, I just comment that out.

That craziness suggests opportunities to learn. It really is easier to 
debug when you get in the habit of using those pragmas. It prevents a 
lot of headache.

> The difference between '@total[$i]' and "@total[$i]" is that with 
the single quote, what u have there is what gets printed out.  With 
double quote, the element of the array gets printed out.

No, look at the first character '@total[0]' vs '$total[0]' (@ vs $).
The first refers to an array (slice) with one element. The second 
refers to one element of an array.

BTW, wrt your other reply to the group, the initialization syntax you 
want is:

@array[0..5] = (1) x 6;

Regards,
Randy.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: generating GIFs

2003-12-25 Thread Andrew Gaffney
zentara wrote:
On Tue, 23 Dec 2003 09:22:01 -0500, zentara <[EMAIL PROTECTED]>
wrote:

I havn't tried it personnally yet, but I think you should be able
to avoid writing that temporary png file.  If you are using
perl5.8 you could write to a variable, and then just have
Image::Magick read from that. The following should show you
the basic idea.
Well, here is a working method for perl5.8

#!/usr/bin/perl
use warnings;
use strict;
use GD;
use Image::Magick;


Well, just I went back and tested this again. F#$%king Image::Magick
dosn't work with this method.  Somehow I got it to work before
posting, but it was a fluke. I think I must have accidently
created a $tmp file, and IM was using it. 
Image::Magick dosn't like reading from a tmp scalar.

But good newsImager does.
So in case anyone was banging their head on the wall
wondering why it didn't work, here is a better method
using Imager. Plus Imager makes a smaller gif. :-)
#!/usr/bin/perl
use warnings;
use strict;
use GD;
use Imager;
my $im = new GD::Image(61,20);
my $text = 'foobar!';
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $gray = $im->colorAllocate(132,132,132);
my $blue = $im->colorAllocate(206,206,255);
# Different shades of blue are to give it a slightly more 3D effect
my $leftblue = $im->colorAllocate(231,231,255);
my $bottomblue = $im->colorAllocate(165,165,206);
my $rightblue = $im->colorAllocate(123,123,156);
my $topblue = $im->colorAllocate(214,214,255);
$im->transparent($white);
$im->interlaced('true');
$im->filledRectangle(0,0,60,19,$white); # Transparent background
$im->filledRectangle(3,3,60,19,$gray); # Draw gray "shadow" rectangle
$im->filledRectangle(0,0,57,16,$blue); # Draw blue foreground rectangle
$im->rectangle(0,0,57,16,$white); # Make blue rectangle border
transparent
$im->line(1,0,56,0,$topblue);
$im->line(57,1,57,15,$rightblue);
$im->line(1,16,56,16,$bottomblue);
$im->line(0,1,0,15,$leftblue);
# Determine size of generated text in order to center it on the blue
rectangle
#my @bounds = GD::Image->stringFT($black,"./arial.ttf",9,0,0,0,$text);
#print "@bounds\n";
#$im->stringFT($black,"./arial.ttf",9,0,((57-$bounds[2])/2),13,$text);
$im->string(gdSmallFont, 2, 2, $text, $black);
# Write image to temporary PNG file
my $tmp = '';
open IMAGE, "+>",\$tmp or die $!;
binmode IMAGE;
print IMAGE $im->png;
close IMAGE;
#print $tmp;
# Convert image to GIF file
my $img = Imager->new;
$img->read(data=>$tmp, type=>'png')
   or die "Cannot read: ", $img->errstr;
$img->write(file=>"$0.gif", type=>'gif')
   or die "Cannot write: ",$img->errstr;
__END__
I'd never tried your last post, but I will try this one, especially since it actually 
works ;) Thanks.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: anon ref to scalar?

2003-12-25 Thread Randal L. Schwartz
> "mcdavis941" == mcdavis941  <[EMAIL PROTECTED]> writes:

mcdavis941> I'm working on a clone method for an object (which makes a deep copy of 
the data structure and all other data structures 'contained' by it).  I'm trying to 
create a new reference that refers to the same thing an existing reference points to, 
but is actually a separate reference, so that you get two separately-valued references 
pointing to the same underlying value.  

mcdavis941> It's not going as planned.

Have you seen Storable's "clone" routine?

Have you seen my article on deep copy?


I don't mind you reinventing the wheel, provided you have already
studied prior art.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Help: Array Manipulation

2003-12-25 Thread R. Joseph Newton
u235sentinel wrote:

> I'm a newbie to perl also.  Been workign with it for a whole 2 weeks
> now.  Actually.. make that 3 ::grinz::
>
> Warning.. lengthy email below.. I beg forgiveness in advance :-)

Length isn't a problem.  There are some problems here, though, because you
are not addressing the issues that are holding him back.  One is the syntax
for accessing an array element.  Array elements should be accessed as
scalars, with the scalar notation:

my $element = $array1[$index];

That is a major source of the problems the OP found.  The other is that he
expects the print statement to automatically space the output.  It won't.


>
> Ok.  Here is what I did.

Some things you should have done inline:

> #!/usr/bin/perl

use strict;   #  *always*
use warnings;   # until you canotherwise catch the things you get warnings
about.

>
>
> @array1[0..5] = 1;

Means nothing, AFAIK.
Greetings! E:\d_drive\perlStuff>perl -w -Mstrict
my @Array1;
@Array1[0..5] = 1;
print "$_\n" for @Array1;
^Z
1
Use of uninitialized value in concatenation (.) or string at - line 3.

Use of uninitialized value in concatenation (.) or string at - line 3.

Use of uninitialized value in concatenation (.) or string at - line 3.

Use of uninitialized value in concatenation (.) or string at - line 3.

Use of uninitialized value in concatenation (.) or string at - line 3.

 Try instead:
$_ = 1 for @array[0..4];


>
> @total[0] = 0;
>
> for($i=0; $i<4; $i++)
> {
>  if($i == 0)
>  {
>   @total[$i] = @array1[$i];
> print "First group";
>   print @total[$i];
>  }
>  else
>  {
>   $j = $i - 1;
> print "Second group";
>   @total[$i] = @total[$j] + @array1[$i];
>   print @total[$i];
>  }
>  }
>
> When I run it I get the following:

You both need to start by using strict and warnings.  It will also help if
you use variable names that tell you somethng about what you are trying to
do.  I'd suggest the OP start by using strict, and using the proper syntax
to address elements of an array.  Then post when he he gets satuck.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Help: Array Manipulation

2003-12-25 Thread u235sentinel
Understood.  I guess I was trying to show him ( the senec route) that 
basically no running total was being compiled.  Also that  wasn't  
the total.  I guess it was too late at night for a simple response from 
me :-)

Charles K. Clarkson wrote:

u235sentinel <[EMAIL PROTECTED]> wrote:
[snipped valiant attempt]
: 
: So now you see on the left the sum of each container in the array. 
: 
: Ok.. I await the flogging.  Someone is bound to have done a better job 
: explaining this.  At least I can blame it on being up after 
: midnight ;-)

   Test your solution with:

@array1[0..5] = ( 1, 4, -200, 8, 15, 0 );



HTH,

Charles K. Clarkson
 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: compile to CGI

2003-12-25 Thread R. Joseph Newton
Stijn DM wrote:

> Hi,
>
> I installed a script called "megauploader" successfully and did some layout
> work in the php documents
> to fit it to my own needs.
>
> Now I also would like to change the layout in the progress bar window. The
> problem
> is that this is a CGI document and I am somewhat inexperienced in Perl.
>
> Each time I make a modification in the CGI file (using a text editor) and I
> save it, I get a Internal
> Server Error. I think because of the fact that I didn't compile the original
> script to a new cgi file.
>
> Is there any way that I can modify the cgi files or that I can compile the
> perl
> files to cgi again? This might seem a really dumb question, but as I said,
> I'm new on the issue.
>
> Thanks for your help,
> Stijn

I'm going to take a wild peep into my crystal ball, and guess that you are
FTP'ing in binary mode from a Windows or Mac.  Use ASCII mode when FTP'ing
scripts to an unknown or different OS.  The different systems use different
escape sequences for their newlines, and ASCII mode will handle the translation
transparently.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl Help: Array Manipulation

2003-12-25 Thread Randy W. Sims
[Please respond to the mailing-list so that others can contribute and 
learn from the discussion. Thanks.]

On 12/25/2003 10:31 AM, Duong Nguyen wrote:
Hello,

Thanks for your reply.  I think I am a bit confused between using array slices and a particular element of an array.  The "print" function prints out the same value for both cases.  Do I use the latter when I want to deal with arithmetic operations (scalar)?

Thanks,
Duong
The simple explanation is that, when you want to refer to a single 
element of an array, the left-most symbol should be a '$'; the '$' 
indicates to perl that you want to access a single (scalar) value. If 
you want to access multiple elements of an array (or hash), you would 
use an array slice (left-most symbol would be '@'); the '@' indicates to 
perl that you want to access a _list_ of 1 or more elements as a group.

Randy.


  - Original Message - 
  From: Randy W. Sims 
  To: Duong Nguyen 
  Cc: [EMAIL PROTECTED] 
  Sent: Thursday, December 25, 2003 3:02 AM
  Subject: Re: Perl Help: Array Manipulation

  On 12/25/2003 2:51 AM, Duong Nguyen wrote:

  >   From: Randy W. Sims 
>
  >   On 12/25/2003 12:59 AM, Duong Nguyen wrote:
  >   > Hello everyone,
  >   > 
  >   > Sorry for the spam, I am new to Perl and am having a hard time manipulating arrays.  Below is the sample code that I am working on:
  >   > 
  >   > @array1[0..5] = 1;
  >   > @total[0] = 0;
  >   > 
  >   > for($i=0; $i<4; $i++)
  >   > {
  >   >  if($i == 0)
  >   >  {
  >   >   @total[$i] = @array1[$i];
  >   >   print @total[$i];
  >   >  }
  >   >  else
  >   >  {
  >   >   $j = $i - 1;
  >   >   @total[$i] = @total[$j] + @array1[$i];
  >   >   print @total[$i];
  >   >  }
  >   >  }
  >   > 
  >   > This code would work in C/C++, but with Perl, instead of adding up the previous values, the array "Total" seems to treat the integer value as a string and join them together.  So instead of ending up with 4 as my resulting total, I instead get .  I know this is a rather dumb question, but any help would be GREATLY appreciated.  Thanks in advance.
  > 
  >   hint #1: Add the following to the beginning of your program
  > 
  >   use strict;
  >   use warnings;
  > 
  >   hint #2: Do you know the difference between '@total[$i]' and '$total[$i]' ?
  > 
   >
   > Every time I use "strict" my program goes all crazy on me with the 
  global and local variables.  So instead, I just comment that out.

  That craziness suggests opportunities to learn. It really is easier to 
  debug when you get in the habit of using those pragmas. It prevents a 
  lot of headache.

   > The difference between '@total[$i]' and "@total[$i]" is that with the 
  single quote, what u have there is what gets printed out.  With double 
  quote, the element of the array gets printed out.

  No, look at the first character '@total[0]' vs '$total[0]' (@ vs $).
  The first refers to an array (slice) with one element. The second refers 
  to one element of an array.

  BTW, wrt your other reply to the group, the initialization syntax you 
  want is:

  @array[0..5] = (1) x 6;

  Regards,
  Randy.




--
A little learning is a dang'rous thing;
Drink deep, or taste not the Pierian spring;
There shallow draughts intoxicate the brain;
And drinking largely sobers us again.
- Alexander Pope
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Perl Help: Array Manipulation

2003-12-25 Thread Randy W. Sims
On 12/25/2003 12:18 PM, u235sentinel wrote:

But wouldn't the original initilization also work?

@array1[0..5] = 1;
No. Think of this in terms of parallel assignment, ignoring for the 
moment that we are talking of arrays, the above is equivalent to:

($e0, $e1, $e2, $e3, $e4, $e5) = 1;

which is equivalent to:

($e0, $e1, $e2, $e3, $e4, $e5) = (1);

because the list on the left-hand side of the assignment operator ('='), 
puts the right-hand side in list context. This is then filled in by perl 
to become:

($e0, $e1, $e2, $e3, $e4, $e5) = (1, undef, undef, undef, undef, undef);

because the list on the right-hand side must have the same number of 
elements as the list on the left-hand side.

The common idiom to populate an array with a particular value is to use 
the times operator ('x') which reproduces its left-hand argument the 
number of times specified by its right-hand argument:

($e0, $e1, $e2, $e3, $e4, $e5) = (1) x 6;

which is equivelent to:

($e0, $e1, $e2, $e3, $e4, $e5) = ((1), (1), (1), (1), (1), (1));

which then gets flatened to:

($e0, $e1, $e2, $e3, $e4, $e5) = (1, 1, 1, 1, 1, 1);

With an array slice, perl basically turns the original:

@array1[0..5] = 1;

into something like:

($array1[0], $array1[1], $array1[2], $array1[3], $array1[4], $array1[5]) 
 = (1, undef, undef, undef, undef, undef);

in the same manner as the first example above.

Regards,
Randy.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Perl Help: Array Manipulation

2003-12-25 Thread u235sentinel
Ahhh.. Ok.  I see the mistake.  I've purchased Oreilly's "Learning Perl" 
3rd Edition and have been steadily plugging through it.  There is an 
example on page 45 which shows another way to populate an array.  Here 
is one such example they give.

@numbers = 1..1e5;

So basically if you didn't want to use  =(1) x 6 you could do it this way.

I had confused where the .. goes :-)

thx for the clarify



Randy W. Sims wrote:

On 12/25/2003 12:18 PM, u235sentinel wrote:

But wouldn't the original initilization also work?

@array1[0..5] = 1;


No. Think of this in terms of parallel assignment, ignoring for the 
moment that we are talking of arrays, the above is equivalent to:

($e0, $e1, $e2, $e3, $e4, $e5) = 1;

which is equivalent to:

($e0, $e1, $e2, $e3, $e4, $e5) = (1);

because the list on the left-hand side of the assignment operator 
('='), puts the right-hand side in list context. This is then filled 
in by perl to become:

($e0, $e1, $e2, $e3, $e4, $e5) = (1, undef, undef, undef, undef, undef);

because the list on the right-hand side must have the same number of 
elements as the list on the left-hand side.

The common idiom to populate an array with a particular value is to 
use the times operator ('x') which reproduces its left-hand argument 
the number of times specified by its right-hand argument:

($e0, $e1, $e2, $e3, $e4, $e5) = (1) x 6;

which is equivelent to:

($e0, $e1, $e2, $e3, $e4, $e5) = ((1), (1), (1), (1), (1), (1));

which then gets flatened to:

($e0, $e1, $e2, $e3, $e4, $e5) = (1, 1, 1, 1, 1, 1);

With an array slice, perl basically turns the original:

@array1[0..5] = 1;

into something like:

($array1[0], $array1[1], $array1[2], $array1[3], $array1[4], 
$array1[5])  = (1, undef, undef, undef, undef, undef);

in the same manner as the first example above.

Regards,
Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]