cgi script to capture http headers

2006-09-28 Thread Kaushal Shriyan

Hi ALL

I have a issue

when i use script (test.cgi)

#!/bin/bash
echo Content-type: text/plain;
echo
set

I get all the http headers populated with the values correctly

but when I use the below script (test-cgi)

#!/bin/sh

# disable filename globbing
set -f

echo Content-type: text/plain
echo

echo CGI/1.0 test script report:
echo

echo argc is $#. argv is $*.
echo

echo SERVER_SOFTWARE = $SERVER_SOFTWARE
echo SERVER_NAME = $SERVER_NAME
echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo REQUEST_METHOD = $REQUEST_METHOD
echo HTTP_ACCEPT = $HTTP_ACCEPT
echo PATH_INFO = $PATH_INFO
echo PATH_TRANSLATED = $PATH_TRANSLATED
echo SCRIPT_NAME = $SCRIPT_NAME
echo QUERY_STRING = $QUERY_STRING
echo REMOTE_HOST = $REMOTE_HOST
echo REMOTE_ADDR = $REMOTE_ADDR
echo REMOTE_USER = $REMOTE_USER
echo AUTH_TYPE = $AUTH_TYPE
echo CONTENT_TYPE = $CONTENT_TYPE
echo CONTENT_LENGTH = $CONTENT_LENGTH

I dont get values for REMOTE_HOST = and REMOTE_USER =

I am calling the script http://mydomain.com/cgi-bin/test-cgi

Please let me know if you need any information

Thanks and Regards

Kaushal

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: cgi script to capture http headers

2006-09-28 Thread Beginner
Hi

On 28 Sep 2006 at 17:21, Kaushal Shriyan wrote:

 Hi ALL
 
 I have a issue
 
 when i use script (test.cgi)
 
 #!/bin/bash
 echo Content-type: text/plain;
 echo
 set
 
 I get all the http headers populated with the values correctly
 
 but when I use the below script (test-cgi)
 
 #!/bin/sh
 
 # disable filename globbing
 set -f


 I dont get values for REMOTE_HOST = and REMOTE_USER =
 
 I am calling the script http://mydomain.com/cgi-bin/test-cgi
 
 Please let me know if you need any information
 
 Thanks and Regards
 
 Kaushal

I think the first point is that your not using Perl !!! This is a 
list 4 perl not shell scripting.

Secondly remote_user is not always avaiable.

Lastly you could try:

#!/usr/bin/perl

use strict;
use warnings;
use CGI qw/:standard/;
 
my $q = new CGI;
print $q-header(-type='text/html');
print $q-start_html('test');

print remote_host();

print $q-end_html;

After that I would tenatively suggest doing some basic reading on the 
subject (CGI and/or Perl/CGI).

Good luck.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




please advise help with regex

2006-09-28 Thread Gregory Machin

Hi
I need to parse the logs for my named server. i'm having difficulty getting
my mind around the regex to break the data up .. i want the break it up and
store it in a data base then maniptulate the data from there ...
|date   | time   |catagory|severity|client   |ip
|port   |view||query
|
28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view
internal: updating zone 'lan.linserv.co.za/IN': adding an RR at '
greg.lan.linserv.co.za' A

any ideas ?

Many thanks



--
Gregory Machin
[EMAIL PROTECTED]
www.linuxpro.co.za


Re: please advise help with regex

2006-09-28 Thread Rob Dixon

Gregory Machin wrote:
 Hi
 I need to parse the logs for my named server. i'm having difficulty getting
 my mind around the regex to break the data up .. i want the break it up and
 store it in a data base then maniptulate the data from there ...
 |date   | time   |catagory|severity|client   |ip
 |port   |view||query
 |
 28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view
 internal: updating zone 'lan.linserv.co.za/IN': adding an RR at '
 greg.lan.linserv.co.za' A

 any ideas ?

Hi Gregory

It looks like your data fields are separated by a colon and a space, except for
the first three. Is there really nothing at all between the milliseconds and the
'category' field?

Anyway, assuming the data I have is correct (it's difficult to tell with the
wrapping that the various email systems apply) the code below should do what you
want. It works by splitting on, as I said, colon and whitespace, and then
pulling off the first field and splitting it again into three based on the
contents of these fields' data. You also seem to want the client field split
into 'client', IP address and port number, so I've pulled that field out and
split it up as well.

Hope it helps,

Rob



use strict;
use warnings;

while (DATA) {

  chomp;

  my @data = split /:\s+/;

  my $prefix = $data[0];
  splice @data, 0, 1, $prefix =~ /(\S+)\s+([0-9:.]+)(.+)/;

  my $client = $data[-4];
  splice @data, -4, 1, $client =~ /[^\s#]+/g;

  print $_\n foreach @data;
}

__DATA__
28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view internal: 
updating zone 'lan.linserv.co.za/IN': adding an RR at 'greg.lan.linserv.co.za' A


**OUTPUT**

28-Sep-2006
10:10:57.266
update
info
client
192.168.1.170
33364
view internal
updating zone 'lan.linserv.co.za/IN'
adding an RR at 'greg.lan.linserv.co.za' A

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: please advise help with regex

2006-09-28 Thread Gregory Machin

i have been playing... will this work and wich is more efficient ?

/^([0-3][0-9]\-
   #day-|
   (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+#month
|
   \-(20)[0-9][0-9]\s+
   #year till 2099 |
  [0-9][0-9]\:
   #hour |= date and time
   [0-9][0-9]\:
   #miniute |
   [0-9][0-9]\:)
   #hour-|
   ((\.\d{3})?
   #milliseconds
   (\w\:)
   #catagory- catagory
   (\s+\w\:)
   #severity- serverity
   (\w\s+)
   #host- host
   (s+\d+\.\d+\.\d+\.\d+)
#ip- ip
   (\#\d+/i)
   #port- port
   (\:\s+\s\w\s\w\:)#view
   - view
   (\s+[:alpha:]/)#query
   - query


On 9/28/06, Rob Dixon [EMAIL PROTECTED] wrote:


Gregory Machin wrote:
 Hi
 I need to parse the logs for my named server. i'm having difficulty
getting
 my mind around the regex to break the data up .. i want the break it up
and
 store it in a data base then maniptulate the data from there ...
 |date   | time   |catagory|severity|client   |ip
 |port   |view||query
 |
 28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view
 internal: updating zone 'lan.linserv.co.za/IN': adding an RR at '
 greg.lan.linserv.co.za' A

 any ideas ?

Hi Gregory

It looks like your data fields are separated by a colon and a space,
except for
the first three. Is there really nothing at all between the milliseconds
and the
'category' field?

Anyway, assuming the data I have is correct (it's difficult to tell with
the
wrapping that the various email systems apply) the code below should do
what you
want. It works by splitting on, as I said, colon and whitespace, and then
pulling off the first field and splitting it again into three based on the
contents of these fields' data. You also seem to want the client field
split
into 'client', IP address and port number, so I've pulled that field out
and
split it up as well.

Hope it helps,

Rob



use strict;
use warnings;

while (DATA) {

   chomp;

   my @data = split /:\s+/;

   my $prefix = $data[0];
   splice @data, 0, 1, $prefix =~ /(\S+)\s+([0-9:.]+)(.+)/;

   my $client = $data[-4];
   splice @data, -4, 1, $client =~ /[^\s#]+/g;

   print $_\n foreach @data;
}

__DATA__
28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view
internal:
updating zone 'lan.linserv.co.za/IN': adding an RR at '
greg.lan.linserv.co.za' A

**OUTPUT**

28-Sep-2006
10:10:57.266
update
info
client
192.168.1.170
33364
view internal
updating zone 'lan.linserv.co.za/IN'
adding an RR at 'greg.lan.linserv.co.za' A

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response






--
Gregory Machin
[EMAIL PROTECTED]
www.linuxpro.co.za


cgi script

2006-09-28 Thread Kaushal Shriyan

Hi ALL

I have a issue when i use script (test.cgi)

#!/bin/bash
echo Content-type: text/plain;
echo
set

I get all the http headers populated with the values correctly

but when I use the below script (test-cgi)

#!/bin/sh

# disable filename globbing
set -f

echo Content-type: text/plain
echo

echo CGI/1.0 test script report:
echo

echo argc is $#. argv is $*.
echo

echo SERVER_SOFTWARE = $SERVER_SOFTWARE
echo SERVER_NAME = $SERVER_NAME
echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo REQUEST_METHOD = $REQUEST_METHOD
echo HTTP_ACCEPT = $HTTP_ACCEPT
echo PATH_INFO = $PATH_INFO
echo PATH_TRANSLATED = $PATH_TRANSLATED
echo SCRIPT_NAME = $SCRIPT_NAME
echo QUERY_STRING = $QUERY_STRING
echo REMOTE_HOST = $REMOTE_HOST
echo REMOTE_ADDR = $REMOTE_ADDR
echo REMOTE_USER = $REMOTE_USER
echo AUTH_TYPE = $AUTH_TYPE
echo CONTENT_TYPE = $CONTENT_TYPE
echo CONTENT_LENGTH = $CONTENT_LENGTH

I dont get values for REMOTE_HOST = and REMOTE_USER =

I am calling the script http://mydomain.com/cgi-bin/test-cgi

Please let me know if you need any information

Thanks and Regards

Kaushal

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




why Perl complaints my script

2006-09-28 Thread chen li
Hi all,

I write a small script for permutation. When I use
version 1) Perl always complaint it although I get the
result. If I use version 2) it never says a word about
it. Any comments?

Thank you in advance,

Li

version 1)###

use strict;
use warnings;

print permutation(5,2); # 5 choose 2

exit;

#subroutine permutation

sub permutation{

 my ($n, $k)[EMAIL PROTECTED];
my $result=1;

for ($k; $k=1;$k--) {$result*=$n--;}#line 15
return  $result; 
}

#screen output
Useless use of private variable in void context at
fac1.pl line 15.
20


version 2)###

use strict;
use warnings;

print permutation(5,2); # 5 choose 2

exit;

###subroutine permutation##

sub permutation{

my $n=shift;
my $result=1;

for (my $k=shift; $k=1;$k--) {$result*=$n--;}
return  $result; 
}

###screen output

20

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why Perl complaints my script

2006-09-28 Thread Igor Sutton


for ($k; $k=1;$k--) {$result*=$n--;}#line 15



You don't need to declare $k inside for (). Change that to

for (; $k = 1; $k--)

and perl won't complain about it anymore. I think the place before the first
';' is used for declaring any variables inside the lexical scope of for.
Maybe someone could explain this better?

--
Igor Sutton Lopes [EMAIL PROTECTED]


Re: interpoliation within regexp

2006-09-28 Thread Derek B. Smith
--- Derek B. Smith [EMAIL PROTECTED]
wrote:

 I need to substitute a conversion using chr, but
 have
 failed on multiple attempts.  Basically if the first
 element contains a # then convert it. Will anyone
 advise?
 
 thank you
 derek
 
 #if first char is a-z then print it else warn
 #chop string into individual characters
 
 my @chars  = unpack
 (A1 x length($password),$password);
 
 if ($chars[0] =~ /^\D/) {
   print Your new string is:\t,@chars,\n;
 }
 else {
   print string starts with number, now
 converting\n,
 @chars, \n;
   substr($chars[0],0,1) =~
 s/\Q{$chars[0]}/{chr($chars[0]}\E/;
   print @chars;
 }
 

I will try to use the /e modifier as such:

s/(\$\w+)/$1/e;

An explanation is below:
/e
 Righthand side of a s/// is code to eval
 
/ee
 Righthand side of a s/// is a string to eval, then
run as code, and its return value eval'led again.
 



__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why Perl complaints my script

2006-09-28 Thread Adriano Ferreira

On 9/28/06, chen li [EMAIL PROTECTED] wrote:

Hi all,

I write a small script for permutation. When I use
version 1) Perl always complaint it although I get the
result. If I use version 2) it never says a word about
it. Any comments?


