perl and PostgreSQL?

2005-02-01 Thread Mariano Cunietti
Hi,
can anybody address me to online resources to learn how to connect to a
PostgreSQL DB server through a Perl script?
Code examples are welcome ;-)
TIA

Mariano

-
Mariano Cunietti
System Administrator
Enter S.r.l.
Via  Stefanardo da Vimercate, 28
20128 - Milano - Italy
Tel.  +39 02 25514319
Fax   +39 02 25514303
[EMAIL PROTECTED]
www.enter.it - www.enterpoint.it
-
Gruppo Y2K - www.gruppoy2k.it


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




Re: perl and PostgreSQL?

2005-02-01 Thread Remo Sanges
On Feb 1, 2005, at 11:21 AM, Mariano Cunietti wrote:
Hi,
can anybody address me to online resources to learn how to connect to a
PostgreSQL DB server through a Perl script?
http://www.perl.com/pub/a/1999/10/DBI.html
http://search.cpan.org/~timb/DBI/DBI.pm
http://search.cpan.org/~rudy/DBD-Pg-1.32/Pg.pm
HTH
Remo
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Different key in 2 hashes

2005-02-01 Thread Mark Martin
Hi,
okay  - straight out of the coobook :
my @different = ()
foreach (keys %hash1)
{
  delete $hash1{$_} unless exists $hash2$_};
  push(@this_not_that,$_) unless exists $registered{$_};
}
easy to remove the different key from hash one and record the removed item 
in @different.

My question is how would you record the removed item in another hash so 
that it has the original key and corresponding value?

I've tried :
%different = ();
foreach $key (keys %hash1)
{
  $value = $hash1{$key};
  @different{$_} = $value unless exists $hash2{$_};
}
but I get all sorts of rubbish
Cheers,
Mark
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Different key in 2 hashes

2005-02-01 Thread Remo Sanges
On Feb 1, 2005, at 1:53 PM, Mark Martin wrote:
Hi,
okay  - straight out of the coobook :
my @different = ()
foreach (keys %hash1)
{
  delete $hash1{$_} unless exists $hash2$_};
  push(@this_not_that,$_) unless exists $registered{$_};
}
easy to remove the different key from hash one and record the removed 
item in @different.

My question is how would you record the removed item in another hash 
so that it has the original key and corresponding value?

I've tried :
%different = ();
foreach $key (keys %hash1)
{
  $value = $hash1{$key};
  @different{$_} = $value unless exists $hash2{$_};
}
$different{$key} = $value unless exists $hash2{$key};
HTH
Remo
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Different key in 2 hashes

2005-02-01 Thread Bob Showalter
Mark Martin wrote:
> Hi,
> okay  - straight out of the coobook :
> 
> my @different = ()
> foreach (keys %hash1)
> {
>delete $hash1{$_} unless exists $hash2$_};
>push(@this_not_that,$_) unless exists $registered{$_};
> }
> 
> easy to remove the different key from hash one and record the removed
> item in @different.
> 
> My question is how would you record the removed item in another hash
> so that it has the original key and corresponding value?
> 
> I've tried :
> 
> %different = ();
> foreach $key (keys %hash1)
> {
>$value = $hash1{$key};
>@different{$_} = $value unless exists $hash2{$_};
> }

You're using $_, but $key has the key

> 
> but I get all sorts of rubbish

delete() returns the thing(s) deleted, so

for my $key (keys %hash1) {
$different{$key} = delete $hash1{$key} unless exists $hash2{$key};
}

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




Compile perl code/files via STDIN

2005-02-01 Thread Michael Seele
hi,
i want to open a perl process and enter the code/files to compile via 
STDIN. i know it is possible. but how?
does somebody know a tutorial or something like this which explains how 
i can compile perl code via STDIN?
thx mseele

--
G & H Softwareentwicklung GmbH Tel.: +49(0)7451/53706-20
Robert-Bosch-Str. 23   Fax:  +49(0)7451/53706-90
D-72160 Horb a.N.  http://www.guh-software.de 

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



rmdir

2005-02-01 Thread dsimmons

