RE: Strange behaviour while using DBI with binding

2010-08-19 Thread Babale Fongo
Normally I would expect a quoted string to represent one value, this is 
probably not true for DBI binding as you mentioned. 

Cheers

=> -Original Message-
=> From: Chas. Owens [mailto:chas.ow...@gmail.com]
=> Sent: 19 August 2010 13:22
=> To: Babale Fongo
=> Cc: Uri Guttman; beginners@perl.org
=> Subject: Re: Strange behaviour while using DBI with binding
=> 
=> On Wed, Aug 18, 2010 at 19:55, Babale Fongo 
=> wrote:
=> snip
=> > In the first example, DBI always passed the value for offset and
=> ignored the
=> > second value after the comma.
=> >
=> > I'm now using the second code as it works without problem even if
=> string
=> > contains space. I just need to understand why DBI behaves that way.
=> >
=> > I cannot hard code limit in the string because the value varies.
=> This is
=> > used in a pager and the values of limit varies depending on which
=> page is to
=> > be displayed.
=> snip
=> 
=> Placeholders represent single values.  The DBI will properly quote any
=> value it binds to the placeholder.  Therefore, you must use more than
=> one placeholder if you want to provide more than one value:
=> 
=> #!/usr/bin/perl
=> 
=> use strict;
=> use warnings;
=> 
=> use DBI;
=> 
=> unlink "foo.db" or die $! if -e "foo.db";
=> my $dbh = DBI->connect(
=>  "dbi:SQLite:dbname=foo.db",
=>  "",
=>  "",
=>  {
=>  ChopBlanks => 1,
=>  PrintError => 0,
=>  RaiseError => 1,
=>  ShowErrorStatement => 1,
=>  FetchHashKeyName   => "NAME_lc",
=>  }
=> ) or die DBI->errstr;
=> 
=> $dbh->do("CREATE TABLE foo (n INTEGER)");
=> 
=> my $insert = $dbh->prepare("INSERT INTO foo (n) VALUES (?)");
=> 
=> for my $n (1 .. 100) {
=>  $insert->execute($n);
=> }
=> 
=> my $select = $dbh->prepare("SELECT n FROM foo ORDER BY n LIMIT ?, ?");
=> 
=> my $count  = 5;
=> my $offset = 0;
=> 
=> do {
=>  $select->execute($offset, $count);
=>  my @a;
=>  while (my $rec = $select->fetchrow_hashref) {
=>  push @a, $rec->{n};
=>  }
=>  if ($select->rows) {
=>  my $format = join(" ", ("%3d") x @a) . "\n";
=>  printf $format, @a;
=>  $offset += $count;
=>  } else {
=>  $offset = 0;
=>  }
=> } while ($offset);
=> 
=> 
=> --
=> Chas. Owens
=> wonkden.net
=> The most important skill a programmer can have is the ability to read.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Strange behaviour while using DBI with binding

2010-08-18 Thread Babale Fongo
>From your last comments, I am not sure where this is leading to, but here is
all I have to say.

Below are 2 pieces of code. Both have been tested with space in the string
and again without space. 

$limit = "$offset,$number_rows"  or $limit = "$offset, $number_rows"; 

1) This does not work (with or without space in the string).

my $sth = $dbh->prepare(qq{
Select fname, lname, dob, substr(desc, 1, 200)  from user
left join personal_data on 
user.id = personal_data.id where gender = ? and position = ?
order by lname limit ?
});
$sth->execute($gender, $role, $limit);


2) This works fine (with or without space in the string).

my $sth = $dbh->prepare(qq{
Select fname, lname, dob, substr(desc, 1, 200)  from user
left join personal_data on 
user.id = personal_data.id where gender = ? and position = ?
order by lname limit $limit
});
$sth->execute($gender, $role);


In the first example, DBI always passed the value for offset and ignored the
second value after the comma.

I'm now using the second code as it works without problem even if string
contains space. I just need to understand why DBI behaves that way.

I cannot hard code limit in the string because the value varies. This is
used in a pager and the values of limit varies depending on which page is to
be displayed.




Calling Exit from within a subroutine

