Error in the "if" block

2006-02-19 Thread Ron Smith
Hi all,
   
  This page accepts a series of numbers, separated by spaces, and gives the 
values listed bellow.

  I'm getting the following error, but don't see why. Can anyone spot my error?
   
  Please, enter numbers separated by spaces only!: Bad file descriptor at 
E:/www/cgi-bin/pg93ex3.11SeriesOfNumbers.pl line 14.

I've narrowed the problem down to the "if" block (the regex), I'd like to 
accept numbers and spaces only. Here's the code:

#!E:/www/perl/bin/perl.exe

use strict;
use warnings;
use CGI qw( :standard );
use CGI::Carp qw( fatalsToBrowser );
 print header();
 
 my $userIn = param( "textfield" );
 
if ( $userIn =~ /^(\d+|\s*)$/ ) {
 $userIn = $1;
} else {
 die "Please, enter numbers separated by spaces only!: $!";
}
 
my @numbers = split( / /, $userIn );
my $total = scalar( @numbers );
my @sorted = sort( @numbers );
my $smallestNum =   @sorted[0];
my $largestNum = @sorted[-1];

 my $sum = 0;
 foreach ( @numbers ) {
  $sum += $_;
}

my $average = ( $sum / $total );

print<

Series of Numbers




This page accepts a series of numbers, separated by spaces, and gives the 
values listed bellow.

  

  Enter your numbers here: 
  


  

  http://mail.yahoo.com/config/login?/pg93ex3.11SeriesOfNumbers.html";> 
Click here to go back! 
  


  The total number of numbers entered is: 
   $total 


  The smallest number   is: 
   @sorted[0] 


  The largest number is: 
   @sorted[-1] 


  The sum of all the numbers is: 
   $sum 


  The average of all the numbers is:
   $average 

  


HTML


Ron Smith
[EMAIL PROTECTED]

Re: Making Image::Magick against a specific ImageMagick installation path

2006-02-19 Thread acummingsus
On Friday 17 February 2006 10:25, JupiterHost.Net wrote:
> Howdy list,
>
> When installign Image::Magick you do this:
>
> perl Makefile.PL
> make
> make install
>
> How do I tell it the path that ImageMagick is installed in sot hat its
> get built agianst them specifically?
>
> The docs and comments in Makefile.PL are pretty slim :)
>
> Would this do what I'm looking for above:
>
>   perl Makefile.PL PREFIX=/foo/bar/imagemagic
>
> as regards to:
>
>   # Set Perl Installation prefix to ImageMagick installation prefix
>   # 'PREFIX' => '/usr'
>
> in Makefile.PL

I don't know.  Hopefully you get answer.  Would it hurt anything to try it?

Slackware 10.2  I just grepped the pkg and found 13 in /usr/bin

You *could* (though this likely be the hard way to do it) make sym links 
in /usr/bin pointing to wherever these actually are on your system.

[EMAIL PROTECTED]:/var/log/packages# ls | grep imagemagi
imagemagick-6.2.3_3-i486-2
[EMAIL PROTECTED]:/var/log/packages# cat imagemagick-6.2.3_3-i486-2
PACKAGE NAME: imagemagick-6.2.3_3-i486-2
[ snipped ]
usr/bin/
usr/bin/compare
usr/bin/conjure
usr/bin/convert
usr/bin/display
usr/bin/composite
usr/bin/identify
usr/bin/Magick++-config
usr/bin/Wand-config
usr/bin/mogrify
usr/bin/Magick-config
usr/bin/montage
usr/bin/import
usr/bin/animate
usr/doc/
[ snipped ]
--

[EMAIL PROTECTED]:/usr/bin# pwd
/usr/bin
[EMAIL PROTECTED]:/usr/bin# ln -s 
/usr/local/wherever_imagemagick's_bin_is_at/mogrify 
mogrify

ln-swhere_mogrify_really_ismogrify

Too much work to sym link each/all 13 of these --
unless ( Perl_is_used ) { print "Perl makes it easy\n";}

Better off to get it how you requested up above.

-- 
Alan.

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




Re: Error in the "if" block

2006-02-19 Thread Hans Meier (John Doe)
Ron Smith am Sonntag, 19. Februar 2006 18.47:
> Hi all,

Hi Ron

>   This page accepts a series of numbers, separated by spaces, and gives the
> values listed bellow.
>   I'm getting the following error, 

No information about the input that causes the error; are there also inputs 
not causing an error?

>   but don't see why. Can anyone spot my error?
>   Please, enter numbers separated by spaces only!: Bad file descriptor at
> E:/www/cgi-bin/pg93ex3.11SeriesOfNumbers.pl line 14.