Perl always complain (provided you called for that with -w or use
warnings) when you do something like that:

$ perl -w -e 'my $a; $a'
Useless use of a variable in void context at -e line 1

This is meant to warn you about a probable mistake:
you may have meant
 $a++
 a# to invoke a sub
or something like that. As Igor has said the first statement in the
for is often used for declaring loop variables or, more generally, for
loop initialization statements. If you don't have these initialization
statements, you may omit it.

Regards,
Adriano Ferreira

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why Perl complaints my script

2006-09-28 Thread Dr.Ruud
chen li schreef:

 for ($k; $k=1;$k--) {$result*=$n--;}

Alternative:

  $result *= $n-- for 1..$k ;

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why Perl complaints my script

2006-09-28 Thread chen li
Thanks,

Li

--- Dr.Ruud [EMAIL PROTECTED] wrote:

 chen li schreef:
 
  for ($k; $k=1;$k--) {$result*=$n--;}
 
 Alternative:
 
   $result *= $n-- for 1..$k ;
 
 -- 
 Affijn, Ruud
 
 Gewoon is een tijger.
 
 
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 http://learn.perl.org/
 http://learn.perl.org/first-response
 
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why Perl complaints my script

2006-09-28 Thread chen li
Thank you very much,

Li

--- Igor Sutton [EMAIL PROTECTED] wrote:

 
  for ($k; $k=1;$k--) {$result*=$n--;}#line
 15
 
 
 You don't need to declare $k inside for (). Change
 that to
 
 for (; $k = 1; $k--)
 
 and perl won't complain about it anymore. I think
 the place before the first
 ';' is used for declaring any variables inside the
 lexical scope of for.
 Maybe someone could explain this better?
 
 -- 
 Igor Sutton Lopes [EMAIL PROTECTED]
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why Perl complaints my script

2006-09-28 Thread chen li
Hi Andriano,

Thank you very much,

Li

--- Adriano Ferreira [EMAIL PROTECTED] wrote:

 On 9/28/06, chen li [EMAIL PROTECTED] wrote:
  Hi all,
 
  I write a small script for permutation. When I use
  version 1) Perl always complaint it although I get
 the
  result. If I use version 2) it never says a word
 about
  it. Any comments?
 
 Perl always complain (provided you called for that
 with -w or use
 warnings) when you do something like that:
 
 $ perl -w -e 'my $a; $a'
 Useless use of a variable in void context at -e line
 1
 
 This is meant to warn you about a probable mistake:
 you may have meant
   $a++
   a# to invoke a sub
 or something like that. As Igor has said the first
 statement in the
 for is often used for declaring loop variables or,
 more generally, for
 loop initialization statements. If you don't have
 these initialization
 statements, you may omit it.
 
 Regards,
 Adriano Ferreira
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 http://learn.perl.org/
 http://learn.perl.org/first-response
 
 
 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: cgi script

2006-09-28 Thread Tom Phoenix

On 9/28/06, Kaushal Shriyan [EMAIL PROTECTED] wrote:


#!/bin/bash
echo Content-type: text/plain;
echo
set


That's a shell script. You're not even using a Perl program; why are
you asking for help in a Perl beginners' forum?


I dont get values for REMOTE_HOST = and REMOTE_USER =


Are you sure that they're set?

If you'd like a Perl program that may answer some of your questions
about your CGI environment, try Inside:

   http://search.cpan.org/~phoenix/Inside-1.01/

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: interpoliation within regexp

2006-09-28 Thread Mumia W.

On 09/28/2006 08:16 AM, Derek B. Smith wrote:

--- Derek B. Smith [EMAIL PROTECTED]
wrote:


I need to substitute a conversion using chr, but
have
failed on multiple attempts.  Basically if the first
element contains a # then convert it. Will anyone
advise?

thank you
derek

#if first char is a-z then print it else warn
#chop string into individual characters

my @chars  = unpack
(A1 x length($password),$password);

