Re: Syntax problem

2018-03-28 Thread Shlomi Fish
Hi,

On Wed, 28 Mar 2018 13:00:47 +0700
Olivier  wrote:

> Hi,
> 
> I am building a script to modify my LDAP directory and I want to use
> something like:
> 
> $mesg = $ldap->modify( $dn,
>   replace => {
> description => 'New List of members',
> seeAlso => 'Some reference'
>   }
> );
> 
> But I would like to build the list of replacements dynamically, that is,
> have a variable of the appropriate type, where I can first store
> "description" and "New List of members" then also store "seeAlso" and
> "Some reference"; and then only use that variable to do the replace.
> 

please see http://perl-begin.org/topics/references/ .

> I have two questions:
> 
> - What type should I use for the variable?
> 
> - What will be the syntax for the $ldap->modify statement?
> 
> Thanks in advance,
> 
> Olivier
> 
> 
> 



-- 
-
Shlomi Fish   http://www.shlomifish.org/
“So, who the hell is Qoheleth?” - http://shlom.in/qoheleth

When people agree with me I always feel I must be wrong.
— https://en.wikiquote.org/wiki/Oscar_Wilde (via fortune-mod)

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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




Syntax problem

2018-03-28 Thread Olivier
Hi,

I am building a script to modify my LDAP directory and I want to use
something like:

$mesg = $ldap->modify( $dn,
  replace => {
description => 'New List of members',
seeAlso => 'Some reference'
  }
);

But I would like to build the list of replacements dynamically, that is,
have a variable of the appropriate type, where I can first store
"description" and "New List of members" then also store "seeAlso" and
"Some reference"; and then only use that variable to do the replace.

I have two questions:

- What type should I use for the variable?

- What will be the syntax for the $ldap->modify statement?

Thanks in advance,

Olivier



-- 

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




syntax problem

2002-10-22 Thread Chris Benco
Fairly new to perl, and even programming in general.

 When I try to have this program it to a large number of pings (anything
over about 200) it times out.  There is a built in feature to
Net::Telnet::Cisco to change the Timeout value, but I can't seem to get it
coded correctly.

http://search.cpan.org/author/JOSHUA/Net-Telnet-Cisco-1.10/Cisco.pm

shows this

$ok = $obj-cmd($string);
$ok = $obj-cmd(String   = $string,
[Output  = $ref,]
[Prompt  = $match,]
[Timeout = $secs,]
[Cmd_remove_mode = $mode,]);

@output = $obj-cmd($string);
@output = $obj-cmd(String   = $string,
[Output  = $ref,]
[Prompt  = $match,]
[Timeout = $secs,]
[Cmd_remove_mode = $mode,]
[Normalize_cmd = $boolean,]);

#

use strict;
use warnings;
use Net::Telnet::Cisco;

my $protocol  = '';
my $ip   = $ARGV[1];
my $repeat= $ARGV[0];
my $datagram  = '';
my $timeout   = '';
my $extended  = '';
my $sweep = '';

my $session = Net::Telnet::Cisco-new(host = '10.0.0.1') or die Can not
connect to host0;
$session-login('Password','password') or die 1;
$session-enable('enablepass') or die 2;
my @output = $session-cmd(

ping
$protocol
$ip
$repeat
$datagram
$timeout
$extended
$sweep
);
foreach (@output) {
if ($_ =~ /Success/){
print $_;
}
}



adding