Hm, line 14 contains the die "Please..."

>
> I've narrowed the problem down to the "if" block (the regex), I'd like to
> accept numbers and spaces only. Here's the code:
>
> #!E:/www/perl/bin/perl.exe
>
> use strict;
> use warnings;
> use CGI qw( :standard );
> use CGI::Carp qw( fatalsToBrowser );
>  print header();
>
>  my $userIn = param( "textfield" );
>
> if ( $userIn =~ /^(\d+|\s*)$/ ) {

This does not match inputs containing more than one number.

What you want is something like

/^\s*((?:\d+\s*?)+)\s*$/

The inner (?:) does not capture output (see perldoc perlre), 
and the regex trims the input (which is allowed to contain leading and 
trailing space)

>  $userIn = $1;
> } else {
>  die "Please, enter numbers separated by spaces only!: $!";
> }

The if-else could be shortened to (untested, so please check):

die "Bla" unless ($userIn)=$userIn=~/^\s*((?:\d+\s*?)+)\s*$/;

> my @numbers = split( / /, $userIn );

This only splits on a single space character.

my @numbers = split /\s+/, $userIn;

splits (explicitly) on the same whitespace allowed in the regex above.



hth!
Hans

[irrelevant parts snipped away]



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




Re: Error in the "if" block

2006-02-19 Thread Ron Smith
> 
> No information about the input that causes the
> error; are there also inputs 
> not causing an error?

Yes, the input expected would be:
" 32 11 25" or "32 11 25 " or " 32 11 25 " ...etc.

>  
> What you want is something like
> 
> /^\s*((?:\d+\s*?)+)\s*$/
> 
> The inner (?:) does not capture output (see perldoc
> perlre), 
> and the regex trims the input (which is allowed to
> contain leading and 
> trailing space)
>

This worked superbly for what I'm doing. :-) I found
reference to "?:" on page 204 of the "Camel Book", but
it isn't enough info to tell how to use it. I'm
looking into 'perldoc perlre' righ now. Thanks, for
giving me another resource. :-)

> The if-else could be shortened to (untested, so
> please check):
> 
> die "Bla" unless
> ($userIn)=$userIn=~/^\s*((?:\d+\s*?)+)\s*$/;
> 
Right; a lot shorter. Why, the parentheses around
$userIn?

> > my @numbers = split( / /, $userIn );
> 
> This only splits on a single space character.
> 
> my @numbers = split /\s+/, $userIn;
> 
> splits (explicitly) on the same whitespace allowed
> in the regex above.

I changed this too. Thanks, Hans!
> 
> [irrelevant parts snipped away]

Ron Smith
[EMAIL PROTECTED]

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




perl with databases

2006-02-19 Thread Octavian Rasnita
Hi,

I need to recommend/use a better database than MySQL that should work well
with perl.
I have read some web pages about PostgreSQL and I have seen that it has a
procedural language PLPERL, while Oracle doesn't have such a thing. I have
also seen that Oracle is a little better than PostgreSQL.

The database I need to keep is not very very big, but too big for MySQL, and
the most important thing is the speed of selections/updates.

Is the fact that Oracle doesn't have an internal support for perl but just
for Java an important thing?
Are important the advantages of Oracle over PostgreSQL?

Thank you.

Teddy


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




Re: Error in the "if" block

2006-02-19 Thread John W. Krahn
Ron Smith wrote:
> Hi all,

Hello,

> This page accepts a series of numbers, separated by spaces, and gives
> the values listed bellow.
> 
> I'm getting the following error, but don't see why. Can anyone spot
> my error?
> 
> Please, enter numbers separated by spaces only!: Bad file descriptor
> at E:/www/cgi-bin/pg93ex3.11SeriesOfNumbers.pl line 14.
> 
> I've narrowed the problem down to the "if" block (the regex), I'd like
> to accept numbers and spaces only. Here's the code:
> 
> #!E:/www/perl/bin/perl.exe
> 
> use strict;
> use warnings;
> use CGI qw( :standard );
> use CGI::Carp qw( fatalsToBrowser );
>  print header();
>  
>  my $userIn = param( "textfield" );
>  
> if ( $userIn =~ /^(\d+|\s*)$/ ) {
>  $userIn = $1;
> } else {
>  die "Please, enter numbers separated by spaces only!: $!";

Your problem is that you are using the $! variable:

perldoc perlvar
[snip]
   $!  If used numerically, yields the current value of the C "errno"
   variable, or in other words, if a system or library call fails,
   it sets this variable.  This means that the value of $! is
   meaningful only immediately after a failure:


But you are using it for a pattern match failure which is neither a system nor
a library call.


> }
> 
> my @numbers = split( / /, $userIn );