if ($chars[0] =~ /^\D/) {
  print Your new string is:\t,@chars,\n;
}
else {
  print string starts with number, now
converting\n,
@chars, \n;
  substr($chars[0],0,1) =~
s/\Q{$chars[0]}/{chr($chars[0]}\E/;
  print @chars;
}



I will try to use the /e modifier as such:

s/(\$\w+)/$1/e;

An explanation is below:
/e
 Righthand side of a s/// is code to eval
 
/ee

 Righthand side of a s/// is a string to eval, then
run as code, and its return value eval'led again.
 



What does your input data look like, and what do you want the output to 
look like?




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: interpoliation within regexp

2006-09-28 Thread Derek B. Smith

-- Derek B. Smith [EMAIL PROTECTED]
wrote:

 --- Derek B. Smith [EMAIL PROTECTED]
 wrote:
 
  I need to substitute a conversion using chr, but
  have
  failed on multiple attempts.  Basically if the
 first
  element contains a # then convert it. Will anyone
  advise?
  
  thank you
  derek
  
  #if first char is a-z then print it else warn
  #chop string into individual characters
  
  my @chars  = unpack
  (A1 x length($password),$password);
  
  if ($chars[0] =~ /^\D/) {
print Your new string is:\t,@chars,\n;
  }
  else {
print string starts with number, now
  converting\n,
  @chars, \n;
substr($chars[0],0,1) =~
  s/\Q{$chars[0]}/{chr($chars[0]}\E/;
print @chars;
  }
  
 
 I will try to use the /e modifier as such:
 
 s/(\$\w+)/$1/e;
 
 An explanation is below:
 /e
  Righthand side of a s/// is code to eval
  
 /ee
  Righthand side of a s/// is a string to eval, then
 run as code, and its return value eval'led again.

*
The results I am getting when using data::dumper is:

string starts with number, now converting
6FhJ9Z
DUMP:   $VAR1 = 1;
DUMP2:  $VAR1 = ' ';
$VAR2 = 'F';
$VAR3 = 'h';
$VAR4 = 'J';
$VAR5 = '9';
$VAR6 = 'Z';
$VAR7 = '
';

from code:

## generate random 8 char string.
my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
my $password = join '', map { $a[int rand @a] } 0 ..
5;

#if first char is a-z then print it else warn
#chop string into individual characters

my @chars  = unpack (A1 x length($password),
$password);
if ($chars[0] =~ /^\D/) {
  print Your new string is:\t,@chars,\n;
}
else {
  print string starts with number, now converting\n,
@chars, \n;
  print DUMP:\t, Dumper(substr($chars[0],0,1) =~
s/$chars[0]/chr ($1)/e);
  print DUMP2:\t, Dumper @chars,\n;
}


Any help please on as to why chr is not working?
thx
derek














__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: interpoliation within regexp

2006-09-28 Thread Derek B. Smith
--- Mumia W. [EMAIL PROTECTED]
wrote:

 On 09/28/2006 08:16 AM, Derek B. Smith wrote:
  --- Derek B. Smith [EMAIL PROTECTED]
  wrote:
  
  I need to substitute a conversion using chr, but
  have
  failed on multiple attempts.  Basically if the
 first
  element contains a # then convert it. Will anyone
  advise?
 
  thank you
  derek
 
  #if first char is a-z then print it else warn
  #chop string into individual characters
 
  my @chars  = unpack
  (A1 x length($password),$password);
 
  if ($chars[0] =~ /^\D/) {
print Your new string is:\t,@chars,\n;
  }
  else {
print string starts with number, now
  converting\n,
  @chars, \n;
substr($chars[0],0,1) =~
  s/\Q{$chars[0]}/{chr($chars[0]}\E/;
print @chars;
  }
 
  
  I will try to use the /e modifier as such:
  
  s/(\$\w+)/$1/e;
  
  An explanation is below:
  /e
   Righthand side of a s/// is code to eval
   
  /ee
   Righthand side of a s/// is a string to eval,
 then
  run as code, and its return value eval'led again.
   
  
 
 What does your input data look like, and what do you
 want the output to 
 look like?
 
 
 
**
The input data is a 6 character randomized string that
could start with a # such as 6FhJ9Z.  If it does start
with a number then I need to convert this character
into its cooresponding alpha char, [a-z,A-Z].

The output data from the string 6FhJ9Z should be
[a-z,A-Z]FhJ9Z I guess what I am asking for is not
plausible after looking at the ASCII table b/c there
is no cooresponding letter for number 6. Silly me, ok
then maybe grab any [a-z,A-Z] character.

my $foo = pack(C*, 6); print $foo;
or
chr ('6'); 

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




hash slices

2006-09-28 Thread Gerald Host

I'm using DBI's selectall_hashref with 5 key columns.  I want to display
each row where key col 1 is 'yes' or NULL (undef or '' ?)


   foreach my $medCategory (keys
%{$href-{'yes'}-{qw('' 'yes')}-{qw('' 'yes')}}) {
   foreach my $med (keys
%{$href-{qw('yes')}-{qw('' 'yes')}-{qw('' 'yes')}-{$medCategory}}) {
  foreach my $ID (keys
%{$href-{qw('yes')}-{qw('' 'yes')}-{qw(''
'yes')}-{$medCategory}-{$med}}) {


print qq{ $href-{qw('yes')}-{qw(''
'yes')}-{qw('' 'yes')}-{$medCategory}-{$med}-{$ID}-{ID} };
print qq{ $href-{qw('yes')}-{qw(''
'yes')}-{qw('' 'yes')}-{$medCategory}-{$med}-{$ID}-{Medication} };
 }
}
   }

This isn't working of course because I don't quite understand the syntax I
need.  Can someone give me a hint?  Thanks!

Ryan


Re: hash slices

2006-09-28 Thread Rob Dixon

Gerald Host wrote:

 I'm using DBI's selectall_hashref with 5 key columns.  I want to display
 each row where key col 1 is 'yes' or NULL (undef or '' ?)


 foreach my $medCategory (keys %{$href-{'yes'}-{qw('' 'yes')}-{qw('' 
'yes')}}) {
   foreach my $med (keys %{$href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
'yes')}-{$medCategory}}) {
 foreach my $ID (keys %{$href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
'yes')}-{$medCategory}-{$med}}) {
   print qq{ $href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
'yes')}-{$medCategory}-{$med}-{$ID}-{ID} };
   print qq{ $href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
'yes')}-{$medCategory}-{$med}-{$ID}-{Medication} };

 }
   }
 }

 This isn't working of course because I don't quite understand the syntax I
 need.  Can someone give me a hint?  Thanks!

 Ryan

Ryan/Gerald (!)

You don't want to use selectall_hashref because, as is the nature of hashes, the
key must be unique, which means the database table's key field that provides it
must also be unique. If you get this working, you will retrieve a single record
for each possible value of each key: presumably 'yes', 'no', '', and NULL or
something like that.

It does look though as if you're pulling all your database data into a Perl hash
and trying to interrogate that. Surely, in your example above, you should be
writing somthing such as:

  my $data = $dbh-selectall_arrayref(qq(
SELECT id, medication
FROM table
WHERE col1 = 'yes' OR OR col1 = '' OR col1 IS NULL
ORDER BY id
  ));

  foreach my $row (@$data) {
printf %s: %s\n, @$row;
  }

(I don't know what the 'yes' field's name is, or what the table name is.)

By the way, qw doesn't work like that - you've used it as a tool that just
allows you to miss out the commas.

  qw(yes no maybe)

is the same as

  ('yes', 'no', 'maybe')

i.e. its effect is the same as a call to split() on the string within the
delimiters. There's no way no write the empty string using this of course, so
your

  qw('' 'yes')

should be

  ('', 'yes')

but that won't make the program work!

Hope this helps,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: match and grab

2006-09-28 Thread Rob Dixon

Rob Dixon wrote:

 John W. Krahn wrote:

 Rob Dixon wrote:

 John W. Krahn wrote:


perldoc -f print
  print FILEHANDLE LIST
  print LIST
  print   Prints a string or a list of strings.  Returns true if
  successful.  FILEHANDLE may be a scalar variable name, in which
  case the variable contains the name of or a reference to the
  filehandle, thus introducing one level of indirection.

If the comma is missing then the first scalar or bareword argument is
treated as a filehandle.


Hmm. Well if I was wrong I'd like to be corrected, but it certainly 
/looks/ and /behaves/ like indirect-object method call syntax, and the 
equivalent arrow syntax works and does the same thing. But whether it's

really a method call under the hood I'm not absolutely certain,
especially when there are oddities like

print(STDOUT text\n);

working fine. Whatever it is, it certainly stops being either a list 
operator or a function call, so what else can it be?


So you are saying that everytime print() is used IO::Handle gets
sucked in somehow?


Well it's not so far-fetched. After all a lot of magical things happen in 
Perl, and PerlIO does an on-demand load thing behind the scenes in 5.8. But 
no, I know that print() is a built-in but thought that it was hooked in on 
the back of a indirect object method call syntax. A couple of things support 
this: first that


STDOUT-print()

works fine, and secondly that it's impossible to write a simple subroutine 
prototype that does what print() and printf() do whereas that can be done for
all (?) other Perl functions. On the other hand you /can/ write an object 
method that behaves the same syntactically.



And how would this have worked in Perl1 through Perl4 before OO was
added?


Now that is a puzzle and I hadn't thought of it. But it strikes me as an 
astonishing choice to provide a unique syntax which is invalid for any other
built-in or user-written subroutine for just two built-in functions, and 
solely to allow an optional first parameter. It is also a huge coincidence 
that that same syntax pops up later on as a valid construct for object method

calls and so makes everything OK.

I am quite happy to believe you are right John, and if that is so then I 
apologise to the list for my mistake, but am also left puzzling over what 
seems to be a number of enigmas within a language I thought I knew well.


Sorry about the amount of quoting, but this goes back a few weeks and I thought
people may need a reminder.

I've just found a reference in the Perl documentation which says that things are
just as I thought they were, thank goodness!

perldoc perlobj

  Indirect Object Syntax

