Re: foreach and next

2012-04-08 Thread Binish A.R
Enclose DBI operation inside eval - #!/usr/bin/perl use strict; use warnings; use DBI; use DBD::mysql; foreach $db (hostdb($project)) { eval {         my $server = $db;         my $dbname = information_schema;         my $port = 3306;         my $dsn =

Re: foreach and next

2012-04-08 Thread Shlomi Fish
Hi Vyacheslav, On Sun, 08 Apr 2012 06:12:53 + Vyacheslav agapov.sl...@gmail.com wrote: Hello all. My english bad and i have a problem. I am connected to databases in a cycle foreach and the script die, if one of database is not available. #!/usr/bin/perl use strict; use

regex

2012-04-08 Thread Somu
Hello everyone... Thanks for the previous replies. I'm really improving! A new problem.. Check if the word begins with un or in and has exactly 5 letters. $word =~ '^(un|in).{3}$' Check if the word begins with un or in or non and has more than 5 letters. $word =~ '^(un|in).{3}.+$' What do i

Re: foreach and next

2012-04-08 Thread Vyacheslav
Thanks all. using eval helped me. 08.04.2012 09:43, Shlomi Fish пишет: Hi Vyacheslav, On Sun, 08 Apr 2012 06:12:53 + Vyacheslavagapov.sl...@gmail.com wrote: Hello all. My english bad and i have a problem. I am connected to databases in a cycle foreach and the script die, if one of

Re: regex

2012-04-08 Thread Binish A.R
Why don't you check the length of the string as well .. ie if (length($word) ==  5 $word =~ /^(un|in|non).+$/) {  ## Do something }   From: Somu som@gmail.com To: beginners@perl.org Sent: Sunday, April 8, 2012 4:30 PM Subject: regex Hello everyone...

Re: regex

2012-04-08 Thread Binish A.R
if you are  looking for the regex only solution, then you may try this $word =~ /^((un|in).{3}|non.{2})$/   From: Binish A.R arbin...@yahoo.com To: som@gmail.com som@gmail.com; beginners@perl.org beginners@perl.org Sent: Sunday, April 8, 2012 6:19 PM

Re: regex

2012-04-08 Thread Somu
yes... Maybe have to work with this only... Thanks $word =~ /^((un|in).{3}|non.{2})$/

Re: foreach and next

2012-04-08 Thread Shlomi Fish
Hi Vyacheslav, On Sun, 08 Apr 2012 15:10:06 + Vyacheslav agapov.sl...@gmail.com wrote: Thanks all. using eval helped me. The problem with eval in Perl 5 is that it catches any and all thrown exceptions . I.e: by default, it doesn't do Object-Oriented exceptions like Java, Ruby, Python

Re: regex

2012-04-08 Thread Rob Dixon
On 08/04/2012 12:00, Somu wrote: Hello everyone... Thanks for the previous replies. I'm really improving! A new problem.. Check if the word begins with un or in and has exactly 5 letters. $word =~ '^(un|in).{3}$' Check if the word begins with un or in or non and has more than 5 letters.

Re: foreach and next

2012-04-08 Thread Dr.Ruud
On 2012-04-08 17:10, Vyacheslav wrote: using eval helped me. You should not use exceptions for normal code flow. Read the DBI docs (perldoc DBI). If a failed connection must be an exception, set RaiseError to true. But if it isn't an exception, leave it false, and test $dbh-err (or the

Re: foreach and next

2012-04-08 Thread Vyacheslav
I enabled RaiserError, then script die. ... my %attr = ( PrintError = 0, RaiseError = 1 ); my $dbh = DBI-connect($dsn, $user, $pass, \%attr); # or die Can't connect to the DB: $DBI::errstr\n; my $query = SHOW DATABASES; my $sth = $dbh-prepare($query) or die Can't prepare SQL statement:

Re: foreach and next

2012-04-08 Thread Jim Gibson
At 12:50 AM + 4/9/12, Vyacheslav wrote: I enabled RaiserError, then script die. ... my %attr = ( PrintError = 0, RaiseError = 1 ); Use: RaiseError = 0 instead so that your script will not raise an exception and die. Then check $dbh-err. -- To unsubscribe, e-mail:

Merge two files with similar column entries

2012-04-08 Thread S Pratap Singh
Hi , I have few files which contains user name and data transfer rate in MBs and this data is collected for year and for each month report is saved in 12 different files I have to merge all the files to prepare the final report Files are as below Filename1 : January #User Name #Data

Re: regex

2012-04-08 Thread John W. Krahn
Somu wrote: Hello everyone... Hello, Thanks for the previous replies. I'm really improving! A new problem.. Check if the word begins with un or in and has exactly 5 letters. $word =~ '^(un|in).{3}$' You should use the matching operator on the right hand side of the binding operator

Re: Merge two files with similar column entries

2012-04-08 Thread Jim Gibson
At 3:33 AM +0530 4/9/12, S Pratap Singh wrote: Hi , I have few files which contains user name and data transfer rate in MBs and this data is collected for year and for each month report is saved in 12 different files I have to merge all the files to prepare the final report Files are as below

Help parsing tab delimited files

2012-04-08 Thread Tiago Hori
Hi Guys, I know there are modules for parsing tab delimited files, but I am trying to develop a script as a learning exercise to learn the better, so any help would be appreciated. Let's say I have two columns and two rows: Joe \t Doe Jane \t Doe So here is what I got: #!usr/bin/perl use

Re: Help parsing tab delimited files

2012-04-08 Thread Binish A.R
replace     @array = split (/\t/, $_);  with               @array = split;   From: Tiago Hori tiago.h...@gmail.com To: beginners@perl.org Sent: Monday, April 9, 2012 6:42 AM Subject: Help parsing tab delimited files Hi Guys, I know there are modules for

Re: Help parsing tab delimited files

2012-04-08 Thread John W. Krahn
Tiago Hori wrote: Hi Guys, Hello, I know there are modules for parsing tab delimited files, but I am trying to develop a script as a learning exercise to learn the better, so any help would be appreciated. Let's say I have two columns and two rows: Joe \t Doe Jane \t Doe So here is what I

Re: Help parsing tab delimited files

2012-04-08 Thread Michael Rasmussen
On Sun, Apr 08, 2012 at 08:44:53PM -0700, Binish A.R wrote: replace     @array = split (/\t/, $_);  with               @array = split; I advise to not do that, because when you add more data - like Joe Bob \t Briggs  @array will have three elements. My output from your sample data and

Re: Help parsing tab delimited files

2012-04-08 Thread Jim Gibson
At 10:42 PM -0230 4/8/12, Tiago Hori wrote: Hi Guys, I know there are modules for parsing tab delimited files, but I am trying to develop a script as a learning exercise to learn the better, so any help would be appreciated. Let's say I have two columns and two rows: Joe \t Doe Jane \t Doe