I would write that as:

my @numbers = $userIn =~ /\d+/g;
@numbers or die "Please, enter numbers separated by spaces only!";


> my $total = scalar( @numbers );

"my $total =" forces scalar context so using the scalar() function is redundant.

> my @sorted = sort( @numbers );
> my $smallestNum =   @sorted[0];
> my $largestNum = @sorted[-1];

perldoc -q difference
Found in /usr/lib/perl5/5.8.6/pod/perlfaq4.pod
   What is the difference between $array[1] and @array[1]?

   The former is a scalar value; the latter an array slice, making it a
   list with one (scalar) value.  You should use $ when you want a scalar
   value (most of the time) and @ when you want a list with one scalar
   value in it (very, very rarely; nearly never, in fact).

   Sometimes it doesn’t make a difference, but sometimes it does.  For
   example, compare:

   $good[0] = ‘some program that outputs several lines‘;

   with

   @bad[0]  = ‘same program that outputs several lines‘;

   The "use warnings" pragma and the −w flag will warn you about these
   matters.


Or you could write those three lines like this:

my ( $smallestNum, $largestNum ) = sort @numbers;

But since you are sorting numbers, you probably want to do a numeric sort to
get the correct numbers:

my ( $smallestNum, $largestNum ) = sort { $a <=> $b } @numbers;


And of course you can do that more efficiently using a for loop:

my ( $smallestNum, $largestNum ) = @numbers[ 0, 0 ];
for ( @numbers ) {
$smallestNum = $_ if $smallestNum > $_;
$largestNum  = $_ if $largestNum  < $_;
}


>  my $sum = 0;
>  foreach ( @numbers ) {
>   $sum += $_;
> }
> 
> my $average = ( $sum / $total );

You could just use the array there as a mathematical expression forces scalar
context:

my $average = ( $sum / @numbers );




John
-- 
use Perl;
program
fulfillment

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




Re: Error in the "if" block

2006-02-19 Thread John W. Krahn
Ron Smith wrote:
> Hi all,

Hello,

> This page accepts a series of numbers, separated by spaces, and gives
> the values listed bellow.
> 
> I'm getting the following error, but don't see why. Can anyone spot
> my error?
> 
> Please, enter numbers separated by spaces only!: Bad file descriptor
> at E:/www/cgi-bin/pg93ex3.11SeriesOfNumbers.pl line 14.
> 
> I've narrowed the problem down to the "if" block (the regex), I'd like
> to accept numbers and spaces only. Here's the code:
> 
> #!E:/www/perl/bin/perl.exe
> 
> use strict;
> use warnings;
> use CGI qw( :standard );
> use CGI::Carp qw( fatalsToBrowser );
>  print header();
>  
>  my $userIn = param( "textfield" );
>  
> if ( $userIn =~ /^(\d+|\s*)$/ ) {
>  $userIn = $1;
> } else {
>  die "Please, enter numbers separated by spaces only!: $!";

Your problem is that you are using the $! variable:

perldoc perlvar
[snip]
   $!  If used numerically, yields the current value of the C "errno"
   variable, or in other words, if a system or library call fails,
   it sets this variable.  This means that the value of $! is
   meaningful only immediately after a failure:


But you are using it for a pattern match failure which is neither a system nor
a library call.


> }
> 
> my @numbers = split( / /, $userIn );

I would write that as:

my @numbers = $userIn =~ /\d+/g;
@numbers or die "Please, enter numbers separated by spaces only!";


> my $total = scalar( @numbers );

"my $total =" forces scalar context so using the scalar() function is redundant.

> my @sorted = sort( @numbers );
> my $smallestNum =   @sorted[0];
> my $largestNum = @sorted[-1];

perldoc -q difference
Found in /usr/lib/perl5/5.8.6/pod/perlfaq4.pod
   What is the difference between $array[1] and @array[1]?

   The former is a scalar value; the latter an array slice, making it a
   list with one (scalar) value.  You should use $ when you want a scalar
   value (most of the time) and @ when you want a list with one scalar
   value in it (very, very rarely; nearly never, in fact).

   Sometimes it doesn't make a difference, but sometimes it does.  For
   example, compare:

   $good[0] = 'some program that outputs several lines';

   with

   @bad[0]  = 'same program that outputs several lines';

   The "use warnings" pragma and the -w flag will warn you about these
   matters.


Or you could write those three lines like this:

my ( $smallestNum, $largestNum ) = sort @numbers;

But since you are sorting numbers, you probably want to do a numeric sort to
get the correct numbers:

my ( $smallestNum, $largestNum ) = sort { $a <=> $b } @numbers;


And of course you can do that more efficiently using a for loop:

my ( $smallestNum, $largestNum ) = @numbers[ 0, 0 ];
for ( @numbers ) {
$smallestNum = $_ if $smallestNum > $_;
$largestNum  = $_ if $largestNum  < $_;
}


>  my $sum = 0;
>  foreach ( @numbers ) {
>   $sum += $_;
> }
> 
> my $average = ( $sum / $total );

You could just use the array there as a mathematical expression forces scalar
context:

my $average = ( $sum / @numbers );




John
-- 
use Perl;
program
fulfillment

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




Re: Error in the "if" block

2006-02-19 Thread John W. Krahn
Ron Smith wrote:
Hans Meier (John Doe) wrote:
>>
>>The if-else could be shortened to (untested, so
>>please check):
>>
>>die "Bla" unless
>>($userIn)=$userIn=~/^\s*((?:\d+\s*?)+)\s*$/;
>
> Right; a lot shorter. Why, the parentheses around
> $userIn?

Context.  Without the parentheses you have scalar context but with the
parentheses you have list context.  In scalar context the match operator
returns 'true' or 'false' but in list context it returns the contents of all
capturing parentheses in the pattern.


John
-- 
use Perl;
program
fulfillment

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




Re: perl with databases

2006-02-19 Thread Owen Cook

On Sun, 19 Feb 2006, Octavian Rasnita wrote:
> 
> I need to recommend/use a better database than MySQL that should work well
> with perl.
> I have read some web pages about PostgreSQL and I have seen that it has a
> procedural language PLPERL, while Oracle doesn't have such a thing. I have
> also seen that Oracle is a little better than PostgreSQL.
> 
> The database I need to keep is not very very big, but too big for MySQL, and
> the most important thing is the speed of selections/updates.
> 
> Is the fact that Oracle doesn't have an internal support for perl but just
> for Java an important thing?
> Are important the advantages of Oracle over PostgreSQL?


I suggest you use Matt Sergeant's DBD::SQLite a Self Contained RDBMS in a
DBI Driver.

It rocks


Owen


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




Re: Error in the "if" block

2006-02-19 Thread Hans Meier (John Doe)
Ron Smith am Sonntag, 19. Februar 2006 21.27:
> I changed this too. Thanks, Hans!
>
> > [irrelevant parts snipped away]

The "irrelevant" was not quite true...

As always, John W. Krahn looked closer into the code, finds simpler solutions 
and does not miss to point to the appropriate documentation - if in doubt, 
take his advice :-)

Greetings
Hans

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




[OT] Re: perl with databases

2006-02-19 Thread Hans Meier (John Doe)
Owen Cook am Sonntag, 19. Februar 2006 22.21:
> I suggest you use Matt Sergeant's DBD::SQLite a Self Contained RDBMS in a
> DBI Driver.
>
> It rocks

Owen, thanks a lot for this tip!!!
The aggregate function feature looks very promising
:-)

Hans

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




end of line

2006-02-19 Thread Bowen, Bruce
I have a text file with lines of varying length. 

000,;,001,WL0,001,001,000,000,000,000
011,@D 
,011,000,001,050,050,105,105,004,004,064,255,000,001,116,255,255,255,106,255,255,255,255,116,255,255,255
012,D,038,032,000,002,000,001,000,000
013,@D 
,013,000,001,050,050,105,105,004,004,064,255,000,001,091,255,255,255,106,255,255,255,255,091,255,255,255

According to a hex editor each line ends with a hex 0D 0A.

I can index into this file searching for items such as 012,D or 011,@D. 
 $a = index($data, "011,[EMAIL PROTECTED]");

 What I need to do once the line is found is to isolate that one line.  I can 
do a substr starting at the index and that eliminates all data in front of the 
subject line, but then it contains all of the data past, to the end of the 
file. 
  $sub1 = substr($data, $a);

 My first attempt was to then try and index on "/\n" and that indicated it 
could not find that character.
  $in = index($sub1, "/\n");

  I then tried 0x0D could find that and then 0x0A and while it seemed to find 
that character it wasn't the index was only half way into the line not at the 
end of the line as I expected.
  $in = index($sub1, 0x0D); result was a -1

  $in = index($sub1, 0x0A); result was 28 which if used to get a second substr

  $sub2 = substr($sub1, 0, $in);

yields 011,@D ,011,000,001,050,050,

Anyone got a clue as to what is going on?

Thanks,
Bruce Bowen



Re: end of line

2006-02-19 Thread Owen Cook

On Sun, 19 Feb 2006, Bowen, Bruce wrote:

> I have a text file with lines of varying length. 
> 
> 000,;,001,WL0,001,001,000,000,000,000
> 011,@D 
> ,011,000,001,050,050,105,105,004,004,064,255,000,001,116,255,255,255,106,255,255,255,255,116,255,255,255
> 012,D,038,032,000,002,000,001,000,000
> 013,@D 
> ,013,000,001,050,050,105,105,004,004,064,255,000,001,091,255,255,255,106,255,255,255,255,091,255,255,255
> 
> According to a hex editor each line ends with a hex 0D 0A.
> 
> I can index into this file searching for items such as 012,D or 011,@D. 
>  $a = index($data, "011,[EMAIL PROTECTED]");
> 
>  What I need to do once the line is found is to isolate that one line.  I can 
> do a substr starting at the index and that eliminates all data in front of 
> the subject line, but then it contains all of the data past, to the end of 
> the file. 
>   $sub1 = substr($data, $a);
> 
>  My first attempt was to then try and index on "/\n" and that indicated it 
> could not find that character.
>   $in = index($sub1, "/\n");
> 
>   I then tried 0x0D could find that and then 0x0A and while it seemed to find 
> that character it wasn't the index was only half way into the line not at the 
> end of the line as I expected.
>   $in = index($sub1, 0x0D); result was a -1
> 
>   $in = index($sub1, 0x0A); result was 28 which if used to get a second substr
> 
>   $sub2 = substr($sub1, 0, $in);
> 
> yields 011,@D ,011,000,001,050,050,
> 
> Anyone got a clue as to what is going on?


You need to look at 'chomp'

while(){
chomp;
my $line=$_;
#do something with $line
}


Try something along those lines



Owen


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




Re: end of line

2006-02-19 Thread Xavier Noria

On Feb 19, 2006, at 23:32, Bowen, Bruce wrote:


I have a text file with lines of varying length.

000,;,001,WL0,001,001,000,000,000,000
011,@D , 
011,000,001,050,050,105,105,004,004,064,255,000,001,116,255,255,255,10 
6,255,255,255,255,116,255,255,255

012,D,038,032,000,002,000,001,000,000
013,@D , 
013,000,001,050,050,105,105,004,004,064,255,000,001,091,255,255,255,10 
6,255,255,255,255,091,255,255,255


According to a hex editor each line ends with a hex 0D 0A.

I can index into this file searching for items such as 012,D or  
011,@D.

 $a = index($data, "011,[EMAIL PROTECTED]");

 What I need to do once the line is found is to isolate that one line.


A possible idiom is:

   my @lines  = <>; # slurp all lines
   my @wanted = grep { m'012,D|011,@D' } @lines;

If the file is too big:

   my @wanted = ();
   while (my $line = <>) {
   push @wanted, $line if $line =~ m'012,D|011,@D';
   }

You get the idea.

-- fxn

PS: Untested examples.

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




Re: perl with databases

2006-02-19 Thread Alan C
On Sunday 19 February 2006 12:56, Octavian Rasnita wrote:
[ . . ]
> The database I need to keep is not very very big, but too big for MySQL,
> and the most important thing is the speed of selections/updates.
[ . . ]

DB_File  and  BerkelyDB

are two Perl modules that use the embedded database which is at/from

http://www.google.com/search?q=sleepycat+software&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official

Oracle just recently bought out Sleepycat.

But this is not SQL.  But it is fast and it's used for lots of things.

You would need to compare your need for this versus your need for SQL and
then choose which one of the two based on what your needs are.

--
Alan.


Re: Net::Server

2006-02-19 Thread Hans Meier (John Doe)
Tom Allison am Samstag, 18. Februar 2006 21.27:
> I am trying to set up a server using Net::Server.
> Mostly this is out of curiousity more than anything else.
> But following the man pages I got stuck.
>
> I was trying to set up a server to connect to port 8081,
> but none of the configuration options I've put in below appear in the file
> I'm running.

Ok, since nobody else answered... I didn't have a thorough look at the module. 
Maybe my ideas help, but I doubt it a bit:


What about

package  Net::Server::AuthServer;

?

> use strict;
> use warnings;
> use Net::Server;
> use Data::Dumper;
> use vars [EMAIL PROTECTED];
> @ISA = qw[Net::Server];
>
> my $server = bless {
>port=> '8081',
>log_level   => '4',
>reverse_lookups => '1',
>pid_file=> '/var/run/net_test.pid',
>listen  => '16',
>user=> 'nobody',
>group   => 'nobody',
> }, 'AuthServer';

}, 'Net::Server::AuthServer';

?