The other way to invoke a method is by using the so-called indirect
object notation. This syntax was available in Perl 4 long before
objects were introduced, and is still used with filehandles like this:

   print STDERR help!!!\n;


But presumably it wasn't called 'indirect object notation' back then?

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash slices

2006-09-28 Thread Gerald Host



Ryan/Gerald (!)



(Ryan)

You don't want to use selectall_hashref because, as is the nature of hashes,

the
key must be unique, which means the database table's key field that
provides it
must also be unique. If you get this working, you will retrieve a single
record
for each possible value of each key: presumably 'yes', 'no', '', and NULL
or
something like that.



I know.  One of my key columns is an ID field so there will be a unique key.


It does look though as if you're pulling all your database data into a Perl

hash
and trying to interrogate that. Surely, in your example above, you should
be
writing somthing such as:

   my $data = $dbh-selectall_arrayref(qq(
 SELECT id, medication
 FROM table
 WHERE col1 = 'yes' OR OR col1 = '' OR col1 IS NULL
 ORDER BY id
   ));

   foreach my $row (@$data) {
 printf %s: %s\n, @$row;
   }



nope:

   my $href =$$dbh-selectall_hashref(q{SELECT * FROM recommendations WHERE
RxNumber=? ORDER BY medCategory, Medication, methodPreference}, [qw(
medCategory Medication include ifFollowedProtocol ifCycling ID) ],
undef,('12345'));



So I'm still confused about what I need to do.  I want to:

1. display the rows with ifFollowedProtocol eq '' or 'yes' in order of
medCategory
2. display the rows with ifFollowedProtocol eq '' or 'no' in order of
medCategory

I thought I could do this with a hash of hashes...I know there are other
ways, but I'd like to understand how to do it with this hashref using hash
slices if it's possible.

Thanks!


Re: regex help needed

2006-09-28 Thread Jay Savage

On 9/27/06, Owen [EMAIL PROTECTED] wrote:

On Wed, 27 Sep 2006 13:11:17 -0600
Gerald Wheeler [EMAIL PROTECTED] wrote:

 I am looking for: ab1in line1
 and looking for: ab2 in line 2

 actually ab1 and ab2 immediately follow the last / (there are
 numerous / on the line (w/o quotes))

 These are not working.  can some explain what these say and what they
 should say (syntax) to return the results I'm looking for: if ab1/ab2
 are in the line, return true.

 /^[^\#]*ab1/,@lines

 /^[^\#]*ab2/,@lines


Is there more to this code somewhere? This says match $_ against a
pattern, ignore the result and return @lines. I doubt that's what you
want. If you have warnings on, it should give you warnings like
useless use of [something or other] and use of uninitialized value
in pattern match (m//) at...

Did you intend a grep or something similar there? Something like

   my @hits = grep /^[^\#]*ab1/, @lines

might return a useful result.

As for the patterns themselves, '^' means start looking at the
beginning of the string. '[^\#]*' means look for zero or more
characters in the class of all characters that aren't '\' or '#'. And
'ab1' means exactly that.



Presumeably you want a match against '/ab1'

In which case you might just get by with /\/ab1/

But you may need to provide a few more specifications and example data


But that will match any ab1, not just the one after the last '/'

If '/ab1' will always be the end of the string, or at least the end of
a word, you could go for:

   /\ab1$/
 or
   /\ab1\s/

That makes assumptions that may not be valid, though. we'd need to see data.

Failing test data--or given unpredictable data--I'd go for something like:

  m{.*/ab1}  $' !~ m{/}
 or
  m{/ab1[^/]*$}

Although I'm sure someone will have a more efficient, or at least more
elegant, approach.

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!


Re: interpoliation within regexp

2006-09-28 Thread Mumia W.

On 09/28/2006 12:04 PM, Derek B. Smith wrote:

**
The input data is a 6 character randomized string that
could start with a # such as 6FhJ9Z.  If it does start
with a number then I need to convert this character
into its cooresponding alpha char, [a-z,A-Z].

The output data from the string 6FhJ9Z should be
[a-z,A-Z]FhJ9Z I guess what I am asking for is not
plausible after looking at the ASCII table b/c there
is no cooresponding letter for number 6. Silly me, ok
then maybe grab any [a-z,A-Z] character.

my $foo = pack(C*, 6); print $foo;
or
chr ('6'); 




What is the purpose of this program?



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash slices

2006-09-28 Thread John W. Krahn
Gerald Host wrote:
 I'm using DBI's selectall_hashref with 5 key columns.  I want to display
 each row where key col 1 is 'yes' or NULL (undef or '' ?)
 
 
 foreach my $medCategory (keys %{$href-{'yes'}-{qw('' 'yes')}-{qw('' 
 'yes')}}) {
 foreach my $med (keys %{$href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
 'yes')}-{$medCategory}}) {
 foreach my $ID (keys %{$href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
 'yes')}-{$medCategory}-{$med}}) {
 
 print qq{ $href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
 'yes')}-{$medCategory}-{$med}-{$ID}-{ID} };
 print qq{ $href-{qw('yes')}-{qw('' 'yes')}-{qw('' 
 'yes')}-{$medCategory}-{$med}-{$ID}-{Medication} };
 }
 }
 }
 
 This isn't working of course because I don't quite understand the syntax I
 need.  Can someone give me a hint?  Thanks!

A slice of a variable has to start with @, for example:

@array_slice[ 1 .. 9 ];
@hash_slice{ 'one', 'two', 'three' };

If you have a multidimensional data structure you can only slice at the end:

@{ $array_ref-[ 3 ][ 7 ] }[ 1 .. 9 ];
@{ $hash_ref-{ x }{ y } }{ 'one', 'two', 'three' };

In your example:

%{ $href-{ 'yes' }-{ qw( '' 'yes' ) }-{ qw( '' 'yes' ) } }

There is no slice, and the lists evaluate to the last item in the list so what
you actually have is:

%{ $href-{ 'yes' }-{ 'yes' }-{ 'yes' } }

And yes, the single quotes are included in the key as that is the way qw() 
works.

It looks like you want something like this:

for my $href1 ( @{ $href-{ yes } }{ '', 'yes' } ) {
for my $href2 ( @{ $href1 }{ '', 'yes' } ) {
for my $medCategory ( keys %$href2 ) {
for my $med ( keys %{ $href2-{ $medCategory } } ) {
for my $ID ( keys %{ $href2-{ $medCategory }{ $med } } ) {

print  $href2-{ $medCategory }{ $med }{ $ID }{ ID } ;
print  $href2-{ $medCategory }{ $med }{ $ID }{
Medication } ;
}
}
}
}
}




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: interpoliation within regexp

2006-09-28 Thread Derek B. Smith
--- Mumia W. [EMAIL PROTECTED]
wrote:

 On 09/28/2006 12:04 PM, Derek B. Smith wrote:
  **
  The input data is a 6 character randomized string
 that
  could start with a # such as 6FhJ9Z.  If it does
 start
  with a number then I need to convert this
 character
  into its cooresponding alpha char, [a-z,A-Z].
  
  The output data from the string 6FhJ9Z should be
  [a-z,A-Z]FhJ9Z I guess what I am asking for is not
  plausible after looking at the ASCII table b/c
 there
  is no cooresponding letter for number 6. Silly me,
 ok
  then maybe grab any [a-z,A-Z] character.
  
  my $foo = pack(C*, 6); print $foo;
  or
  chr ('6'); 
  
 
 
 What is the purpose of this program?
 
 


To generate a random 6 character string.
 
If the first character starts with a # then I just
ignore the new string and tell it to goto LABLE, b/c
for 0-32 on the ASCII table cannot be used as a 1st
character in a user password.

## generate random 8 char password.
PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
my $password = join '', map { $a[int rand @a] } 0 ..
5;

#if first char is a-z then print it else warn
#chop string into individual characters

my @chars  = unpack (A1 x length($password),
$password);
if ($chars[0] =~ /^\D/) {
  print Your new password is:\t,@chars,\n;
}
else {
  #print string starts with number:\t,@chars,
\trestarting\n;
  #substr($chars[0],0,1) =~ s/$chars[0]/chr ($1)/e);
## execute with regexp substitute ?/? 
  goto PASSWD;
}

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Hash problem

2006-09-28 Thread Johnson, Reginald \(GTI\)
I am doing an example from Perl Objects, References  modules. I suspect
many of  you already use this book as a reference.
My hash is showing the address instead of  the name and I'm not sure
why. Here is my output.

this is person=HASH(0x20040014)
this is who=HASH(0x20040014)
HASH(0x20040014) is missing preserver
HASH(0x20040014) is missing sunscreen
HASH(0x20040014) is missing water_bottle
HASH(0x20040014) is missing jacket

