Re: Warning: Use of uninitialized value
"Uri Guttman" wrote: >> "BW" == Bob Williams writes: > > BW> Hi Rob, Many thanks. That does what I want :) Now I need to study > BW> your code to learn why. > > and you need to learn to bottom post. you wrote one line and quoted 80 > lines which have already been seen by others. google for bottom posting > and learn why it is better to read posts and quotes top to bottom like > we do with everything else. > > uri > Understood. I was replying in the same style as Rob used. My mistake. Bob -- openSUSE 11.2, Kernel 2.6.31.5-0.1-desktop, KDE 4.3.3 Intel Core2 Quad Q9400 2.66GHz, 4GB DDR RAM, nVidia GeForce 9200GS -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
newline problem
HI, I am new to perl and I have written a smal script to grab data from one file, and put them into another file. The problem is new lines, which are printing nice under a linux environment, but it is all messed up if I open it with notepad. I am running Perl 5 under cygwin. Heres the script: #!/usr/bin/perl open (READ, "opt.txt") || die "Can't find opt.txt\n"; $x=0; while ($info = ) { chomp $info; @data = split (/\t/, $info); push @cells, [...@data]; $x++; } close READ || die "Couldn't close opt.txt"; open (WRITE, ">rel.txt") || die "Can't find rel.txt\n"; $y=0; print WRITE "#DoNotEditThisLine: UndoCommandFile off_files model_n_m_z endfile=/tmp/6222\n\n"; foreach (@cells){ print WRITE "cr balla=1,blablabla=$cells[$y][0],foobar=$cells[$y][0]_ $cells[$y][1]\n"; print WRITE "bleh=10175,foounbar=$cells[$y][1]\n\n"; $y++; } close WRITE || die "Couldn't close rel.txt"; exit (0); Now if I cat the output in cygwin, the newlines are working. If I open it with notepad, one new line is working which is after print WRITE "bleh=10175,foounbar=$cells[$y][1]\n\n"; (please note not both of newlines are working). Any ideas? I need those in that specific format -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
AW: newline problem
Michom asked: > I am new to perl and I have written a smal script to grab data from > one file, and put them into another file. The problem is new lines, > which are printing nice under a linux environment, but it is all > messed up if I open it with notepad. I am running Perl 5 under cygwin. This is a "feature" of Notepad - it expects DOS-style "\r\n" as a line ending. HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: newline problem
Michom wrote: > open (WRITE, ">rel.txt") || die "Can't find rel.txt\n"; Try: open my $write_fh, '>:crlf', "rel.txt" or die "could not open rel.txt: $!\n"; You will have to change WRITE to $write_fh in the rest of the code. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: newline problem
Michom wrote: HI, Hello, I am new to perl and I have written a smal script to grab data from one file, and put them into another file. The problem is new lines, which are printing nice under a linux environment, but it is all messed up if I open it with notepad. I am running Perl 5 under cygwin. Heres the script: #!/usr/bin/perl The next two lines should be: use warnings; use strict; They will help you find mistakes in your code. open (READ, "opt.txt") || die "Can't find opt.txt\n"; $x=0; $x is not used anywhere so you don't really need it. while ($info = ) { chomp $info; @data = split (/\t/, $info); push @cells, [...@data]; $x++; } close READ || die "Couldn't close opt.txt"; If you are going to use the higher precedence || operator then don't forget to use parentheses. close( READ ) || die "Couldn't close opt.txt"; open (WRITE, ">rel.txt") || die "Can't find rel.txt\n"; $y=0; print WRITE "#DoNotEditThisLine: UndoCommandFile off_files model_n_m_z endfile=/tmp/6222\n\n"; foreach (@cells){ print WRITE "cr balla=1,blablabla=$cells[$y][0],foobar=$cells[$y][0]_ $cells[$y][1]\n"; print WRITE "bleh=10175,foounbar=$cells[$y][1]\n\n"; You are iterating over the @cells array so you don't really need $y you can just dereference the current element directly: print WRITE "cr balla=1,blablabla=$_->[0],foobar=$_->[0]_$_->[1]\n", "bleh=10175,foounbar=$_->[1]\n\n"; $y++; } close WRITE || die "Couldn't close rel.txt"; exit (0); Now if I cat the output in cygwin, the newlines are working. If I open it with notepad, one new line is working which is after print WRITE "bleh=10175,foounbar=$cells[$y][1]\n\n"; (please note not both of newlines are working). Any ideas? I need those in that specific format You don't need two different loops, you can operate on both files at the same time: #!/usr/bin/perl use warnings; use strict; my $read_file = 'opt.txt'; my $write_file = 'rel.txt'; open READ, '<', $read_file or die "Can't open '$read_file' $!"; open WRITE, '>', $write_file or die "Can't open '$write_file' $!"; print WRITE "#DoNotEditThisLine: UndoCommandFile off_files model_n_m_zendfile=/tmp/6222\n\n"; while ( my $info = ) { chomp $info; my @data = split /\t/, $info; print WRITE "cr balla=1,blablabla=$data[0],foobar=$data[0]_$data[1]\n", "bleh=10175,foounbar=$data[1]\n\n"; } close READ or die "Couldn't close '$read_file' $!"; close WRITE or die "Couldn't close '$write_file' $!"; exit 0; __END__ John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
prepare(SELECT ... FROM TABLE) error
when the table does not exist the prepare fails. How do ignore the error thrown by the prepare() and catch it later in the program? my $dbh = DBI->connect("dbi:ODBC:mysql" ,$login ,$passwd ,{ RaiseError => 0 } ); ... $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch $retCode = $sth->execute(); if ($dbh->err) { print "Table $table -- DOES NOT EXIST\n"; }
Re: prepare(SELECT ... FROM TABLE) error
On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito wrote: > when the table does not exist the prepare fails. How do ignore the error > thrown by the prepare() and catch it later in the program? > > > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } --output:-- executing other code here There was an error inside that eval block above: ***prepare error*** at 2perl.pl line 7.
Re: prepare(SELECT ... FROM TABLE) error
Is this the idea? I do not ever want to catch the error from the prepare statement itself -- I want my code to catch and throw the error. And I am using Perl 5.8 so I do not need the use 5.010; pragma thx use strict; use warnings; use 5.010; eval { my $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); }; if ($dbh->err) { print "Table $table -- DOES NOT EXIST\n"; } $retCode = $sth->execute(); --- On Mon, 1/2/10, 7 <7stud.7s...@gmail.com> wrote: From: 7 <7stud.7s...@gmail.com> Subject: Re: prepare(SELECT ... FROM TABLE) error To: "Beginners Perl" Date: Monday, 1 February, 2010, 14:05 On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito wrote: > when the table does not exist the prepare fails. How do ignore the error > thrown by the prepare() and catch it later in the program? > > > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } --- On Mon, 1/2/10, 7 <7stud.7s...@gmail.com> wrote: From: 7 <7stud.7s...@gmail.com> Subject: Re: prepare(SELECT ... FROM TABLE) error To: "Beginners Perl" Date: Monday, 1 February, 2010, 14:05 On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito wrote: > when the table does not exist the prepare fails. How do ignore the error > thrown by the prepare() and catch it later in the program? > > > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } --output:-- executing other code here There was an error inside that eval block above: ***prepare error*** at 2perl.pl line 7.
Re: prepare(SELECT ... FROM TABLE) error
Also, if prepare fails, I want to continue processing -- hence the need to capture the error in my code and not have DBI::DBD throw and exception then stop all processing ... --- On Mon, 1/2/10, Tony Esposito wrote: From: Tony Esposito Subject: Re: prepare(SELECT ... FROM TABLE) error To: "Beginners Perl" , "7" <7stud.7s...@gmail.com> Date: Monday, 1 February, 2010, 14:40 Is this the idea? I do not ever want to catch the error from the prepare statement itself -- I want my code to catch and throw the error. And I am using Perl 5.8 so I do not need the use 5.010; pragma thx use strict; use warnings; use 5.010; eval { my $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); }; if ($dbh->err) { print "Table $table -- DOES NOT EXIST\n"; } $retCode = $sth->execute(); --- On Mon, 1/2/10, 7 <7stud.7s...@gmail.com> wrote: From: 7 <7stud.7s...@gmail.com> Subject: Re: prepare(SELECT ... FROM TABLE) error To: "Beginners Perl" Date: Monday, 1 February, 2010, 14:05 On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito wrote: > when the table does not exist the prepare fails. How do ignore the error > thrown by the prepare() and catch it later in the program? > > > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } --- On Mon, 1/2/10, 7 <7stud.7s...@gmail.com> wrote: From: 7 <7stud.7s...@gmail.com> Subject: Re: prepare(SELECT ... FROM TABLE) error To: "Beginners Perl" Date: Monday, 1 February, 2010, 14:05 On Mon, Feb 1, 2010 at 12:11 PM, Tony Esposito wrote: > when the table does not exist the prepare fails. How do ignore the error > thrown by the prepare() and catch it later in the program? > > > my $dbh = DBI->connect("dbi:ODBC:mysql" > ,$login > ,$passwd > ,{ RaiseError => 0 } > ); > ... > $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable"); # don't catch > $retCode = $sth->execute(); > if ($dbh->err) { > print "Table $table -- DOES NOT EXIST\n"; > } > > See if this helps: use strict; use warnings; use 5.010; eval { die "***prepare error***"; }; say 'executing other code here'; if ($@) { say "There was an error inside that eval block above: $@"; } --output:-- executing other code here There was an error inside that eval block above: ***prepare error*** at 2perl.pl line 7.
Re: Warning: Use of uninitialized value
Bob Williams wrote: "Uri Guttman" wrote: "BW" == Bob Williams writes: BW> Hi Rob, Many thanks. That does what I want :) Now I need to study BW> your code to learn why. and you need to learn to bottom post. you wrote one line and quoted 80 lines which have already been seen by others. google for bottom posting and learn why it is better to read posts and quotes top to bottom like we do with everything else. uri Understood. I was replying in the same style as Rob used. My mistake. My apologies to all. I have been away from this list for over a year, and know full well that bottom-posting is the preferred style. Shame on me! Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Different approaches for Daemon and fork/thread
On Mon, 01 Feb 2010 01:26:23 -0600, Alvaro Mantilla Gimenez wrote: > I need to create a perl daemon that split in two process (each has > different data input) and then they split in as many child > (fork)/threads as need it. > > Daemon >| >- >| | > Process 1 Process 2 >| | > ----- > | | | | | | > child1 child2 childn child1 child2 childn > > I would like to know which is the best approach for create the daemon > (Proc::Simple, Proc::Daemon, etc...) and some recommendation about the > fork/thread question (which one: forks or threads? why? some example?). I've been using Working::Daemon lately; it does the proper double fork/ setsid method of daemonization. As to processes vs threads, that really depends on how many children, how long they will live, what sort of communication they need to do with parents or each other. Describe your application in more detail, please. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/