> print Dumper($server);
>
> $server->run();
>
> ##
>
> The output shows up as:
>
> [EMAIL PROTECTED]:~$ perl -w -T net_test.pl
> $VAR1 = bless( {
>   'group' => 'nobody',
>   'pid_file' => '/var/run/net_test.pid',
>   'listen' => '16',
>   'log_level' => '4',
>   'reverse_lookups' => '1',
>   'user' => 'nobody',
>   'port' => '8081'
> }, 'AuthServer' );

This is ok, since you dump from the actual namespace a variable defined in the 
same namespace.


Did you have a look into the source code of the provided subclasses of 
Net::Server (Net::Server::PreforkSimple etc.).
This may help.

hth,
Hans

> 2006/02/18-15:22:15 AuthServer (type Net::Server) starting! pid(5506)
> Port Not Defined.  Defaulting to '20203'
> Binding to TCP port 20203 on host *
> Group Not Defined.  Defaulting to EGID '1000 1000 44 40 29 25 24 20'
> User Not Defined.  Defaulting to EUID '1000'
>
> #
>
> It's pretty clear that it's not really taking any queues from me.
> I'm just taking my queues from the man pages.
> Should I take my queues from someplace else?

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




Re: end of line

2006-02-19 Thread John W. Krahn
Bowen, Bruce wrote:
> I have a text file with lines of varying length. 

Most text files are like that.

> 000,;,001,WL0,001,001,000,000,000,000
> 011,@D 
> ,011,000,001,050,050,105,105,004,004,064,255,000,001,116,255,255,255,106,255,255,255,255,116,255,255,255
> 012,D,038,032,000,002,000,001,000,000
> 013,@D 
> ,013,000,001,050,050,105,105,004,004,064,255,000,001,091,255,255,255,106,255,255,255,255,091,255,255,255
> 
> According to a hex editor each line ends with a hex 0D 0A.

Then set the Input Record Separator to OD OA

$/ = "\x0D\x0A";



John
-- 
use Perl;
program
fulfillment

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




Re: Net::Server

2006-02-19 Thread Tom Phoenix
On 2/18/06, Tom Allison <[EMAIL PROTECTED]> wrote:

> I am trying to set up a server using Net::Server.

I believe that you omitted a vital piece at the top of your code: a
package directive.

package AuthServer;

Without that, your @ISA variable isn't @AuthServer::ISA. But that's
not the error you're getting, so I think it was omitted when you
cut-and-pasted. With that line, I get the same results you do.

Other than that omission, I don't see that you're doing anything other
than what the docs suggest. Which version are you using? If it's below
version 1.0 (I found version 0.9 on CPAN) the documentation,
interface, or other key features are perhaps flawed or missing. Maybe
the interface is different than the documentation shows; none of the
tests (in the t directory) looks at a glance to be similar to the code
that the documentation shows.

There's a maintainer's email address in the README. It's not out of
line to ask that a module's documentation should contain a smidgen of
working example code. :-)  Have you written to that address yet?

As an alternative, there may be another module on CPAN which is
complete and debugged, or you could perhaps make your own module. Good
luck, and let us know how it turns out!

--Tom Phoenix
Stonehenge Perl Training

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




Re: populating a Hash

2006-02-19 Thread John W. Krahn
David Gilden wrote:
> Good morning,

Hello,

> I would like to populate a hash from a csv text file,

Do you really think that you need to?

> then test for the existence  of a value in the hash.

A value?  Or a key?

perldoc -f exists

> If not found return an error message and exit.
> 
> 
> ithe text file will have the format of:
> # whitelist created 2/18/06 or some other comment on the first line
> name1,nick1
> ---
> name25,nick25
> ---
> 
> my $approvedUser = pram('approvedUser'); # cgi.pm
> 
> my $whitelist = './'whitelist.txt;

That is a syntax error, perhaps you meant:

my $whitelist = './whitelist.txt';