I want to delete the files from a directory
then delete the directory.

I have code which processes a file containing
a list of files, one per line.  
That routine creates a subdirectory
based on the file name and then writes files to the subdirectory.

I have the following code to process
the same file containing the list of file names, deleting the files in
the relevant subdirectory then attempting delete the directory.

However, when attempting to delete the
directory the routine indicates that permission is denied.  

The code follows the source, delete_dir.pl
is attached.  Also is an example of the source for delete_dir.pl

The command line input is delete_dir.pl
dir_test.txt

Thanks in advance for your feedback.

use strict;
use warnings;

open(INFILE,   "<  $ARGV[0]")
|| die("can't open inputfile: $ARGV[0]");

my $fname = "";
my $fext = "";
my $wait = "";
my $name = "";
my $retval = "";

while () {
        chomp($_);
        print
"$_\n";
        ($fname,$fext)
= split(/\./,$_);
        print
"file name:      $fname\n";
        print
"file extension: $fext\n";
        
        opendir(DIR,
$fname) || print "no $fname directory!\n";
        $wait
= ;
        
        while
($name = readdir(DIR)) {
         
 print "$name\n";
         
 $name = $fname."\\".$name;
         
 unlink($name);
         
 print "$name\n";
         
 
        }
        rmdir($fname)
|| warn "cannot delete $fname: $!";
        $wait
= ;
} #endwhile

DTR012008DT040929.PRN
DTR112008DT040929.PRN=

delete_dir.pl
Description: Binary data
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: rmdir

2005-02-01 Thread Ing. Branislav Gerzo
[EMAIL PROTECTED] [d], on Tuesday, February 1, 2005 at 09:58 (-0500)
thinks about:

d> I want to delete the files from a directory then delete the directory.

use File::Path;
$remove = 'C:\temp';
rmtree($remove) if -e $remove;

more @ http://search.cpan.org/~nwclark/perl-5.8.6/lib/File/Path.pm

-- 

 ...m8s, cu l8r, Brano.

[Quarterbacks do it from behind]



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




Re: rmdir

2005-02-01 Thread Mariano Cunietti
Hi,
I was wondering if there is anybody who can show me the *correct* way to
use a fast pattern-search-and-assign.

I mean: I am extracting viertual aliases from a postfix config file:

# cannot use 'split' function, some statements in the second field may
contain whitespaces (e.g. ERROR "blah blah")
my ($virtual, $address) = ($_ =~ /^([^\s]+) (.*)$/);

but I always get:

"Use of uninitialized value in printf at 
./extract_users_virtusertable.pl line 16"

even if I try using the slow approach (extract, then assign using $1 and
$2), it doesn't work.
What's wrong?
TIA


-
Mariano Cunietti
System Administrator
Enter S.r.l.
Via  Stefanardo da Vimercate, 28
20128 - Milano - Italy
Tel.  +39 02 25514319
Fax   +39 02 25514303
[EMAIL PROTECTED]
www.enter.it - www.enterpoint.it
-
Gruppo Y2K - www.gruppoy2k.it


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




RE: Different key in 2 hashes

2005-02-01 Thread Mark Martin
Thank you - worked a treat.
At 09:00 01/02/2005 -0500, Bob Showalter wrote:
Mark Martin wrote:
> Hi,
> okay  - straight out of the coobook :
>
> my @different = ()
> foreach (keys %hash1)
> {
>delete $hash1{$_} unless exists $hash2$_};
>push(@this_not_that,$_) unless exists $registered{$_};
> }
>
> easy to remove the different key from hash one and record the removed
> item in @different.
>
> My question is how would you record the removed item in another hash
> so that it has the original key and corresponding value?
>
> I've tried :
>
> %different = ();
> foreach $key (keys %hash1)
> {
>$value = $hash1{$key};
>@different{$_} = $value unless exists $hash2{$_};
> }
You're using $_, but $key has the key
>
> but I get all sorts of rubbish
delete() returns the thing(s) deleted, so
for my $key (keys %hash1) {
$different{$key} = delete $hash1{$key} unless exists $hash2{$key};
}
--
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: rmdir