Here is the code
#!/usr/bin/perl
use strict;

my @gilligan = qw(red_shirt hat  lucky_socks water_bottle);
my @skipper = qw ( blue_shirt  hat preserver  sunscreen);
my @professor = qw(sunscreen water_bottle slide_rule batteries
radio);

my %all = {
Gilligan = [EMAIL PROTECTED],
Skipper =  [EMAIL PROTECTED],
Professor = [EMAIL PROTECTED],
  };

check_items_for_all(\%all);

sub check_items_for_all{
my $all = shift;
for my $person(sort keys %$all) {
print this is person=$person\n;
check_items_required($person, $all-{$person});
} #end for
} #end check_items_for_all

sub check_items_required {
my $who = shift;
print this is who=$who\n;
my $items = shift;
my @required = qw(preserver sunscreen water_bottle
jacket);

for my $item (@required) {
unless (grep $item eq $_, @$items) { #if
statement is false
print $who is missing $item\n;
} #end unless
 } #end for
} #end sub


Reggie Johnson
TSM Admin




Re: interpoliation within regexp

2006-09-28 Thread John W. Krahn
Derek B. Smith wrote:
 --- Mumia W. [EMAIL PROTECTED]
 wrote:

What is the purpose of this program?
 
 To generate a random 6 character string.
  
 If the first character starts with a # then I just
 ignore the new string and tell it to goto LABLE, b/c
 for 0-32 on the ASCII table cannot be used as a 1st
 character in a user password.
 
 ## generate random 8 char password.
 PASSWD: my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
 my $password = join '', map { $a[int rand @a] } 0 ..
 5;

Why not just specify a non-digit for the first character:

my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');

my $password = join '', $a[ 10 + rand( @a - 10 ) ], map $a[ rand @a ], 1 .. 5;



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: interpoliation within regexp

2006-09-28 Thread Derek B. Smith

 
 Why not just specify a non-digit for the first
 character:
 
 my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
 
 my $password = join '', $a[ 10 + rand( @a - 10 ) ],
 map $a[ rand @a ], 1 .. 5;
 
 
 
 John


Ok great, but I do not fully understand this. Will you
explain in English?

thx

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash problem

2006-09-28 Thread chen li


--- Johnson, Reginald (GTI) [EMAIL PROTECTED]
wrote:

 I am doing an example from Perl Objects, References
  modules. I suspect
 many of  you already use this book as a reference.
 My hash is showing the address instead of  the name
 and I'm not sure
 why. Here is my output.
 
 this is person=HASH(0x20040014)
 this is who=HASH(0x20040014)
 HASH(0x20040014) is missing preserver
 HASH(0x20040014) is missing sunscreen
 HASH(0x20040014) is missing water_bottle
 HASH(0x20040014) is missing jacket
 
 Here is the code
 #!/usr/bin/perl
 use strict;
 
 my @gilligan = qw(red_shirt hat  lucky_socks
 water_bottle);
 my @skipper = qw ( blue_shirt  hat preserver
  sunscreen);
 my @professor = qw(sunscreen water_bottle
 slide_rule batteries
 radio);
 
 my %all = {
 Gilligan = [EMAIL PROTECTED],
 Skipper =  [EMAIL PROTECTED],
 Professor = [EMAIL PROTECTED],
   };
 
 check_items_for_all(\%all);
 
 sub check_items_for_all{
 my $all = shift;
 for my $person(sort keys %$all) {
 print this is person=$person\n;

 check_items_required($person, $all-{$person});
 } #end for
 } #end check_items_for_all
 
 sub check_items_required {
 my $who = shift;
 print this is who=$who\n;
 my $items = shift;
 my @required = qw(preserver
 sunscreen water_bottle
 jacket);
 
 for my $item (@required) {
 unless (grep $item eq $_,
 @$items) { #if
 statement is false
 print $who is missing
 $item\n;
 } #end unless
  } #end for
 } #end sub
 
 
 Reggie Johnson
 TSM Admin
Hi,

1) add line  use warnings; after line use strict;

2) change %all( which is a hash) into $all_ref(which
is a hash reference)

3) Are the following what you expect?
###output #

this is person=Gilligan
this is who=Gilligan
Gilligan is missing preserver
Gilligan is missing sunscreen
Gilligan is missing jacket
this is person=Professor
this is who=Professor
Professor is missing preserver
Professor is missing jacket
this is person=Skipper
this is who=Skipper
Skipper is missing water_bottle
Skipper is missing jacket

Li

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash problem

2006-09-28 Thread D. Bolliger
Johnson, Reginald (GTI) am Donnerstag, 28. September 2006 21:58:
 I am doing an example from Perl Objects, References  modules. I suspect
 many of  you already use this book as a reference.
 My hash is showing the address instead of  the name and I'm not sure
 why. Here is my output.

 this is person=HASH(0x20040014)
 this is who=HASH(0x20040014)
 HASH(0x20040014) is missing preserver
 HASH(0x20040014) is missing sunscreen
 HASH(0x20040014) is missing water_bottle
 HASH(0x20040014) is missing jacket

 Here is the code
 #!/usr/bin/perl
 use strict;

 my @gilligan = qw(red_shirt hat  lucky_socks water_bottle);
 my @skipper = qw ( blue_shirt  hat preserver  sunscreen);
 my @professor = qw(sunscreen water_bottle slide_rule batteries
 radio);

 my %all = {

usage of '()' instead of '{}' would probably help :-)

The hash as defined in your line has one key with a stringified address, and 
the value is undef.

Check this out with

use Data::Dumper;
warn Data::Dumper::Dumper (\%all);


 Gilligan = [EMAIL PROTECTED],
 Skipper =  [EMAIL PROTECTED],
 Professor = [EMAIL PROTECTED],
   };

 check_items_for_all(\%all);

 sub check_items_for_all{
 my $all = shift;
 for my $person(sort keys %$all) {
 print this is person=$person\n;
 check_items_required($person, $all-{$person});
 } #end for
 } #end check_items_for_all

 sub check_items_required {
 my $who = shift;
 print this is who=$who\n;
 my $items = shift;
 my @required = qw(preserver sunscreen water_bottle
 jacket);

 for my $item (@required) {
 unless (grep $item eq $_, @$items) { #if
 statement is false
 print $who is missing $item\n;
 } #end unless
  } #end for
 } #end sub

Hope this helps!

Dani

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash problem

2006-09-28 Thread John W. Krahn
Johnson, Reginald (GTI) wrote:
 I am doing an example from Perl Objects, References  modules. I suspect
 many of  you already use this book as a reference.
 My hash is showing the address instead of  the name and I'm not sure
 why. Here is my output.
 
 this is person=HASH(0x20040014)
 this is who=HASH(0x20040014)
 HASH(0x20040014) is missing preserver
 HASH(0x20040014) is missing sunscreen
 HASH(0x20040014) is missing water_bottle
 HASH(0x20040014) is missing jacket
 
 Here is the code
 #!/usr/bin/perl

use warnings;

 use strict;
 
 my @gilligan = qw(red_shirt hat  lucky_socks water_bottle);
 my @skipper = qw ( blue_shirt  hat preserver  sunscreen);
 my @professor = qw(sunscreen water_bottle slide_rule batteries
 radio);
 
 my %all = {
 Gilligan = [EMAIL PROTECTED],
 Skipper =  [EMAIL PROTECTED],
 Professor = [EMAIL PROTECTED],
   };

If you had included the warnings pragma then perl would have told you what is
wrong:

Reference found where even-sized list expected at Hash_problem.pl line 8.

You need to assign a list to %all, not an anonymous hash:

my %all = (
Gilligan  = [EMAIL PROTECTED],
Skipper   = [EMAIL PROTECTED],
Professor = [EMAIL PROTECTED],
);




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




New Perl Forum Up

2006-09-28 Thread Philip

Hi everyone -

I sincerely hope this email is not regarded as spam, if so please excuse me.
I've decided to create a Perl forum board over at
http://perl.nixpub.combecause I'm tired of the advertisement infested
Perl forums that are out
there. I could go on, but if your interested please take a look, I am very
interested in helping the Perl community out as much as I can. I am
certainly not trying to drive away users from this mailing list either, as I
have learned a great deal so far from it. Thank you for your time!

--
My religion consists of a humble admiration of the illimitable superior
spirit who reveals himself in the slight details we are able to perceive
with our frail and feeble mind.
 - Albert Einstein


Re: interpoliation within regexp