> my %hash
> 
> open(EL,"$whitelist") ||  &errorMessage( "Read in, Could not find $whitelist, 
> $!");

perldoc -q quoting

You are using an ampersand on the subroutine which has certain side-effects
that may not be desirable.

perldoc perlsub

> my @lines = ;

You are reading the whole file into memory but that is not really nessesary.

> close(EL);
> 
> foreach(@lines){
> next if /#/;
> my($key,$val)= split (@lines,",");

perldoc -f split
   split /PATTERN/,EXPR,LIMIT

split() uses the first argument as a regular expression pattern so assuming
@lines has 23 elements in it, it will be converted to the number 23 and that
will be used as the pattern to split on:

my($key,$val)= split (/23/,",");

Since the string "," has no '23' (or any digits at all) in it, it will be
returned unaltered and assigned to the $key variable.

>$hash{$key} = $val;
>  }
> close(EL);
> 
> if (!defined $approvedUser =~ %hash){

The expression to the right of the binding operator (=~) will be treated as a
regular expression pattern and a hash in scalar context evaluates to a number
so your expression is something like:

if ( !defined $approvedUser =~ m-5/8- ){

The match operator will never return an undefined value so your error message
will never print.

> &errorMessage( "your not an authorized user")
> }
> 
> 
> errorMessage(message){

perldoc perlsub

If you want to define a subroutine you have to use:

sub errorMessage {

> shift;

shift() removes the first element of an array and returns it.  Inside a
subroutine, if you don't specify an array it defaults to the @_ array which
contains all the values passed to the subroutine.  You are not assigning the
return value of shift() to a variable so it disappears.

> print "$_\n";

You have not assigned a value to $_ so nothing (except a newline) will be 
printed.

> exit;

You should usually exit() with a value that signifies success or failure.
Most OSs use zero for success and a non-zero value for failure.

> }
> 
> 
> How close am I to having a working script, I have guessed at some of syntax 
> here, and am not familiar 
> with using 'defined'.

If you just want to see if a certain name is present in the file you can do
something like this:

use warnings;
use strict;

sub errorMessage {
my $message = shift;
print "$message\n";
exit 1;
}

my $approvedUser = param( 'approvedUser' ); # cgi.pm
my $whitelist = 'whitelist.txt';
open EL, '<', $whitelist
or errorMessage( "Read in, Could not open $whitelist, $!");

my ( $key, $val );
while (  ) {
next if /#/;
( $key, $val ) = /^([^,]+),(.+)/;
last if $approvedUser eq $key;
}

errorMessage( 'you are not an authorized user' )
unless defined $key;

__END__


If you do really need a hash then:

use warnings;
use strict;

sub errorMessage {
my $message = shift;
print "$message\n";
exit 1;
}

my $approvedUser = param( 'approvedUser' ); # cgi.pm
my $whitelist = 'whitelist.txt';
open EL, '<', $whitelist
or errorMessage( "Read in, Could not open $whitelist, $!");

my %hash;
while (  ) {
next if /#/;
my ( $key, $val ) = /^([^,]+),(.+)/;
$hash{ $key } = $val;
}

errorMessage( 'you are not an authorized user' )
unless exists $hash{ $approvedUser };

__END__




John
-- 
use Perl;
program
fulfillment

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




dual core cpu

2006-02-19 Thread Ken Perl
Does perl support dual core cpu(HT) technology?
--
perl -e 'print unpack(u,"62V5N\"FME;G\!Ehttp://learn.perl.org/> 




Re: dual core cpu

2006-02-19 Thread Owen Cook

On Mon, 20 Feb 2006, Ken Perl wrote:

> Does perl support dual core cpu(HT) technology?
> --
> perl -e 'print unpack(u,"62V5N\"FME;G\!E ")'


As an observer, I would say yes.

When you configure CPAN, I think it asks a question "How many cores do you
have...press enter if you don't understand this question" The letter
"j" appears

Also when you build perl, the config script asks a similiar question IIRC.



Owen 


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




Re: Error in the "if" block

2006-02-19 Thread Ron Smith
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
 
> Your problem is that you are using the $! variable:
> 
> But you are using it for a pattern match failure
> which is neither a system nor
> a library call.
> 
> > my @numbers = split( / /, $userIn );
> 
> I would write that as:
> 
> my @numbers = $userIn =~ /\d+/g;
> @numbers or die "Please, enter numbers separated by
> spaces only!";
> 
Yep. Actually, I had already followed your suggestion,
with the addition of "\n". But, it was to get rid of
the fact that "$!" was spitting out the file name.
Thanks, for an explaination behind the *real* reason I
should make the change.
> 
> > my $total = scalar( @numbers );
> 
> "my $total =" forces scalar context so using the
> scalar() function is redundant.

Thanks, I shortened this up too; scalar function gone.
[pg. 73 "Camel Book]
> 
> 
> But since you are sorting numbers, you probably want
> to do a numeric sort to
> get the correct numbers:
> 
> my ( $smallestNum, $largestNum ) = sort { $a <=> $b
> } @numbers;
>
I'm using: my @sorted = sort { $a <=> $b } @numbers;
Thanks, again. [pg. 790 "Camel Book"] This was
overlooked in my haste.
> 
> >  my $sum = 0;
> >  foreach ( @numbers ) {
> >   $sum += $_;
> > }
> > 
> > my $average = ( $sum / $total );
> 
> You could just use the array there as a mathematical
> expression forces scalar
> context:
> 
> my $average = ( $sum / @numbers );
>
This is bookmarked for future reference. Thanks, a lot
John. :-) 


Ron Smith
[EMAIL PROTECTED]

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




IP Number/ IP Address Array

2006-02-19 Thread overkill


I need to convert the first column of a list of IP numbers to IP addresses.  I 
created an array of my list but am stumped on how to convert the numbers.


File:
180884576   imstrmcs05
180884577   imstrmcs06
180884578   imstrmcs07
180884579   imstrmcs08
180884580   imstrmcs09
180884581   imstrmcs10


Script:
# Properly formatting into an array
open(IPLIST, "file") || die "couldn't open the file";

while ($x = )
{
chop $x;
@arr = split /\s+/,$x;
print "@arr\n";
}

# Converting IP number to IP address.
foreach $ipaddr {
$ip1 = int ($ipaddr / (256**3));
$ipaddr %= ($ip1 * 256**3);
$ip2 = int ($ipaddr / (256**2));
$ipaddr %= ($ip2 * 256**2);
$ip3 = int ($ipaddr /256);
$ip4 = $ipaddr % ($ip3 * 256);

$realip=$ip1 . "." . $ip2 . "." . $ip3 . "." . $ip4;
print "$realip\n";
}

close(IPLIST);


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




Matrix Average code / Module Avaialable ?

2006-02-19 Thread I BioKid
Dear All,

Is there any program/module to calculate matrix average

I have a matrix of NxN and I need to see the average of the same
for example

11 22 43 54 50
27 87 74 32 10
66 58 98 78 20
22 23 44 16 34

I have gone through Math::Matrix
http://search.cpan.org/~ulpfr/Math-Matrix-0.4/Matrix.pm

and Math::Cephes::Matrix - but none of them have a provison to do matrix
average calculation.

thanks in advance,
Happy Perl !!!
--
S Khadar
"Refrain from illusions, insist on work and not words,
patiently seek divine and scientific truth."


Re: Error in the "if" block

2006-02-19 Thread Ron Smith


--- "John W. Krahn" <[EMAIL PROTECTED]> wrote:

> Ron Smith wrote:
> Hans Meier (John Doe) wrote:
> >>
> >>The if-else could be shortened to (untested, so
> >>please check):
> >>
> >>die "Bla" unless
> >>($userIn)=$userIn=~/^\s*((?:\d+\s*?)+)\s*$/;
> >
> > Right; a lot shorter. Why, the parentheses around
> > $userIn?
> 
> Context.  Without the parentheses you have scalar
> context but with the
> parentheses you have list context.  In scalar
> context the match operator
> returns 'true' or 'false' but in list context it
> returns the contents of all
> capturing parentheses in the pattern.

Thanks.
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 
> 
> 
> 


Ron Smith
[EMAIL PROTECTED]

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




Re: end of line

2006-02-19 Thread Xavier Noria

On Feb 20, 2006, at 0:39, Bowen, Bruce wrote:


A possible idiom is:

my @lines  = <>; # slurp all lines
my @wanted = grep { m'012,D|011,@D' } @lines;

*
I tried
open STATE, "STATEFILE.txt" or die
my @lines = ;
my $state = grep {m"011.,"} @lines
print "state = ", $state, "\n";

And I get state = 1
No errors but not the output I'm looking for.


Note that there was an array @wanted in my example, that makes a  
difference:


open my $st, "STATEFILE.txt" or die $!;
my @lines = <$st>;
close $st;

my @states = grep { /011.,/ } @lines;
print "state = $_" for @states;

That can be done in the command line as well (the example uses Unix  
shell quotes, adapt to Windows if needed):


$ perl -ne 'print qq(state = $_) if /011.,/' < STATEFILE.txt

-- fxn


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




IP Number/ IP Address Array

2006-02-19 Thread overkill

Greetings,

I need to convert the first column of a list of IP numbers to IP 
addresses.  I created an array of my list but am stumped on how to convert 
the numbers.


File:
180884576   imstrmcs05
180884577   imstrmcs06
180884578   imstrmcs07
180884579   imstrmcs08
180884580   imstrmcs09
180884581   imstrmcs10


Script:
# Properly formatting into an array
open(IPLIST, "file") || die "couldn't open the file";

while ($x = )
{
chop $x;
@arr = split /\s+/,$x;
print "@arr\n";
}

# Converting IP number to IP address.
foreach $ipaddr {
$ip1 = int ($ipaddr / (256**3));
$ipaddr %= ($ip1 * 256**3);
$ip2 = int ($ipaddr / (256**2));
$ipaddr %= ($ip2 * 256**2);
$ip3 = int ($ipaddr /256);
$ip4 = $ipaddr % ($ip3 * 256);

$realip=$ip1 . "." . $ip2 . "." . $ip3 . "." . $ip4;
print "$realip\n";
}

close(IPLIST);


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