2010-07-21 Thread Babale Fongo
I call several subroutines within my program.  The program is design in a
way that I don't expect my subroutines to return to the caller but to exit
once they have executed. 

At the moment I don't have exit or return at the end of my subroutines.

 

mysub(); # will the sub return here? If yes what happen if I don't capture
it and act?



.

...

reset of the code

 

sub mysub{

   do this

  don that

  ...

 # I don't call exit or return

}

 

 

I understand a sub will normally implicitly return the last thing it
evaluation, but what happens if I don't act on what has been returned to the
caller? Will be programme stall because it doesn't know what to do next or
will it exit?

 

 Mimi



Win32 Module to change local Password on Remote Computers

2006-03-12 Thread Babale Fongo
Hi,

 

I'm trying to programmatically change a local password on several Computers,
but the Win32API::Net and Win32::NetAdmin modules seem not to be appropriate
for that.

Wondering whether there's any Win32 API module for that. I tried using the
UserChangePassword function, and wasn't surprise it didn't work.

 

 

use diagnostics;

use Net::Ping;

use Win32API::Net qw(:User);

use strict;

 

my $host = 'localhost';

 

my $obj = Net::Ping->new("icmp");

 

print "\nTrying to ping $host\n..\n";

 

if ($obj->ping($host, 2)){

print "Ping successful\n";



if (UserChangePassword("$host", 'user', 'oldpasswd ',
'ChangedNow')){

 

print "Work ok\n";



}else { print "Failed: $^E\n";}



}else {

print "Could not ping\n";

}

 

$obj->close();

 

#

 

Any suggestion...?

 

Thanks 

Babs

 



RE: Compare file modification time

2005-02-14 Thread Babale Fongo
It was just an attempt to see how someone else may tackle this issue.  I
thought of sorting, but I wasn't sure it will do exactly what I expect.
Here is what I've have so far:

my $dir = "/mydir";

opendir(DH, "$dir") || die "Failed to open $dir: $!\n";

my $counter = 0;
while (defined(my $file = readdir (DH))){
next if $file =~ /^\.+$/;
push @files, $file;
$counter++;

}
  closedir (DH);

if ($counter > 7){

for (@files){
 $file_mtime{$_} = (stat($_))[9];

 Need to compare mtime here...
}


}

||-Original Message-
||From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
||Sent: Saturday, February 12, 2005 5:19 PM
||To: [EMAIL PROTECTED]
||Cc: beginners@perl.org
||Subject: Re: Compare file modification time
||
||[EMAIL PROTECTED] wrote:
||> How do I best compare mtime of several files. I have a script for making
||> daily backups  into a given directory. Now I want to modify it to
||> delete old backups if the total exceed cetain number.
||>
||> The idea was to compare the mtime of all file to figure out old files to
||> delete, but somehow I think it shouldn't be all that complicated.
||> Any elegant idea on how to acomplice this?
||>
||> Thanks
||>
||
||mtimes are just integers, so you can compare them with the normal math
||operators. Theoretically you can open a directory, list the files, read
||the mtimes with c into a hash with file/mtime structure. Then just
||sort the hash by the mtime, and remove any files beyond your desired
||threshold.
||
||What have you tried?  Where did you fail?
||
||perldoc -f opendir
||perldoc -f readdir
||perldoc -f unlink
||perldoc -f stat
||perldoc -f sort
||
||Those 5 functions should get you started...
||
||http://danconia.org
||
||--
||To unsubscribe, e-mail: [EMAIL PROTECTED]
||For additional commands, e-mail: [EMAIL PROTECTED]
|| 
||




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




RE: :SSH (How to split value returned by a system command)

2005-02-02 Thread Babale Fongo
It is a bit weird, but I could workaround it by first joining  the value,
and splitting it thereafter:

@splitted = split /\s+/, join "", @found;

Thanks anyway...