2006-09-28 Thread D. Bolliger
Derek B. Smith am Donnerstag, 28. September 2006 22:28:
  Why not just specify a non-digit for the first
  character:
 
  my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
 
  my $password = join '', $a[ 10 + rand( @a - 10 ) ],
  map $a[ rand @a ], 1 .. 5;
 
 
 
  John

 Ok great, but I do not fully understand this. Will you
 explain in English?

Join with '':
a) a randomly selected entry from @a excluding the digits
   at positions 0..9 [the part between the 1st and 
   2nd comma]
b) five randomly selected entries from @a
   [the map part]

Note: @a is used in scalar context both times, meaning the number of entries 
in @a.

perldoc -f map
perldoc -f join
perldoc -f rand


My tip for cases where you get a working solution you don't understand fully:
a) Try to find out what belongs together (imagine '()'s)
b) Try to break the solution apart according to the findings in a)
c) examine the parts: print them out, dump them with Data::Dumper, modify
   them, read the man pages
d) put them together again, eventually one by one part, using examination 
   techniques as in c)


Hope this helps!

Dani


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Hash problem

2006-09-28 Thread Johnson, Reginald \(GTI\)


-Original Message-
From: D. Bolliger [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 28, 2006 4:32 PM
To: beginners@perl.org
Subject: Re: Hash problem


Johnson, Reginald (GTI) am Donnerstag, 28. September 2006 21:58:
 I am doing an example from Perl Objects, References  modules. I
suspect
 many of  you already use this book as a reference.
 My hash is showing the address instead of  the name and I'm not sure
 why. Here is my output.

 this is person=HASH(0x20040014)
 this is who=HASH(0x20040014)
 HASH(0x20040014) is missing preserver
 HASH(0x20040014) is missing sunscreen
 HASH(0x20040014) is missing water_bottle
 HASH(0x20040014) is missing jacket

 Here is the code
 #!/usr/bin/perl
 use strict;

 my @gilligan = qw(red_shirt hat  lucky_socks water_bottle);
 my @skipper = qw ( blue_shirt  hat preserver  sunscreen);
 my @professor = qw(sunscreen water_bottle slide_rule batteries
 radio);

 my %all = {

usage of '()' instead of '{}' would probably help :-)

The hash as defined in your line has one key with a stringified address,
and 
the value is undef.

Check this out with

use Data::Dumper;
warn Data::Dumper::Dumper (\%all);


 Gilligan = [EMAIL PROTECTED],
 Skipper =  [EMAIL PROTECTED],
 Professor = [EMAIL PROTECTED],
   };

 check_items_for_all(\%all);

 sub check_items_for_all{
 my $all = shift;
 for my $person(sort keys %$all) {
 print this is person=$person\n;
 check_items_required($person,
$all-{$person});
 } #end for
 } #end check_items_for_all

 sub check_items_required {
 my $who = shift;
 print this is who=$who\n;
 my $items = shift;
 my @required = qw(preserver sunscreen water_bottle
 jacket);

 for my $item (@required) {
 unless (grep $item eq $_, @$items) { #if
 statement is false
 print $who is missing $item\n;
 } #end unless
  } #end for
 } #end sub

Hope this helps!

Dani


Yes this did the trick. Thanks to all of you who responded. I guess it
is a good practice to use data::dumper when you are developing programs.
When I search CPAN in modules I see a quick snopsis of data dumper. Is
there an area in CPAN that has a more verbose listing of modules?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: interpoliation within regexp

2006-09-28 Thread John W. Krahn
Derek B. Smith wrote:
  
Why not just specify a non-digit for the first
character:

my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');

my $password = join '', $a[ 10 + rand( @a - 10 ) ],
map $a[ rand @a ], 1 .. 5;
 
 Ok great, but I do not fully understand this. Will you
 explain in English?

The first ten elements of @a are the digits 0-9 so the first list item picks a
random element that ignores the first ten elements of @a and the next five
list items pick a random element from the entire array.



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash problem

2006-09-28 Thread D. Bolliger
Johnson, Reginald (GTI) am Donnerstag, 28. September 2006 22:56:
 I guess it
 is a good practice to use data::dumper when you are developing programs.

What you should always use is (as others pointed out) the lines:

use strict;
use warnings;

to improve detection of errors.

Data::Dumper is useful if you are not shure how a data structure looks like ( 
hm, that should not occur in own programs ;-) ), or to check if it really 
looks as expected.

And of course creating test scripts is always a good thing to answer the 
question: Does my program what it should do? See for example:
Test::Simple
Test::More

 When I search CPAN in modules I see a quick snopsis of data dumper. Is
 there an area in CPAN that has a more verbose listing of modules?

I'm not sure what you mean here. You can use search.cpan.org to search 
modules, and after a click on the module name, the manual is displayed.
Via this page you can (directly) reach the source code, and (indirectly) all 
files in the distribution, including the test scripts.


regards

Dani

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash slices

2006-09-28 Thread Rob Dixon

Gerald Host wrote:

 Rob Dixon wrote:

 You don't want to use selectall_hashref because, as is the nature of hashes,
 the key must be unique, which means the database table's key field that
 provides it must also be unique. If you get this working, you will retrieve a
 single record for each possible value of each key: presumably 'yes', 'no',
 '', and NULL or something like that.

 I know. One of my key columns is an ID field so there will be a unique key.

It doesn't work like that. The hash level corresponding to ifFollowedProtocol
must be unique on its own, It's independent of anything in the nested hashes and
(in your code below) anything with the same 'medCategory' 'Medication' 'include'
and 'ifFollowedProtocol' will try to occupy the same slot in the hash at that
level and previous stuff will be overwritten.

By the way, is your list of key fields below correct? You said you had five key
columns in your original post.

 It does look though as if you're pulling all your database data into a Perl
 hash and trying to interrogate that. Surely, in your example above, you
 should be writing somthing such as:

my $data = $dbh-selectall_arrayref(qq(
  SELECT id, medication
  FROM table
  WHERE col1 = 'yes' OR OR col1 = '' OR col1 IS NULL
  ORDER BY id
));

foreach my $row (@$data) {
  printf %s: %s\n, @$row;
}



 nope:

my $href =$$dbh-selectall_hashref(q{SELECT * FROM recommendations WHERE
 RxNumber=? ORDER BY medCategory, Medication, methodPreference}, [qw(
 medCategory Medication include ifFollowedProtocol ifCycling ID) ],
 undef,('12345'));

OK, that's a little clearer. But why so many key fields? In fact why not just
ID, since it's a unique one. By the way, an ORDER BY is pointless with
selectall_hashref, as hashes are unordered.

 So I'm still confused about what I need to do.  I want to:

 1. display the rows with ifFollowedProtocol eq '' or 'yes' in order of
 medCategory
 2. display the rows with ifFollowedProtocol eq '' or 'no' in order of
 medCategory

 I thought I could do this with a hash of hashes...I know there are other
 ways, but I'd like to understand how to do it with this hashref using hash
 slices if it's possible.

Alright, lets try.two solutions. First mine, which seems to do what you want,
but has only one level of hash so is a lot easier to code for


my $href = $dbh-selectall_hashref(q{
  SELECT *
  FROM recommendations
  WHERE RxNumber = ?
}, 'ID', undef, 12345);

foreach my $id (sort keys %$href) {

  my $data = $href-{$id};

  my $ifp = $data-{ifFollowedProtocol};
  next if defined $ifp and $ifp ne '' and $ifp ne 'yes';

  print $data-{ID}, \n;
  print $data-{Medication}, \n;
}


And now one with all the key fields in as you had, and a hash slice

my $medcat_href = $dbh-selectall_hrefref(q{
  SELECT *
  FROM recommendations
  WHERE RxNumber = ?},
  [qw(
medCategory
Medication
include
ifFollowedProtocol
ifCycling
ID
  )],
  undef,('12345'));

foreach my $med_href (values %$medcat_href) {
  foreach my $include_href (values %$med_href) {
foreach my $protocol_href (values %$include_href) {
  foreach my $cycling_href (@{$protocol_href}{'yes', ''}) {
foreach my $id_href (values %$cycling_href) {
  foreach my $data (values %$id_href) {
print $data-{ID}, \n;
print $data-{Medication}, \n;
  }
}
  }
}
  }
}


which I've simplified from your code by taking the hash references out at each
stage instead of applying the full sequence of keys relative to the root
$medcat_href. Also, if you put the ID key first in the list, the problem of
duplicate 'ifFollowedProtocol' values is removed, but then the whole idea of
putting multiple keys in here becomes obviously pointless as every hash wihtin
the outermost one will have only a single key/value entry.

Now I expect I've misunderstood something here, but I hope some of this is of
some use to get you on track? Let us know.

Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hash problem

2006-09-28 Thread Dr.Ruud
Johnson, Reginald (GTI) schreef:

 I guess it
 is a good practice to use data::dumper when you are developing
 programs.

