Re: case statement in perl

2012-08-01 Thread John W. Krahn

Paul.G wrote:

Below is an extract from the perl script, the switch/case statement seemed like 
a simple solution.



# Mail Program #

operation_CHECKFREEPVS();
print $numPV \n;
# print $FreePV[1] $FreePV[0] $numPV\n;
if ($numPV ne 0 ) {
switch ($numPV) {
   case 1 { print $FreePV[0] \n; }
   case 2 { print $FreePV[0] $FreePV[1] \n; }
   case 3 { print $FreePV[0] $FreePV[1] $FreePV[2] \n; }
}
  }


Couldn't you just do that like this:

if ( @FreePV  @FreePV = 3 ) {
print join( ' ', @FreePV ), \n;
}



  else {
print No PV's available \n;
  }




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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




Re: case statement in perl

2012-08-01 Thread Paul.G
The example below is just a test, I need to be able to insert multiple values 
into a command, those values can be either 1, 2 or upto 5.

Below is closer to the working example, but I will read that document and to 
help make a final decision.

# Check Free PV's
operation_CHECKFREEPVS();

$NEWMIRROR = $MIRROR + $numPV;

if ($numPV ne 0  $MIRROR le 5) {
   # lvextend
print $numPV $NEWMIRROR $MIRROR\n;
    switch ($numPV) {
    case 1 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv 
$FreePV[0]); }
    case 2 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1]); }
    case 3 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1] $FreePV[2]); }
    case 4 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1] $FreePV[2] $FreePV[3]); }
    case 5 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1] $FreePV[2] $FreePV[3] $FreePV[4]);
 }
   } 
   # lvsync
   run(/usr/sbin/lvsync -T $sourcelv);
   logprint Successful $NEWMIRROR mirrors \t\t synced;
}
else {
   cleanexit (10, FAIL \t\t No Free PV's Available);
}

return 0;
}




 From: John W. Krahn jwkr...@shaw.ca
To: Perl Beginners beginners@perl.org 
Sent: Wednesday, 1 August 2012 4:58 PM
Subject: Re: case statement in perl
 
Paul.G wrote:
 Below is an extract from the perl script, the switch/case statement seemed 
 like a simple solution.



 # Mail Program #

 operation_CHECKFREEPVS();
 print $numPV \n;
 # print $FreePV[1] $FreePV[0] $numPV\n;
 if ($numPV ne 0 ) {
     switch ($numPV) {
            case 1 { print $FreePV[0] \n; }
            case 2 { print $FreePV[0] $FreePV[1] \n; }
            case 3 { print $FreePV[0] $FreePV[1] $FreePV[2] \n; }
     }
   }

Couldn't you just do that like this:

if ( @FreePV  @FreePV = 3 ) {
     print join( ' ', @FreePV ), \n;
     }


   else {
     print No PV's available \n;
   }



John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

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

Re: case statement in perl

2012-08-01 Thread Rob Coops
On Wed, Aug 1, 2012 at 9:08 AM, Paul.G medur...@yahoo.com.au wrote:

 The example below is just a test, I need to be able to insert multiple
 values into a command, those values can be either 1, 2 or upto 5.

 Below is closer to the working example, but I will read that document and
 to help make a final decision.

 # Check Free PV's
 operation_CHECKFREEPVS();

 $NEWMIRROR = $MIRROR + $numPV;

 if ($numPV ne 0  $MIRROR le 5) {
# lvextend
 print $numPV $NEWMIRROR $MIRROR\n;
 switch ($numPV) {
 case 1 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv
 $FreePV[0]); }
 case 2 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv
 $FreePV[0] $FreePV[1]); }
 case 3 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv
 $FreePV[0] $FreePV[1] $FreePV[2]); }
 case 4 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv
 $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3]); }
 case 5 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv
 $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3] $FreePV[4]);
  }
}
# lvsync
run(/usr/sbin/lvsync -T $sourcelv);
logprint Successful $NEWMIRROR mirrors \t\t synced;
 }
 else {
cleanexit (10, FAIL \t\t No Free PV's Available);
 }

 return 0;
 }



 
  From: John W. Krahn jwkr...@shaw.ca
 To: Perl Beginners beginners@perl.org
 Sent: Wednesday, 1 August 2012 4:58 PM
 Subject: Re: case statement in perl

 Paul.G wrote:
  Below is an extract from the perl script, the switch/case statement
 seemed like a simple solution.
 
 
 
  # Mail Program #
 
  operation_CHECKFREEPVS();
  print $numPV \n;
  # print $FreePV[1] $FreePV[0] $numPV\n;
  if ($numPV ne 0 ) {
  switch ($numPV) {
 case 1 { print $FreePV[0] \n; }
 case 2 { print $FreePV[0] $FreePV[1] \n; }
 case 3 { print $FreePV[0] $FreePV[1] $FreePV[2] \n; }
  }
}

 Couldn't you just do that like this:

 if ( @FreePV  @FreePV = 3 ) {
  print join( ' ', @FreePV ), \n;
  }