||-Original Message-
||From: Babale Fongo [mailto:[EMAIL PROTECTED]
||Sent: Wednesday, February 02, 2005 11:59 PM
||To: beginners@perl.org
||Subject: Net::SSH (How to split value returned by a system command)
||
||This is what I had:
||
||@found = remote_cmds ("find $remdir  -name '*.zip'");
||
||print "@found" look like this:
||
||/path/file1.zip
||/path/file2.zip
||/path/file3.zip
||
||@found is neither a list nor string, so it is not handy to deal with.
||
||
|| In scalar context, the command returns 1 (true), in list context it
returns
||a list of files (one per line).
|| But the value of @found is not a list, but I can't split it either.
||
|| I tried: @splitted list = spilt /\n/, @found; # didn't work!
||@splitted list = spilt / /, @found; # didn't work either
||
||Has anyone an idea on how split the return?
||
||sub remote _cmds {
||
||  my $cmd = shift;
||
||  my @ret = ssh_cmd ({
|| host => "$host",
||   user => "$user",
||   command => "$cmd"
||}) || die "$!";
||
||return @ret;
||
||
||}




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




Net::SSH (How to split value returned by a system command)

2005-02-02 Thread Babale Fongo
This is what I had:

@found = remote_cmds ("find $remdir  -name '*.zip'");

print "@found" look like this:

/path/file1.zip
/path/file2.zip
/path/file3.zip

@found is neither a list nor string, so it is not handy to deal with.


 In scalar context, the command returns 1 (true), in list context it returns
a list of files (one per line).
 But the value of @found is not a list, but I can't split it either.

 I tried: @splitted list = spilt /\n/, @found; # didn't work!
@splitted list = spilt / /, @found; # didn't work either

Has anyone an idea on how split the return? 

sub remote _cmds {

my $cmd = shift;

my @ret = ssh_cmd ({
 host => "$host",
 user => "$user",
 command => "$cmd"  
}) || die "$!";

return @ret;


}

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


RE: How does defined work?

2005-01-04 Thread Babale Fongo
Both Zero "0" and empty string " " are defined values in Perl, so if you
want to test for values other than zero or empty string; then try something
like thing:

if ($nUserId) { # so "0", 0 or " " will fail here
  $juror_number = $nUserId;
} else {
  die "No valid ID for User";
}


||-Original Message-
||From: Siegfried Heintze [mailto:[EMAIL PROTECTED]
||Sent: Monday, January 03, 2005 6:58 AM
||To: beginners@perl.org
||Subject: How does defined work?
||
||I am posting this query in beginners instead of beginners-cgi because I
||believe this is a question about the defined statement and not the
$q->param
||statement/function.
||
||I'm using this code:
||$q = new CGI;
||my $nUserId  = $q->param("userId") ;
||
||I was hoping the defined keyword would tell me if userId was present, but
it
||does not seem to be doing that.
||
||How can I make this execute the die statement when userId is missing from
my
||get/post parameters?
||
||if (defined $nUserId) {
||  $juror_number = $nUserId;
||} else {
||  die "No valid ID for User";
||}
||
||Thanks,
||Siegfried
||
||
||--
||To unsubscribe, e-mail: [EMAIL PROTECTED]
||For additional commands, e-mail: [EMAIL PROTECTED]
|| 




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




RE: Regex to match valid host or dns names

2004-10-13 Thread Babale Fongo

Hi,

My original regex to match ips is this:
 "$_ =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}/;", which is ok. But matching dns name
is still a problem. 

K.Prabakar's  suggestion looks good but also failed the test:

"$_ =~ /^\w\w*-?\w+?[\.\w\w*-?\w+?]*$/",

 It will match an invalid dns name like this (host-.domain.com) as a valid.
I'm still working on it, but will welcome any other suggestion.

Babs

||-Original Message-
||From: Steve Bertrand [mailto:[EMAIL PROTECTED]
||Sent: Wednesday, October 13, 2004 5:24 PM
||To: K.Prabakar
||Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
||Subject: Re: Regex to match valid host or dns names
||
||>
||>> example below, it fails to match "host-no.top-level" as a valid host
||>> name. I modify the regex several times - but still don't get the
||>> right
||>> outlook.
||>>
||>> my @hosts = qw(192.168.22.1 192.168.22.18 localhost
||>> another.host.domain
||>> host-no.top-level my.host.domain.com);
||>> foreach (@hosts){
||>> # Works ok
||>> push (@ips, $_ ) if $_ =~ /^\d{1,3}\.\d{1,3}\.\d{1|3}/;
||>>
||>> # Can't match "host-no.top-level".
||>> push (@dns, $_) if $_ =~ /^\w+-?[\w+]?\.?[\w+.{1}]*\w+$/;
||>> }
||
||I'm just beginning to learn a bit about some of the more obscure
||regex's, but I'd like to ask if this following regex would ensure no
||IP's got trapped in the @dns array? (Assuming that no .tld ends in a
||\d):
||
||push (@dns, $_) if $_ =~ /^\w+-?[\w+]?\.?[\w+.{1}]*[a-zA-Z]{2,3}$/;
||
||Steve
||
||
||
||
||>
||>
||>
||>
||>  /^\w+-?[\w+]?\.?[\w+.{1}]*\w+$/-->Here you look for only one "-"
||> and
||> also not allowing any other non-word charaters(like hyphen).
||>
||> The "." can match any character even other than "-" .
||>
||> You can think like this:(For IP's)
||>  search for a number with maximum 3 digits and
||> then followed by the same kind of 3 numbers but prefixed with a dot.
||> Try this ---> $_ =~ /^\d{1,3}[\.\d{1,3}]{3}/
||>
||> You can think like this:(For DNS's)
||> search for a WORD which may(-?) contain hyphen
||> within it and then followed by the same kind of zero-or-more-WORDs
||> but prefixed with a dot which is a normal dns name pattern.
||>
||> Try this > $_ =~ /^\w\w*-?\w+?[\.\w\w*-?\w+?]*$/
||>
||> But this will allow IP's also in your "@dns" because \w can match
||> digits
||> also.
||>
||>
||>
||> --
||> Regards,
||> K.Prabakar
||>
||> --
||> To unsubscribe, e-mail: [EMAIL PROTECTED]
||> For additional commands, e-mail: [EMAIL PROTECTED]
||>  
||>
||>
||>
||
||
||
||--
||To unsubscribe, e-mail: [EMAIL PROTECTED]
||For additional commands, e-mail: [EMAIL PROTECTED]
|| 




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




CGI.pm / Upload File / delete temporary file (CGITemp****)

2004-05-14 Thread Babale Fongo



You don't have to bother about deleting it. GCI.pm takes care of that.

HTH



||
||Hi All,
||
||Been ages since I last posted to this list...
||
||Anyhoo, I have a script which handles the uploading of a file.
||
||It uses the CGI module to get the form params etc and open/read/close
||statements to receive the file.  This is fine and all works well.  The
||problem is a temporary file (of the same size as the uploaded file) is
||created in the TEMP directory.  It has a name along the lines of
||'CGITemp' where the asterisks represent a sequence number.
||
||Is there any switch/arg to prevent this or at least delete this file
when
||the upload is completed?  I have googled to no avail.
||
||I suppose I could just delete it myself but I don't know the CGITemp
||sequence number.
||
||If no one knows I guess i'll have to have a look at the code for
CGI.pm :(
||
||I'm on Win32, perl v5.6.1, CGI v2.752
||
||Thanks
||
||Toby
||
||--
||To unsubscribe, e-mail: [EMAIL PROTECTED]
||For additional commands, e-mail: [EMAIL PROTECTED]
|| 




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




RE: Question about CPAN modules

2004-05-04 Thread Babale Fongo


The program will most likely be hosted by an ISP.  As most ISPs only
have standard Perl modules installed on their machines. The modules my
program need are not default modules, so I want to distribute my program
together with those modules.



||> -Original Message-
||> From: NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED]
||> Sent: Tuesday, May 04, 2004 12:54 PM
||> To: Babale Fongo; [EMAIL PROTECTED]
||> Subject: RE: Question about CPAN modules
||> 
||> > -Original Message-
||> > From: Babale Fongo [mailto:[EMAIL PROTECTED]
||> > Sent: Monday, May 03, 2004 10:54 PM
||> > To: [EMAIL PROTECTED]
||> > Subject: Question about CPAN modules
||> >
||> >
||> > My program depends on some CPAN modules (e.g. Image::Magick,
||> > MD5::Digest) to operate, so I want to distribute it with
||> > those modules. How do I best redistribute module?  Is it
||> > possible to pre-install modules (copy) in my program folder
||> > for distributed?
||> 
||> What you mean by "redistribute your module" ?
||> Are you trying to send your program to people
||> Who don't perl installed on their machine ?
||> 
||> José.
||> 
||> 
||>  DISCLAIMER 
||> 
||> "This e-mail and any attachment thereto may contain information
which is confidential and/or protected by
||> intellectual property rights and are intended for the sole use of
the recipient(s) named above.
||> Any use of the information contained herein (including, but not
limited to, total or partial reproduction,
||> communication or distribution in any form) by other persons than the
designated recipient(s) is prohibited.
||> If you have received this e-mail in error, please notify the sender
either by telephone or by e-mail and delete the
||> material from any computer".
||> 
||> Thank you for your cooperation.
||> 
||> For further information about Proximus mobile phone services please
see our website at
||> http://www.proximus.be or refer to any Proximus agent.



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




Question about CPAN modules

2004-05-04 Thread Babale Fongo
My program depends on some CPAN modules (e.g. Image::Magick,
MD5::Digest) to operate, so I want to distribute it with those modules.
How do I best redistribute module?  Is it possible to pre-install
modules (copy) in my program folder for distributed?
 
Regard
 
Babs  
 


Regex to match domain for cookie

2004-04-16 Thread Babale Fongo
How do I match a domain name starting from the dot? 
 
# Match something like these
".domain4you.co.uk"
".domain-house.de"
 
 
This is what I have:
 
 
@domains = ("http://www.domain.com ", "http://www.domain4you.co.uk  
"http://www.domain-house.de"; "https//rrp.cash-day.com"
  );
 
 
foreach (@domains){
 
$_ =~ /^\D ([\.A-Za-z0-9]+[\.\D])$/; # What is wrong here?
# Need ".domain.com", but I get "ww.domain.com"
$x = $1;
print "$x";
 
 
}
 
 
 
Babs
 
 


Why is path to perl not included in modules?

2004-03-24 Thread Babale Fongo
I've realised that, most perl modules do not have #!/usr/bin/perl
written on the first line.
Does it implies - that modules don't need the perl interpreter to
function?
 
Thanks


if-else-statemnet question

2003-09-04 Thread Babale Fongo
Hello

Below is a  portion of a script that displays a table. The argument
passed by param() determines the number of rows the table should
display. 
For some unknown reason, the value of param() seem to behave strangely.
It at times the value does not change; even if a different number is
sent as an argument to the script.  What is wrong in the conditional
statement or param(). I tried "my $value_of_param " and "use vars
qw($value_of_param)"  but the value remains unpredictable.  

Thanks for any help


#

@links = (1..$pages) if $pages;
foreach $link (@links){

print qq(  [$link]  ); # Clicking
the link sends the value to this script as parameter.
}
   
#my $value_of_param;
use vars qw($value_of_param);

if ($obj->param('action')){
  $value_of_param = $obj->param('action');
 if ($value_of_param == 1){

$sql = "$query LIMIT 0, $max_rows";
 }
 elsif ($value_of_param == 2){
$sql = "$query LIMIT 51, $max_rows";
   }
   else {
  $start_po += ((50 * $value_of_param) + 1);
  $sql = "$query LIMIT $start_po, $max_rows";
   }

   }
   else {
  $sql = "$query LIMIT $start_po, $max_rows";
   }

# See value of  param() :
print qq($value_of_param) if ($value_of_param);






Why "Global symbol require explicit package name"

2003-06-27 Thread Babale Fongo
Hello guy!

I would like to know why I need to declare global variables with "my".

My script looks something like thing:
Use strict;
$strg = "A string";
$strg2 = "a second string";

I get a warning:
"Global symbol require explicit package name."

unless I declare the variables like: 
my $strg = "A string";
my $strg2 = "a second string";

Thanks






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