ITYM: Data::Dumper (casing matters).

-- 
Affijn, Ruud

Gewoon is een tijger.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Querying very big database

2006-09-28 Thread Toddy Prawiraharjo
Hello all,

I am not sure if i'm inside the correct mailing list, but it should be
simple for you guys. Recently i started a simple perl program to catch
all syslog from my netscreen firewall, and put them into a database, so
later can do some analysing on it (sort of AWStats). the database itself
is pretty big, with 600k entry (for 3 weeks of the running firewall)
worth 80 megs in mysql. My question is, during the analysing my perl
script giving very slow processing. I know the query to mysql itself is
pretty quick, less than 2 seconds to return about 40k to 60k result to
perl to be analysed

Here it goes:
snipped
$query = SELECT src, rcvd FROM no_name WHERE start_date =
'$fromdate' AND start_date = '$todate';;
$sth = $dbh-prepare($query);
$sth - execute() || errorhere(SQL Error: $DBI::errstr);
print $querybr;

my %src = ();
my ($totalsent, $totalrcvd, $srcchecked);

while(@row = $sth-fetchrow_array){
$srcchecked = 0;
while($source, $total = each (%src)){
if ($source eq $row[0]){
$srcchecked = 1;
$src{$source} = $src{$source} + $row[1];
}
}
if ($srcchecked != 1){
print $row[0]br;
$src{$row[0]} = $row[1];
}
$totalrcvd = $totalsent + $row[1];
#$totalrcvd = $totalrcvd + $row[2];
}
/snipped

The while loop to do analysing on the data take more than 15 minutes,
and that only to a query for 1 day long records($fromdate-$todate) 
So, if I want perl to give me faster result, what's the solution? Did I
make fundamentally wrong approach?


Thanks in advance for any response



Toddy Prawiraharjo



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Querying very big database

2006-09-28 Thread Rob Dixon

Toddy Prawiraharjo wrote:

Hello all,

I am not sure if i'm inside the correct mailing list, but it should be
simple for you guys. Recently i started a simple perl program to catch
all syslog from my netscreen firewall, and put them into a database, so
later can do some analysing on it (sort of AWStats). the database itself
is pretty big, with 600k entry (for 3 weeks of the running firewall)
worth 80 megs in mysql. My question is, during the analysing my perl
script giving very slow processing. I know the query to mysql itself is
pretty quick, less than 2 seconds to return about 40k to 60k result to
perl to be analysed

Here it goes:
snipped
$query = SELECT src, rcvd FROM no_name WHERE start_date =
'$fromdate' AND start_date = '$todate';;
$sth = $dbh-prepare($query);
$sth - execute() || errorhere(SQL Error: $DBI::errstr);
print $querybr;

my %src = ();
my ($totalsent, $totalrcvd, $srcchecked);

while(@row = $sth-fetchrow_array){
$srcchecked = 0;
while($source, $total = each (%src)){
if ($source eq $row[0]){
$srcchecked = 1;
$src{$source} = $src{$source} + $row[1];
}
}
if ($srcchecked != 1){
print $row[0]br;
$src{$row[0]} = $row[1];
}
$totalrcvd = $totalsent + $row[1];
#$totalrcvd = $totalrcvd + $row[2];
}
/snipped

The while loop to do analysing on the data take more than 15 minutes,
and that only to a query for 1 day long records($fromdate-$todate) 
So, if I want perl to give me faster result, what's the solution? Did I

make fundamentally wrong approach?


You've missed the whole point of hashes, which is that they will access a data
value directly from a key. What you've written is similar to

  my $i = 0;
  my $value;
  foreach my $v (@array) {
if ($i++ == $n) {
  $value = $v;
}
  }

instead of

  $value = $array[$n];

Try this while loop instead of the one you have and see if you get an
improvement:

  while (@row = $sth-fetchrow_array) {

my $key = $row[0];

print $keybr unless exists $src{$key};
$src{$key} += $row[1];

$totalsent += $row[1];
#$totalrcvd += $row[2];
  }

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Querying very big database

2006-09-28 Thread Toddy Prawiraharjo

THX! I always knew it's my n00b scripting that caused the problem. It
now down to 4 lines inside while loop, and I'm flying! The processing
down from ~15 minutes to 4 secs! But, for longer date range (2 weeks
time limit) it clocked at 25 wallclock secs (with processing ~350k mysql
return entries). Any more way to process this beast any faster? Any good
reading or reference about this? Just afraid, if this rolled to
production level, the report for months activities will take minutes to
make!

snipped
$query = SELECT src, sent, rcvd FROM no_name WHERE start_date
= '$fromdate' AND start_date = '$todate';;
$sth = $dbh-prepare($query);
$sth - execute() || errorhere(SQL Error: $DBI::errstr);
#print $querybr;

my %src = ();
my ($totalsent, $totalrcvd);

while(@row = $sth-fetchrow_array){
my $key = $row[0];
$src{$key} += $row[2];
$totalsent = $totalsent + $row[1];
$totalrcvd = $totalrcvd + $row[2];
}
/snipped
Cheers,
 
Toddy Prawiraharjo
 


-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Friday, 29 September 2006 10:04 AM
To: beginners@perl.org
Subject: Re: Querying very big database


Toddy Prawiraharjo wrote:
 Hello all,
 
 I am not sure if i'm inside the correct mailing list, but it should be
 simple for you guys. Recently i started a simple perl program to catch
 all syslog from my netscreen firewall, and put them into a database,
so
 later can do some analysing on it (sort of AWStats). the database
itself
 is pretty big, with 600k entry (for 3 weeks of the running firewall)
 worth 80 megs in mysql. My question is, during the analysing my perl
 script giving very slow processing. I know the query to mysql itself
is
 pretty quick, less than 2 seconds to return about 40k to 60k result to
 perl to be analysed
 
 Here it goes:
 snipped
 $query = SELECT src, rcvd FROM no_name WHERE start_date =
 '$fromdate' AND start_date = '$todate';;
 $sth = $dbh-prepare($query);
 $sth - execute() || errorhere(SQL Error: $DBI::errstr);
 print $querybr;
 
 my %src = ();
 my ($totalsent, $totalrcvd, $srcchecked);
 
 while(@row = $sth-fetchrow_array){
 $srcchecked = 0;
 while($source, $total = each (%src)){
 if ($source eq $row[0]){
 $srcchecked = 1;
 $src{$source} = $src{$source} +
$row[1];
 }
 }
 if ($srcchecked != 1){
 print $row[0]br;
 $src{$row[0]} = $row[1];
 }
 $totalrcvd = $totalsent + $row[1];
 #$totalrcvd = $totalrcvd + $row[2];
 }
 /snipped
 
 The while loop to do analysing on the data take more than 15 minutes,
 and that only to a query for 1 day long records($fromdate-$todate) 
 So, if I want perl to give me faster result, what's the solution? Did
I
 make fundamentally wrong approach?

You've missed the whole point of hashes, which is that they will access
a data
value directly from a key. What you've written is similar to

   my $i = 0;
   my $value;
   foreach my $v (@array) {
 if ($i++ == $n) {
   $value = $v;
 }
   }

instead of

   $value = $array[$n];

Try this while loop instead of the one you have and see if you get an
improvement:

   while (@row = $sth-fetchrow_array) {

 my $key = $row[0];

 print $keybr unless exists $src{$key};
 $src{$key} += $row[1];

 $totalsent += $row[1];
 #$totalrcvd += $row[2];
   }

HTH,

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




sorting DBM hash

2006-09-28 Thread John W. Burns
Sorting DBM Hash
Greetings:
I've run into what appears to be a conflict in sorting
a DBM Hash.  The DBM is opened and closed through tie and untie to store 
selections from Perl Tk medical questionnaire which uses checkboxes, radio 
buttons and
lists, and contains over 200 items.  I'm attempting to verify that all user
selections are accurately stored in the DB.
The first sort routine prints out keys and value.  However it fails to 
include some keys and values such as variable ckb_100 or ckb_104 (or their 
values).
When I use Randal Schwartz's sort from Learning Perl, it (by design) lists
keys sorted by value order (without listing values), but includes all keys 
in the DB including those keys dropped in the first sort.  I have reviewed the
PerlTk program a number of times and can't find an error (realize
this doesn't mean there isn't one).  But why would Randal's sort contain a
key that is not included in the other sort? Randal's sort indicates all
user selections are included in DB; other sort does not.

Here's the first sort code on the DBM Hash; it fails to list all keys and 
their values.
 #!/usr/local/bin/perl
 use warnings;
 use SDBM_File; #load database module which is a clone of DBM provided by 