2005-02-01 Thread Ing. Branislav Gerzo
Mariano Cunietti [MC], on Tuesday, February 01, 2005 at 16:19 (+0100)
typed:

MC> I was wondering if there is anybody who can show me the *correct* way to
MC> use a fast pattern-search-and-assign.
MC> I mean: I am extracting viertual aliases from a postfix config file:

1. you did not change subject
2. if you even did, it is bad posting, if you reply to something and
   change subject (bad references)
3. always make new message and fill TO field with beginners@perl.org

MC> # cannot use 'split' function, some statements in the second field may
MC> contain whitespaces (e.g. ERROR "blah blah")
MC> my ($virtual, $address) = ($_ =~ /^([^\s]+) (.*)$/);

I am not on UNIX, but I should help you, if you send some example
data (always do that).

-- 

 ...m8s, cu l8r, Brano.

["Two wrongs do not make a right; it usually takes three or more."
L.Long]



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




assigning values from a regexp

2005-02-01 Thread Mariano Cunietti

On Tue, 2005-02-01 at 16:33, Ing. Branislav Gerzo wrote:
> Mariano Cunietti [MC], on Tuesday, February 01, 2005 at 16:19 (+0100)
> typed:
> 
> MC> I was wondering if there is anybody who can show me the *correct* way to
> MC> use a fast pattern-search-and-assign.
> MC> I mean: I am extracting viertual aliases from a postfix config file:
> 
> 1. you did not change subject
> 2. if you even did, it is bad posting, if you reply to something and
>change subject (bad references)
> 3. always make new message and fill TO field with beginners@perl.org

sorry, put the Lame on me...I missed to change the subject while
creating a new post

> MC> # cannot use 'split' function, some statements in the second field may
> MC> contain whitespaces (e.g. ERROR "blah blah")
> MC> my ($virtual, $address) = ($_ =~ /^([^\s]+) (.*)$/);
> 
> I am not on UNIX, but I should help you, if you send some example
> data (always do that).

here are some example data:

[EMAIL PROTECTED]   mbiondi
[EMAIL PROTECTED]  salesenter
[EMAIL PROTECTED] cbersa
[EMAIL PROTECTED]  aluffstampa
[EMAIL PROTECTED] contab1
[EMAIL PROTECTED]sales
[EMAIL PROTECTED] sonia
[EMAIL PROTECTED]aliasupersonale
[EMAIL PROTECTED] noautostaff
[EMAIL PROTECTED]  aliasecurity
[EMAIL PROTECTED]  fgiannil
[EMAIL PROTECTED]   fgiannil
[EMAIL PROTECTED] renea
[EMAIL PROTECTED]sergio
[EMAIL PROTECTED]vpiazza
[EMAIL PROTECTED]   alazzara
@consulting.iteuconsulting

It seems something goes wrong with the regexp, assigning the whole $_ to
first variable

> -- 
> 
>  ...m8s, cu l8r, Brano.
> 
> ["Two wrongs do not make a right; it usually takes three or more."
> L.Long]
-- 
-
Mariano Cunietti
System Administrator
Enter S.r.l.
Via  Stefanardo da Vimercate, 28
20128 - Milano - Italy
Tel.  +39 02 25514319
Fax   +39 02 25514303
[EMAIL PROTECTED]
www.enter.it - www.enterpoint.it
-
Gruppo Y2K - www.gruppoy2k.it


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




Re: assigning values from a regexp

2005-02-01 Thread Ing. Branislav Gerzo
Mariano Cunietti [MC], on Tuesday, February 01, 2005 at 16:44 (+0100)
thinks about:

>> MC> my ($virtual, $address) = ($_ =~ /^([^\s]+) (.*)$/);

maybe this helps you:
my ($virtual, $adress) = /^([^\s]+)\s+(.*)$/;

-- 

 ...m8s, cu l8r, Brano.

["That damnabley kind of you, Mr. Mallory!" Arturo]



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




Re: Compile perl code/files via STDIN

2005-02-01 Thread JupiterHost.Net