else {
  print No PV's available \n;
}



 John
 --
 Any intelligent fool can make things bigger and
 more complex... It takes a touch of genius -
 and a lot of courage to move in the opposite
 direction.   -- Albert Einstein

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


Why make life so hard as John suggested you check for the number of
arguments and as long as it is less then 5 you simply join them with a
space and you are done with a single line...

No matter what you do you will always have to check the variables that you
are going to push out, right now I could very well feed a parameter that
ends in a ; and then do something like *rm -rf /* which could make a
serious mess of your system...
Personally I would suggest checking the command flags if they are valid,
and do not contain any funny characters before even considdering putting
this in a system call or equivalent.

Regards,

Rob


Re: case statement in perl

2012-08-01 Thread John W. Krahn

Paul.G wrote:

The example below is just a test, I need to be able to insert multiple values 
into a command, those values can be either 1, 2 or upto 5.

Below is closer to the working example, but I will read that document and to 
help make a final decision.

# Check Free PV's
operation_CHECKFREEPVS();

$NEWMIRROR = $MIRROR + $numPV;

if ($numPV ne 0  $MIRROR le 5) {


You are using string comparisons on numerical values which may not work 
out the way you intended:


$ perl -le'
for my $MIRROR ( 0, 1, 4, 5, 6, 10, 4000 ) {
print $MIRROR le 5 is , $MIRROR le 5 ? TRUE : FALSE;
}
'
0 le 5 is TRUE
1 le 5 is TRUE
4 le 5 is TRUE
5 le 5 is TRUE
6 le 5 is FALSE
10 le 5 is TRUE
4000 le 5 is TRUE



# lvextend
print $numPV $NEWMIRROR $MIRROR\n;
 switch ($numPV) {
 case 1 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv 
$FreePV[0]); }
 case 2 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1]); }
 case 3 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1] $FreePV[2]); }
 case 4 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1] $FreePV[2] $FreePV[3]); }
 case 5 { run(/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] 
$FreePV[1] $FreePV[2] $FreePV[3] $FreePV[4]);
  }


You could do that like this:

if ( @FreePV  @FreePV = 5 ) {
run( /usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv @FreePV );
}



}
# lvsync
run(/usr/sbin/lvsync -T $sourcelv);
logprint Successful $NEWMIRROR mirrors \t\t synced;
}
else {
cleanexit (10, FAIL \t\t No Free PV's Available);
}

return 0;
}




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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




Catalyst model problem- WARNING: No tables found, did you forget to specify db_schema?

2012-08-01 Thread Guruprasad Kulkarni
Hi All,

I am trying to learn Catalyst framework, by following the introduction
modules available on CPAN. I am doing this on strawberry perl, on my PC.
Also, I am using SQLite and have created myapp.db.

While trying to create a model, I get the below error:

\strawberry\perl\bin\MyApp\scriptmyapp_create.pl model DB DBIC::Schema
MyApp::Schema create=static dbi:SQLite:myapp.db on_connect_do=PRAGMA
foreign_keys = ON
 exists D:\strawberry\perl\bin\MyApp\lib\MyApp\Model
 exists D:\strawberry\perl\bin\MyApp\t
Dumping manual schema for MyApp::Schema to directory
D:\strawberry\perl\bin\MyApp\lib ...
Schema dump completed.
WARNING: No tables found, did you forget to specify db_schema?
 exists D:\strawberry\perl\bin\MyApp\lib\MyApp\Model\DB.pm
---

The instruction says make sure your myapp.db database file is in the
application's topmost directory.

I tried placing myapp.db in all possible directories but it is not working.
I understand this warning is coming from
Catalyst::Helper::Model::DBIC::Schema.pm,
but I am not able to troubleshoot beyond that.

Can someone tell me where am I suppose to keep the myapp.db file?

Regards
Guru


Re: Catalyst model problem- WARNING: No tables found, did you forget to specify db_schema?

2012-08-01 Thread Guruprasad Kulkarni
Hi Guys,

I found out the issue here:)

Apparently, there is a note towards the end of the doc:


*NOTE:* Be sure you run the script/myapp_server.pl command from the 'base'
directory of your application, not inside the script directory itself or it
will not be able to locate the myapp.db database file. You can use a fully
qualified or a relative path to locate the database file, but we did not
specify that when we ran the model helper earlier.
Regards
Guru

On Wed, Aug 1, 2012 at 7:17 PM, Guruprasad Kulkarni
guruprasa...@gmail.comwrote:

 Hi All,

 I am trying to learn Catalyst framework, by following the introduction
 modules available on CPAN. I am doing this on strawberry perl, on my PC.
 Also, I am using SQLite and have created myapp.db.

 While trying to create a model, I get the below error:

 \strawberry\perl\bin\MyApp\scriptmyapp_create.pl model DB DBIC::Schema
 MyApp::Schema create=static dbi:SQLite:myapp.db on_connect_do=PRAGMA
 foreign_keys = ON
  exists D:\strawberry\perl\bin\MyApp\lib\MyApp\Model
  exists D:\strawberry\perl\bin\MyApp\t
 Dumping manual schema for MyApp::Schema to directory
 D:\strawberry\perl\bin\MyApp\lib ...
 Schema dump completed.
 WARNING: No tables found, did you forget to specify db_schema?
  exists D:\strawberry\perl\bin\MyApp\lib\MyApp\Model\DB.pm

 ---

 The instruction says make sure your myapp.db database file is in the
 application's topmost directory.

 I tried placing myapp.db in all possible directories but it is not
 working. I understand this warning is coming from 
 Catalyst::Helper::Model::DBIC::Schema.pm,
 but I am not able to troubleshoot beyond that.

 Can someone tell me where am I suppose to keep the myapp.db file?

 Regards
 Guru



RE: Script to test connecting to Oracle DBs

2012-08-01 Thread Martin Gainty

#!/bin/sh
C:/grep/grep.exe -S (SERVICE_NAME = tnsnames.ora  service.ora
rm -r new.ora
echo #!/bin/sh  tns_ping.sh
C:/cygwin/bin/sed.exe 's/(SERVICE_NAME \=/tnsping.exe /' 
service.oratns_ping.sh
vi tns_ping.sh

If you find There is a way to pipe the 2 commands let me know but for now this 
little shell script works  

Martin
___ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und 
Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.


 Date: Sat, 28 Jul 2012 13:45:18 +1200
 Subject: Script to test connecting to Oracle DBs
 From: newbie01.p...@gmail.com
 To: beginners@perl.org; dbi-us...@perl.org
 
 Hi all,
 
 I am looking for a Perl script or something similar that I can use to test
 connection from a client PC to several databases on a server.
 
 Does anyone know of any such script lying around somewhere :(-
 
 Currently, am testing connection from a client PC to an Oracle DB using
 Oracle's sqlplus. All is well and good until I have to test connection to
 multiple databases on the server.
 
 So I am hoping to use a Perl script that I can use which will parse some
 sort of config file that contains hostname.tns_alias combination and then
 test connection to the Oracle DB and run a simple SQL like SELECT COUNT(1)
 from USER_TABLES, if I get an error, that means there is an issue
 connection to that database, otherwise all is good.
 
 At the moment, easiest I can think of using Perl's system command to run
 sqlplus. Or is it better to look at using DBI? Would be very much
 appreciated if someone can provide me a simple DBI script to start with if
 that is the best approach to use.
 
 Any suggestion/advice much appreciated. Thanks in advance.
  

Unexpected token error when providing a regular expression as input

2012-08-01 Thread moijes12
Hi

My program takes is supposed to take regular expression and a file
containing a list of words/lines as input and print all those lines
that match the regular expression. Below is the program


#!/usr/bin/perl

use strict;
use warnings;

sub grep_file {
my $pattern = shift;
my @file_names = @_;

for my $file_name (@file_names) {
open my ($file_handle), $file_name;
while(my $line = $file_handle) {
if ($line =~ m/$pattern/) {
print $line;
}
 }
 close $file_handle;
}
}

grep_file @ARGV;

When I execute this program from the command line by running ./
grep.pl  (.es.){3}  /usr/share/dict/words , I get the error
bash: syntax error near unexpected token `.es.'

But, if execute it as ./grep.pl  \(.es.\){3}  /usr/share/dict/
words , I get the expected result.

Please help me understand this.


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




Re: Script to test connecting to Oracle DBs

2012-08-01 Thread Leo Susanto
use strict;
use DBI;
use DBD::Oracle qw(:ora_types);

my $user   = '';
my $passwd = '';
my $tnsName = '';

$ENV{'ORACLE_HOME'} = 'C:\oracle\product\10.2.0\client_1';
my $dbh = DBI-connect(dbi:Oracle:$tnsName, $user, $passwd);
my $SQL = qq{ SELECT XXX};

my $sth0 = $dbh-prepare($SQL);
print SQL is prepared;\n;
$sth0-execute();
print SQL is executed;\n;
$sth0-finish();


On Fri, Jul 27, 2012 at 6:45 PM, newbie01 perl newbie01.p...@gmail.com wrote:
 Hi all,

 I am looking for a Perl script or something similar that I can use to test
 connection from a client PC to several databases on a server.

 Does anyone know of any such script lying around somewhere :(-

 Currently, am testing connection from a client PC to an Oracle DB using
 Oracle's sqlplus. All is well and good until I have to test connection to
 multiple databases on the server.

 So I am hoping to use a Perl script that I can use which will parse some
 sort of config file that contains hostname.tns_alias combination and then
 test connection to the Oracle DB and run a simple SQL like SELECT COUNT(1)
 from USER_TABLES, if I get an error, that means there is an issue
 connection to that database, otherwise all is good.

 At the moment, easiest I can think of using Perl's system command to run
 sqlplus. Or is it better to look at using DBI? Would be very much
 appreciated if someone can provide me a simple DBI script to start with if
 that is the best approach to use.

 Any suggestion/advice much appreciated. Thanks in advance.

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




Re: case statement in perl

2012-08-01 Thread Uri Guttman

On 08/01/2012 03:08 AM, Paul.G wrote:

The example below is just a test, I need to be able to insert multiple values 
into a command, those values can be either 1, 2 or upto 5.


you aren't getting the issue. the switch module was a major mistake and 
no one should be using it. you have to understand the downside to source 
filtering. no module can properly filter perl code as it is too subtle 
and complex to do so automatically. so source filters can seem to work 
now and if you do some changes to your code (not even near the switch 
stuff), it could break and you will have a hell of a time fixing it. the 
downside of that nasty hard to find bug is never worth it even if 
switch.pm appeals to you. modern perl's have a builtin given/when 
statement, you can use dispatch tables (especially for a fixed list of 
numbers or tokens) and other methods too. just avoid using the switch 
module. there is no way you can defend its use given the extremely nasty 
possible bugs it can introduce.


uri

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




Re: Unexpected token error when providing a regular expression as input

2012-08-01 Thread Robert Wohlfarth
On Tue, Jul 31, 2012 at 12:54 AM, moijes12 moije...@gmail.com wrote:

 When I execute this program from the command line by running ./
 grep.pl  (.es.){3}  /usr/share/dict/words , I get the error
 bash: syntax error near unexpected token `.es.'

 But, if execute it as ./grep.pl  \(.es.\){3}  /usr/share/dict/
 words , I get the expected result.


The parenthesis and curly braces mean something special to the command
line. It's not a Perl issue. It's a shell issue. In your case, the bash
shell. bash tries to interpret (.es.){3} before running Perl. Those
extra slashes you added tell bash to not interpret the parenthesis.

You could also get around the problem by quoting the regular expression on
the command line, like this:
# ./grep.pl '(.es.){3}' /usr/share/dict/words

Hope that helps.

-- 
Robert Wohlfarth


RE: Cannot connect to Oracle db; script will not run

2012-08-01 Thread John Scoles

have a look at 

http://search.cpan.org/~pythian/DBD-Oracle-1.46/lib/DBD/Oracle/Troubleshooting.pm

it should answer most of your questions


 From: james.war...@acxiom.com
 To: beginners@perl.org; dbi-us...@perl.org
 CC: newbie01.p...@gmail.com; rob.di...@gmx.com
 Subject: Cannot connect to Oracle db; script will not run
 Date: Wed, 1 Aug 2012 00:54:13 +

 --Beyond some training, I'm very much a newbie to Perl (and this list). So, 
 please indulge me with my first attempt at a posted question to you; please 
 see below (*with the full code Perl script toward the bottom of my email)...

 -I've been dealing with an issue in a Perl script that I'm writing, similar 
 to what was posted recently under 'Subject: Script to test connecting to 
 Oracle DBs' (and 'Subject: Re: Script to test connecting to Oracle DBs' by 
 Rob Dixon).
 Specifically, from my code:
 $ENV{TWO_TASK} = lady;

 $dbh = DBI-connect($connString, $ladyUser, $ladyPass,
 { AutoCommit=0, RaiseError=0, PrintError=0, ora_check_sql=0 }) or die 
 Could not connect to database:  . DBI-errstr ;

 ... ...but I still keep getting the same error message at command line in 
 unix:
 naszcard@gustavo: /ou8/naszcard/sox = perl -c Clapper_jjw_lookups.pl
 Clapper_jjw_lookups.pl syntax OK
 naszcard@gustavo: /ou8/naszcard/sox = perl Clapper_jjw_lookups.pl -t
 Could not connect to database: ORA-24327: need explicit attach before 
 authenticating a user (DBD ERROR: OCISessionBegin) at Clapper_jjw_lookups.pl 
 line 134.

 FYI: line 134 is above - { AutoCommit=0, RaiseError=0, PrintError=0, 
 ora_check_sql=0 }) or die Could not connect to database:  . DBI-errstr;

 -So, after double-checking that I was using the correct SID, and banging my 
 head against the wall ;-), I commented out the 'use DBI;' and the section 
 above, and just tried to go straight to it, command line, and do it this way 
 instead:
 my $tempCmd = sqlplus /nolog \@ . '/ou8/naszcard/sox/spool_lookup1b.sql ' . 
 $gustavoUser $gustavoPass | grep ORA;
 @oracleErrors = '$tempCmd';

 if(@oracleErrors ne 0) {
 $tempDate = `date`;
 chomp($tempDate);

 my $tempORAError = join(/n,@oracleErrors);
 system(echo \Clapper_jjw_lookups.pl has failed due to ORACLE ERROR(S): \n\n 
 It is $tempDate \n\n $tempORAError\ | mailx -s \Moja Table Lookups Errors\ 
 \ $global_email \ );
 exit;
 }

 ~That produces this not very informative, error generated email:
 -Original Message-
 From: service - PRC [mailto:naszc...@acxiom.com]
 Sent: Monday, July 30, 2012 10:51 PM
 To: Warren James - jawarr
 Subject: Moja Table Lookups Errors

 Clapper_jjw_lookups1.pl has failed due to ORACLE ERROR(S):

 It is Mon Jul 30 22:50:47 CDT 2012


 (@oracleErrors is an array which doesn't seem to be working...)

 *Here is the current, full text of my Perl code (passwords and other 
 sensitive, proprietary, etc., info. changed/hidden/masked to protect the 
 innocent ;-):

 #!/usr/bin/perl
 use strict;
 use warnings;
 #use DBI;
 #use DBD::Oracle qw(:ora_types);
 use Net::SFTP::Foreign;
 use diagnostics;

 
 ## SCRIPT: Clapper_jjw_lookups.pl
 ## AUTHOR: James J. Warren -- jawarr
 ## NOTES: ERRORs logged and emailed
 ##
 ## First Perl script for James
 ##
 

 # --
 #  Global Declaration --
 # --

 my $logPath = ; #-- Directory where all logs go (Does include last '/' )
 my $codePath = ; #-- Directory where all scripts are (Does include last 
 '/' )
 my $ftpDirectory = '/outbound/sftpp/xpj123/';

 my $global_email =  naszprod\@acxiom.com; # -- Global email (All emails 
 will be mailed to this address)


 # my $dbh = ; # -- Database handle that will be initiated later
 my $sth = ; # -- Statement handle that will be initiated later


 my @oracleErrors;

 my $fileConnectionString =  ;
 my $connString =  ;

 my $ladyUser =  ;
 my $ladyPass =  ;
 my $gustavoUser =  ;
 my $gustavoPass =  ;

 my @finishedSqlScripts;

 my $tempQuery = ;
 my $err_str = ;


 # --
 #  End of Global Declaration ---
 # --

 my $startupCounter = 0;

 our($opt_t);
 init();



 if ( $opt_t ){

 $fileConnectionString = `cat ///xxx/logon.sql`; # -- The string 
 passed into the code that decides what user and password to use when login 
 into Oracle
 $connString = 'dbi:Oracle:SID';
 $logPath = '/xxx//logs/reporting/dev/';
 $codePath = '/xxx//xxx/';

 $ladyUser = \@lady;
 $ladyPass = ;
 $gustavoUser = ;
 $gustavoPass = ;

 $global_email = James.Warren\@acxiom.com;


 }
 else{

 

Re: case statement in perl

2012-08-01 Thread Chris Nehren
On Wed, Aug 01, 2012 at 12:02:04 -0400 , Uri Guttman wrote:
 On 08/01/2012 03:08 AM, Paul.G wrote:
 The example below is just a test, I need to be able to insert
 multiple values into a command, those values can be either 1, 2 or
 upto 5.
 
 
 you aren't getting the issue. the switch module was a major mistake
 and no one should be using it. you have to understand the downside to
 source filtering. no module can properly filter perl code as it is
 too subtle and complex to do so automatically. so source filters can
 seem to work now and if you do some changes to your code (not even
 near the switch stuff), it could break and you will have a hell of a
 time fixing it. the downside of that nasty hard to find bug is never
 worth it even if switch.pm appeals to you. modern perl's have a
 builtin given/when statement, you can use dispatch tables (especially
 for a fixed list of numbers or tokens) and other methods too. just
 avoid using the switch module. there is no way you can defend its use
 given the extremely nasty possible bugs it can introduce.

+1

Though given/when is too smart for its own good, I agree with everything
here.  When uri and I agree on something, it's a strong indicator to pay
attention.

-- 
Chris Nehren   | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/


pgpWgsnYFeliD.pgp
Description: PGP signature


Re: case statement in perl

2012-08-01 Thread Hal Wigoda
so why don't they get rid of it?


On Wed, Aug 1, 2012 at 2:33 PM, Chris Nehren
c.nehren/beginn...@shadowcat.co.uk wrote:
 On Wed, Aug 01, 2012 at 12:02:04 -0400 , Uri Guttman wrote:
 On 08/01/2012 03:08 AM, Paul.G wrote:
 The example below is just a test, I need to be able to insert
 multiple values a command, those values can be either 1, 2 or
 upto 5.
 
 
 you aren't getting the issue. the switch module was a major mistake
 and no one should be using it. you have to understand the downside to
 source filtering. no module can properly filter perl code as it is
 too subtle and complex to do so automatically. so source filters can
 seem to work now and if you do some changes to your code (not even
 near the switch stuff), it could break and you will have a hell of a
 time fixing it. the downside of that nasty hard to find bug is never
 worth it even if switch.pm appeals to you. modern perl's have a
 builtin given/when statement, you can use dispatch tables (especially
 for a fixed list of numbers or tokens) and other methods too. just
 avoid using the switch module. there is no way you can defend its use
 given the extremely nasty possible bugs it can introduce.

 +1

 Though given/when is too smart for its own good, I agree with everything
 here.  When uri and I agree on something, it's a strong indicator to pay
 attention.

 --
 Chris Nehren   | Coder, Sysadmin, Masochist
 Shadowcat Systems Ltd. | http://shadowcat.co.uk/



-- 
-
Chicago
Hal Wigoda

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




Re: case statement in perl

2012-08-01 Thread Chris Nehren
On Wed, Aug 01, 2012 at 14:38:42 -0500 , Hal Wigoda wrote:
 so why don't they get rid of it?

I'm not sure which it you're referring to: Switch.pm or given/when.

For better or worse, Perl has a strong culture of backwards
compatibility. Perl is one of the few languages where you can use code
written 10-20 years ago on a new version with few difficulties. 

As for given/when, there are some threads on the perl5-porters mailing
list (where perl development is discussed) about changing given/when to
something that is less ambiguous and less clever.

As for Switch.pm, it has been removed from perl core.

-- 
Chris Nehren   | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/


pgprSLgwr7Uhb.pgp
Description: PGP signature


Re: updating variable in Parent using Parallel::ForkManager

2012-08-01 Thread Dr.Ruud

On 2012-07-30 15:47, punit jain wrote:


my $pm = new Parallel::ForkManager(10);

  my $count=0;

foreach my $user (@users) {

$pm-start($user) and next;

my $result;

  --- do some processing ---

$pm-finish(0, \$result);

}



$pm-wait_all_children;


However the final value of count is not correct. Is there some race
condition on same variable updation by the processes ?

pm - run_on_finish (

sub {

my $result = @;

if (defined($result)) {

my $count += $result;

}

}


I wonder why you expect a parent variable to be available to a child.
I am ignoring the bugs and style issues in your code, because they are 
not relevant to that point.


If you need to merge results from child-processes, it is best to let 
those child-processes write to unshared resources. Rows with an 
autoincrement-id in a database are often fine for that. A separate file 
per child-process on disk can also be fine.


After all children exited, the parent collects all those results and 
merges them.


Map: the parent divides the tasks over the children
Reduce: each child reduces its assigned input to a result
Merge: the parent combines all the results into the final result

--
Ruud


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




Re: case statement in perl

2012-08-01 Thread Paul.G
I have removed the switch funtion from the script.



 From: Uri Guttman u...@stemsystems.com
To: beginners@perl.org 
Sent: Thursday, 2 August 2012 2:02 AM
Subject: Re: case statement in perl
 
On 08/01/2012 03:08 AM, Paul.G wrote:
 The example below is just a test, I need to be able to insert multiple values 
 into a command, those values can be either 1, 2 or upto 5.
 
 
you aren't getting the issue. the switch module was a major mistake and no one 
should be using it. you have to understand the downside to source filtering. no 
module can properly filter perl code as it is too subtle and complex to do so 
automatically. so source filters can seem to work now and if you do some 
changes to your code (not even near the switch stuff), it could break and you 
will have a hell of a time fixing it. the downside of that nasty hard to find 
bug is never worth it even if switch.pm appeals to you. modern perl's have a 
builtin given/when statement, you can use dispatch tables (especially for a 
fixed list of numbers or tokens) and other methods too. just avoid using the 
switch module. there is no way you can defend its use given the extremely nasty 
possible bugs it can introduce.

uri

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