ACTIVE STATE
   $db = c:/temp/userstats.db;  #where data is kept between runs
 dbmopen(%DATA,  $db, 0666 ) or die( Can't open: $! );

 foreach my $key ( sort { $a = $b } keys %DATA ) {
  print $key = $DATA{$key}\n;
 }

Here's Randal Schwartz', Learning Perl,sort; it lists all keys.
 #!/usr/local/bin/perl
 use warnings;
 use SDBM_File; #load database module which is a clone of DBM provided by 
ACTIVE STATE
 $db = c:/temp/userstats.db;#where data is kept between runs
 dbmopen(%DATA,  $db, 0666 ) or die( Can't open: $! );

 my @choices = sort by_score_and_name keys %DATA;
 sub by_score_and_name {
  $DATA{$b} = $DATA{$a} #by descending numeric score
   or
  $a cmp $b   #ASCIIbetically by name
 }
 print @choices, \n;
 dbmclose(%DATA);

Here's a typical PerlTk GUI:
  #Post Traumatic Stress Disorder
 $ckb_100 = $frme_name1a - Checkbutton(-text=post traumatic stress 
disorder, -variable=\$post2,
  -command =\variable_100);
 $ckb_100- deselect();
 $ckb_100- form(-left=460, -top=585);

An anonymous sub routine is used to hold sub routines
for all the question variables.  Here's a standard sub for
checkbox.
  sub variable_100 {
  my $x = ${$ckb_100 -cget(-variable)};
   if ($x == 1)  {
   $DATA{ckb_100} = 1;
   }
  else {

  }

 }

Thanks for any insights.
John Burns












sorting DBM hash

2006-09-28 Thread John W. Burns




Sorting DBM Hash
Greetings:
I've run into what appears to be a conflict in sorting
a DBM Hash.  The DBM is opened and closed through tie and untie to store 
selections
from Perl Tk medical questionnaire which uses checkboxes, radio buttons and
lists, and contains over 200 items.  I'm attempting to verify that all user
selections are accurately stored in the DB.
The first sort routine prints out keys and value.  However it fails to 
include
some keys such as variable ckb_100 or ckb_104 (or their values) along with a 
few other variables.
When I use Randal Schwartz's sort from Learning Perl, it (by design) lists
keys sorted by value order (without listing values), but includes all keys 
in the
DB including those keys dropped in the first sort.  I have reviewed the
PerlTk program a number of times and can't find an error (realize
this doesn't mean there isn't one).  But why would Randal's sort contain a
key that is not included in the other sort? Randal's sort indicates all
user selections are included in DB; other sort does not.

Here's the first sort code on the DBM Hash; it fails to list all keys and 
their values.
 #!/usr/local/bin/perl
 use warnings;
 use SDBM_File; #load database module which is a clone of DBM provided by 
ACTIVE STATE
   $db = c:/temp/userstats.db;  #where data is kept between runs
 dbmopen(%DATA,  $db, 0666 ) or die( Can't open: $! );

 foreach my $key ( sort { $a = $b } keys %DATA ) {
  print $key = $DATA{$key}\n;
 }

Here's Randal Schwartz', Learning Perl,sort; it lists all keys.
 #!/usr/local/bin/perl
 use warnings;
 use SDBM_File; #load database module which is a clone of DBM provided by 
ACTIVE STATE
 $db = c:/temp/userstats.db;#where data is kept between runs
 dbmopen(%DATA,  $db, 0666 ) or die( Can't open: $! );

 my @choices = sort by_score_and_name keys %DATA;
 sub by_score_and_name {
  $DATA{$b} = $DATA{$a} #by descending numeric score
   or
  $a cmp $b   #ASCIIbetically by name
 }
 print @choices, \n;
 dbmclose(%DATA);

Here's a typical PerlTk GUI:
  #Post Traumatic Stress Disorder
 $ckb_100 = $frme_name1a - Checkbutton(-text=post traumatic stress 
disorder, -variable=\$post2,
  -command =\variable_100);
 $ckb_100- deselect();
 $ckb_100- form(-left=460, -top=585);

An anonymous sub routine is used to hold sub routines
for all the question variables.  Here's a standard sub for
checkbox.
  sub variable_100 {
  my $x = ${$ckb_100 -cget(-variable)};
   if ($x == 1)  {
   $DATA{ckb_100} = 1;
   }
  else {

  }

 }

Thanks for any insights.
John Burns












-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




DBI - DB2 Perl Script ... TWiki

2006-09-28 Thread benbart
Hi all,

I have this script that am trying to use to connect to DB2.

At the moment I cannot get the script to connect to DB2.

In the UNIX prompt, if I run . /home/db2inst1/sqllib/db2profile first and then
run the Perl script, then I can connect to DB2.

Also, I can only do export DB2INSTANCE=db2inst1 and then run the Perl script,
then I can connect to DB2.

Can someone please advise how do I do an export DB2INSTANCE=db2inst1 or run the
. /home/db2inst1/sqllib/db2profile and that does not work? I tried to include
the following lines within the Perl script and it does not work too ...

system . /home/db2inst1/sqllib/db2profile;
system export DB2INSTANCE=db2inst1;

Any tips on how to get this to work will be very much appreciated. FYI, am
mainly trying to get this to work for Twiki.


=


#!/usr/bin/perl

# $Id: test.pl,v 11.7 2004/02/01 11:16:16 timbo Exp $
#
# Copyright (c) 1994-1998 Tim Bunce
#
# See COPYRIGHT section in DBI.pm for usage and distribution rights.


# This is now mostly an empty shell I experiment with.
# The real tests have moved to t/*.t
# See t/*.t for more detailed tests.


#use DBI;

use DBI::DBD;   # simple test to make sure it's okay

use Config;
use Getopt::Long;
use strict;

#use DBI;
#use DBD::DB2::Constants;
use DBD::DB2;

#system . /home/db2inst1/sqllib/db2profile;
#system env  /tmp/env.txt;
#system export DB2INSTANCE=db2inst1;

#$dbh = DBI-connect(dbi:DB2:db_name, $username, $password);
#$dbh = DBI-connect(dbi:DB2:DBNIAA01, db2inst1, eriver96);
#my $string=DBNIAA01;
my $string=dbi:DB2:DBNIAA01;
#my $string=dbi:DB2:DBMSDATA;
my $user=db2inst1;
my $pass=eriver96;
my $db=DBNIAA01;
my $hostname=svniadb.at.police.govt.nz;
my $port=5;

#my $string = dbi:DB2:DATABASE=$db; HOSTNAME=$hostname; PORT=$port;
PROTOCOL=TCPIP; UID=$user; PWD=$pass;;
my $dbh = DBI-connect($string, $user, $pass) || die Connection failed with
error: $DBI::errstr;

if (!defined($dbh)) {
print Crap, am exiting ??? \n;
exit; }

#my $stmt = select current timestamp from sysibm.sysdummy1;;
my $stmt = select * from nia.mstr_config;;
my $sth = $dbh-prepare($stmt);
$sth-execute();

while( my @array = $sth-fetchrow_array ) {
 print $array[0]\n;
}

#print $string\n;
#my $dbh = DBI-connect($string, $user, $pass) || die Connection failed with
error: $DBI::errstr;

$sth-finish();
  $dbh-disconnect();



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: DBI - DB2 Perl Script ... TWiki

2006-09-28 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
 Hi all,

Hello,

 I have this script that am trying to use to connect to DB2.
 
 At the moment I cannot get the script to connect to DB2.
 
 In the UNIX prompt, if I run . /home/db2inst1/sqllib/db2profile first and then
 run the Perl script, then I can connect to DB2.
 
 Also, I can only do export DB2INSTANCE=db2inst1 and then run the Perl script,
 then I can connect to DB2.
 
 Can someone please advise how do I do an export DB2INSTANCE=db2inst1 or run 
 the
 . /home/db2inst1/sqllib/db2profile and that does not work? I tried to include
 the following lines within the Perl script and it does not work too ...

Inside your Perl program do this:

BEGIN {
$ENV{ DB2INSTANCE } = 'db2inst1';
}



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




DatabasePlugin for DB2 and SQLSERVER on TWiki ...

2006-09-28 Thread benbart
Hi all,

Am trying to setup TWiki to connect to DB2 and SQLSERVER and needs to configure
the DatabasePlugin.pm and DatabasePluginConfig.pm. So far, am not having any
luck with them. Already, the notes/docs said the plugin had been tested on
MySQL and ORACLE databases only but since I was able to write a simple Perl
script to connect to DB2, I am hoping it will work with DB2 as well.

Anyway, I will be interested to hear from anyone who had managed to configure
these Perl modules to connect to DB2 and SQLSERVER databases.

Thanks in advance.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response