Michael Seele wrote:
hi,
Hello,
i want to open a perl process and enter the code/files to compile via 
STDIN. i know it is possible. but how?
does somebody know a tutorial or something like this which explains how 
i can compile perl code via STDIN?
Do you mean:
perl -e 'print "Hi\n";'
perl script.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Similar C++ digest?

2005-02-01 Thread Christopher Spears
This digest has really helped me learn Perl, so I was
wondering if there is a similar digest for beginning
C++ programmers.

-Chris

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




Re: perl and PostgreSQL?

2005-02-01 Thread Lawrence Statton
> Hi,
> can anybody address me to online resources to learn how to connect to a
> PostgreSQL DB server through a Perl script?
> Code examples are welcome ;-)
> TIA
> 

-  begin perl code  ---

#!/usr/bin/perl

use strict;
use warnings;
use DBI; 

our $_dbh; 

use constant DB_DSN => 'dbi:Pg:dbname=test;';
use constant DB_USER => 'your-user-identity-not-mine';
use constant DB_PASSWORD => 'your-secret-password-not-mine' ;

sub DBH
{
return $_dbh if $_dbh && $_dbh->ping; 

for my $tries (1..10) {
$_dbh = DBI->connect( DB_DSN, DB_USER, DB_PASSWORD );
return $_dbh if $_dbh && $_dbh->ping ;
sleep ( $tries * 3 ) ; 
}
}

my $sth = DBH->prepare( q {
SELECT CITY.NAME, STATE.NAME
FROM CITY
JOIN STATE
ON CITY.STATE = STATE.ABBREV
WHERE CITY.POPULATION > 5
} ) or die "Prepare: ", DBH->errstr ;

$sth->execute( )
or die "Execute: ", $sth->errstr ;

while (my ($city, $state) = $sth->fetchrow_array ) {
print "$city is in $state\n"; 
}


--- end perl code -

Of course this entire program is predicated on having a database ... 

Here is the one I used in pg_dump format (editted for brevity)

CREATE TABLE state (
name character varying,
abbrev character(2) NOT NULL
);

COPY state (name, abbrev) FROM stdin;
Alabama AL
California  CA
Oregon  OR
Washington  WA
Nevada  NV
Idaho   ID
Arizona AZ
\.

ALTER TABLE ONLY state
ADD CONSTRAINT state_pkey PRIMARY KEY (abbrev);

CREATE TABLE city (
name character varying,
state character(2),
population integer
);

COPY city (name, state, population) FROM stdin;
San Francisco   CA  75
Phoenix AZ  120
PortlandOR  54
Montgomery  AL  20
Birmingham  AL  242000
Redding CA  81000
Eugene  OR  138000
Olympia WA  42500
Seattle WA  57
Las Vegas   NV  48
Boise   ID  185000
Tuscon  AZ  486000
\.

ALTER TABLE ONLY city
ADD CONSTRAINT "$1" FOREIGN KEY (state) REFERENCES state(abbrev);

NB - There are embedded tabs in the COPY sections that your mailer might 
destroy.




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




Re: Compile perl code/files via STDIN

2005-02-01 Thread Dave Gray
> i want to open a perl process and enter the code/files to compile via
> STDIN. i know it is possible. but how?
> does somebody know a tutorial or something like this which explains how
> i can compile perl code via STDIN?

$ perl
print "Hello from STDIN\n";
^D
Hello from STDIN
$ 

If the answers so far don't solve your problem, it might help to be
more specific about what exactly you're trying to do.

Dave

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




Re: perl and PostgreSQL?

2005-02-01 Thread Eduardo Vázquez Rodríguez
Did you have already check the compile process of the Perl Module that 
provides access to Postgres?

If you have do it. Then my code might help you
use DBI;
use diagnostics;
use strict;
my $database="Database";
my $username="postgres";
my $password="123";
my ($mbd, $sth1);
$mbd = DBI->connect("dbi:Pg:dbname=$database", "$username", "$password")
   or die "Error: $DBI::errstr \n";