$session-cmd(Timeout = 3600);
my @output = $session-cmd(

gives no error but doesn't help, while

my @output = $session-cmd(
Timeout = 3600,
ping

gives me the error

usage: $obj-cmd([Cmd_remove = $boolean,] [Output = $ref,] [Prompt =
$match,]
 [String = $string,] [Timeout = $secs,]) at C:\x\PingR.pl line 16




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




Re: syntax problem

2002-10-22 Thread Michael Fowler
On Tue, Oct 22, 2002 at 12:49:48PM -0400, Chris Benco wrote:
[snip]
 my @output = $session-cmd(
 
 ping
 $protocol
 $ip
 $repeat
 $datagram
 $timeout
 $extended
 $sweep
 );

[snip]
 $session-cmd(Timeout = 3600);
 my @output = $session-cmd(

[snip]
 my @output = $session-cmd(
 Timeout = 3600,
 ping
[snip]


According to the documentation, the cmd() method can be called one of two
ways: with one argument, or with a list of key-value pairs.

In your first example you're using the one-argument form.  Everything works.

In your second example you attempt to call cmd() twice, expecting the
Timeout specified in the first call to apply to the second call.  I'm not
sure why you thought this would work, but as far as I can tell each cmd()
call is seperate.

In your third example you mix the two different call forms; if you're using
key-value pairs your command has to be specified using the String key, i.e.:

my @output = $session-cmd(
String  =  ping\n$protocol\n$ip\n...,
Timeout =  3600,
);


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




mysql syntax problem

2002-10-02 Thread Steven_Massey

Hi all

when i query a mysql db within a perl script
this works fine...
$sth = $dbh-prepare (SELECT venue from base1 WHERE op = 'K Trevan');

this doesn't..
$sth = $dbh-prepare (SELECT venue from base1 WHERE op = 'K O'Trevan');

i know the issue is 'K O'Trevan'  in that the 2nd ' completes

i just don't know how to resolve it  - other than  changing 'K O'Trevan' to
'K O Trevan'

Any ideas appreciated

Steve











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




Re: mysql syntax problem

2002-10-02 Thread Michael Fowler

On Wed, Oct 02, 2002 at 09:06:16AM +0100, [EMAIL PROTECTED] wrote:
 when i query a mysql db within a perl script
 this works fine...
 $sth = $dbh-prepare (SELECT venue from base1 WHERE op = 'K Trevan');
 
 this doesn't..
 $sth = $dbh-prepare (SELECT venue from base1 WHERE op = 'K O'Trevan');
 
 i know the issue is 'K O'Trevan'  in that the 2nd ' completes
 
 i just don't know how to resolve it  - other than  changing 'K O'Trevan' to
 'K O Trevan'

Use placeholders:

$sth = $dbh-prepare(SELECT venue FROM base1 WHERE op = ?);
$sth-execute(K O'Trevan);

This is a little silly with literal values, as you can easily escape them
manually.  It works much better with data you get from sources that won't
escape it, such as user input.

Read about placeholders in perldoc DBI.

As for manually escaping your values, that's an SQL question, and you should
read the documentation on your database for information on that.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




Re: mysql syntax problem

2002-10-02 Thread Steven_Massey


Michael   Excellent - read DBI/placeholder

thanks



   

  Michael Fowler   

  michael@shoebox To:  [EMAIL PROTECTED] 

  .netcc:  [EMAIL PROTECTED] 

   Subject: Re: mysql syntax problem   

  10/02/02 09:33   

  AM   

   

   





On Wed, Oct 02, 2002 at 09:06:16AM +0100, [EMAIL PROTECTED]
wrote:
 when i query a mysql db within a perl script
 this works fine...
 $sth = $dbh-prepare (SELECT venue from base1 WHERE op = 'K Trevan');

 this doesn't..
 $sth = $dbh-prepare (SELECT venue from base1 WHERE op = 'K O'Trevan');

 i know the issue is 'K O'Trevan'  in that the 2nd ' completes

 i just don't know how to resolve it  - other than  changing 'K O'Trevan'
to
 'K O Trevan'

Use placeholders:

$sth = $dbh-prepare(SELECT venue FROM base1 WHERE op = ?);
$sth-execute(K O'Trevan);

This is a little silly with literal values, as you can easily escape them
manually.  It works much better with data you get from sources that won't
escape it, such as user input.

Read about placeholders in perldoc DBI.

As for manually escaping your values, that's an SQL question, and you
should
read the documentation on your database for information on that.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--






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




RE: mysql syntax problem

2002-10-02 Thread nkuipers

Use placeholders:

Could you also use quote() for this?

Ain't no blood in my body, it's liquid soul in my veins
~Roots Manuva


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




Re: mysql syntax problem

2002-10-02 Thread Michael Fowler

On Wed, Oct 02, 2002 at 09:25:43AM -0700, nkuipers wrote:
 Could you also use quote() for this?

Yes, $dbh-quote() can also be used for quoting strings.  I generally don't
suggest it because it's more awkward and makes for less readable code than
placeholders.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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