$sth1 = $mbd->prepare
   ("
 INSERT INTO public.table1 (field1, field2, field3, field4)

   VALUES(?::varchar(10),  ?::varchar(8) , ?::float4 , ?::varchar(15))
");

### Here comes your perl script for didactic purposes I only get 4 
variables ##

### Inserting into the database 
   $sth1->execute ($normal[0],  $normal[1],  $normal[2],  $normal[3])
  
   or die "Error $DBI::errstr\n";

Lawrence Statton wrote:
Hi,
can anybody address me to online resources to learn how to connect to a
PostgreSQL DB server through a Perl script?
Code examples are welcome ;-)
TIA
   

-  begin perl code  ---
#!/usr/bin/perl
use strict;
use warnings;
use DBI; 

our $_dbh; 

use constant DB_DSN => 'dbi:Pg:dbname=test;';
use constant DB_USER => 'your-user-identity-not-mine';
use constant DB_PASSWORD => 'your-secret-password-not-mine' ;
sub DBH
{
   return $_dbh if $_dbh && $_dbh->ping; 

   for my $tries (1..10) {
	$_dbh = DBI->connect( DB_DSN, DB_USER, DB_PASSWORD );
	return $_dbh if $_dbh && $_dbh->ping ;
	sleep ( $tries * 3 ) ; 
   }
}

my $sth = DBH->prepare( q {
   SELECT CITY.NAME, STATE.NAME
FROM CITY
JOIN STATE
ON CITY.STATE = STATE.ABBREV
WHERE CITY.POPULATION > 5
   } ) or die "Prepare: ", DBH->errstr ;
$sth->execute( )
   or die "Execute: ", $sth->errstr ;
while (my ($city, $state) = $sth->fetchrow_array ) {
   print "$city is in $state\n"; 
}

--- end perl code -
Of course this entire program is predicated on having a database ... 

Here is the one I used in pg_dump format (editted for brevity)
CREATE TABLE state (
   name character varying,
   abbrev character(2) NOT NULL
);
COPY state (name, abbrev) FROM stdin;
Alabama AL
California  CA
Oregon  OR
Washington  WA
Nevada  NV
Idaho   ID
Arizona AZ
\.
ALTER TABLE ONLY state
   ADD CONSTRAINT state_pkey PRIMARY KEY (abbrev);
CREATE TABLE city (
   name character varying,
   state character(2),
   population integer
);
COPY city (name, state, population) FROM stdin;
San Francisco   CA  75
Phoenix AZ  120
PortlandOR  54
Montgomery  AL  20
Birmingham  AL  242000
Redding CA  81000
Eugene  OR  138000
Olympia WA  42500
Seattle WA  57
Las Vegas   NV  48
Boise   ID  185000
Tuscon  AZ  486000
\.
ALTER TABLE ONLY city
   ADD CONSTRAINT "$1" FOREIGN KEY (state) REFERENCES state(abbrev);
NB - There are embedded tabs in the COPY sections that your mailer might 
destroy.

 

--
If I have seen further it is by standing on the shoulders of the giants
Isaac Newton
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Ref and deref of hash

2005-02-01 Thread Jerry Preston
I have a .pm file that calls sub a that calls sub b.  Sub B returns %data to
sub a in the form %a_data = sub a;  I am trying to return \%a_data to the
original program that call sub a.

$results = $data->a;

sub a {
%b_data = &b;

# data good!

return \%b_data
}1;

sub b {


return %b_data
}1;

But no $results data.  What am I missing?

Thanks,

Jerry



RE: Ref and deref of hash

2005-02-01 Thread Jerry Preston
GOT IT!

Jerry

-Original Message-
From: Jerry Preston [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 02, 2005 12:14 AM
To: 'Perl Beginners'
Subject: Ref and deref of hash


I have a .pm file that calls sub a that calls sub b.  Sub B returns %data to
sub a in the form %a_data = sub a;  I am trying to return \%a_data to the
original program that call sub a.

$results = $data->a;

sub a {
%b_data = &b;

# data good!

return \%b_data
}1;

sub b {


return %b_data
}1;

But no $results data.  What am I missing?

Thanks,

Jerry



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