Re: Invalid conversion in sprintf %\
thanks Jim for taking the time to look at my code - i figured out what was going on its seems that using the qw() structure to define my arrays caused the \ signs to be passed on - once i rewrote the array definitions using , quoting like this everything worked as i wanted: my @phraseA = (%1\$s16- , %2\$s16- , %3\$s16- ); i also had to convert the array to a scalar for the InsertPitches subroutine to work correctly with the sprintf. thanks again to John and Jim for your hints, rob this now works for me my @phraseA = (%1\$s16- , %2\$s16- , %3\$s16- ); my @phraseB = (%4\$s16 , %5\$s16 , %6\$s16- ); my @phraseC = (%7\$s16 , %8\$s16 , %9\$s16 ); my @phraseD = (%10\$s16- , %11\$s16 , %12\$s16); my @phraseE = (%13\$s16 , %14\$s16 , %15\$s16-); my @phrasegroup = ([ @phraseA ], [ @phraseB ], [ @phraseC ], [ @phraseD ], [ @phraseE ]); my @phraseperm = map {...@$_} permute(@phrasegroup); #flatten permutation array my @App = map {...@$_, } @phraseperm; my $App = join( ,@App); Jim Gibson said : On 2/18/09 Wed Feb 18, 2009 10:20 AM, Rob Canning r...@goto10.org scribbled: John W. Krahn said : Rob Canning wrote: hi i have a sprintf which uses a scalar as its format: my $Bformat = %1\$s16- %2\$s16 %3\$s16 %4\$s16 %5\$s16 %6\$s16- %7\$s16 %8\$s16 [...] any ideas what i am doing wrong? Strings like '%1\$s16-' are not valid sprintf/printf formats. What does your data look like and what do you expect it to look like after using sprintf? hi, i have put the code here http://pastebin.com/m5d4debbb you will see a my $formatA that works fine and a my @App gives the error There is no $formatA in your program. You define $Aformat in lines 62-125, but do not use it anywhere in your program. Compare lines 226 and 240: 226 InsertPitches( 15, @App, @Aflatperm ), 240 InsertPitches(15, $Bformat, @Bflatperm ), and the first few lines of InsertPitches: sub InsertPitches { my ($num, $form, @notes) = @_; ... } When InsertPitches is called from line 226, the first element of @App will be copied to $form, and the rest of @App will be copied to @notes. The contents of @Aflatperm will be concatenated to the end of @notes. Is this what you want? Did you mean to call InsertPitches with $Aformat instead of @App in line 226? HTH. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- r...@goto10.org rob.goto10.org -- signature.asc Description: Digital signature
calling a program from a perl script and redirecting to output to a file
Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas
Re: Invalid conversion in sprintf %\
John W. Krahn wrote: Strings like '%1\$s16-' are not valid sprintf/printf formats. What does your data look like and what do you expect it to look like after using sprintf? From perldoc -f sprintf: format parameter index An explicit format parameter index, such as 2$. By default sprintf will format the next unused argument in the list, but this allows you to take the arguments out of order, e.g.: printf '%2$d %1$d', 12, 34; # prints 34 12 printf '%3$d %d %1$d', 1, 2, 3; # prints 3 1 1 Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Invalid conversion in sprintf %\
Rob Dixon wrote: John W. Krahn wrote: Strings like '%1\$s16-' are not valid sprintf/printf formats. What does your data look like and what do you expect it to look like after using sprintf? From perldoc -f sprintf: format parameter index An explicit format parameter index, such as 2$. By default sprintf will format the next unused argument in the list, but this allows you to take the arguments out of order, e.g.: printf '%2$d %1$d', 12, 34; # prints 34 12 printf '%3$d %d %1$d', 1, 2, 3; # prints 3 1 1 Thank you for reading the documentation to me but '%1\$s' is not the same as '%1$s'. $ perl -le' my $format = q[%s : %s : %1\$s] . \n; my @data = qw[ one two three four ]; printf $format, @data; ' one : two : %1\$s $ perl -le' my $format = q[%s : %s : %1$s] . \n; my @data = qw[ one two three four ]; printf $format, @data; ' one : two : one John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: calling a program from a perl script and redirecting to output to a file
Thank you David. A typical output file comprises ~200 lines. Most of those files are useless and thus the arrays that contain theirs lines will occupy extra memory. I am running many such scripts concurrently which invoke similar processes several times so I'm wondering if there is a way to erase those arrays from memory upon completion of the execution. thanks in advance, Thomas 2009/2/19 Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com -Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 08:27 To: beginners@perl.org Subject: calling a program from a perl script and redirecting to output to a file Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here Unless the output is trully large, I use somehting like: my @myout = `$apbs input.in`; Then I parse what is in the array. I have number of processes that I do this way. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas
Re: calling a program from a perl script and redirecting to output to a file
This seems to work for me: $apbs = '/bin/ls'; $output = 'output.txt'; `$apbs $output` Does this do what you need? On Feb 19, 2009, at 10:11 AM, Thomas Evangelidis wrote: Thank you David. A typical output file comprises ~200 lines. Most of those files are useless and thus the arrays that contain theirs lines will occupy extra memory. I am running many such scripts concurrently which invoke similar processes several times so I'm wondering if there is a way to erase those arrays from memory upon completion of the execution. thanks in advance, Thomas 2009/2/19 Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com -Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 08:27 To: beginners@perl.org Subject: calling a program from a perl script and redirecting to output to a file Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here Unless the output is trully large, I use somehting like: my @myout = `$apbs input.in`; Then I parse what is in the array. I have number of processes that I do this way. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas Sincerely, James Moser ja...@endpoint.com There are 10 kinds of people in the world. Those who understand binary, and those who do not. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
owen, How do I use the List::Compare module. I read online about a array::compare module is the same thing? marc On Feb 18, 8:33 pm, chas.ow...@gmail.com (Chas. Owens) wrote: On Wed, Feb 18, 2009 at 19:59, Gunnar Hjalmarsson nore...@gunnar.cc wrote: Chas. Owens wrote: snip This is not the best way to go about solving this problem (use diff or a module like Text::Diff*), If we are going to suggest a module, List::Compare would be more to the point IMO. snip No, the lines should not make it out of the files into arrays in the first case. Reading whole files into arrays is one of the reasons this code is bad. snip It is important to note that this algorithm only works if you care about unique lines. If you need to know that file1 has 5 lines of foo and file2 has 4 lines of foo, this code will not tell you that. Since the files contain file names from directory listings, that cannot be applicable to the problem at hand. snip Yes, but it is an important thing to note lest you try to use it for something else later. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: calling a program from a perl script and redirecting to output to a file
-Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 09:12 To: Wagner, David --- Senior Programmer Analyst --- CFS Cc: beginners@perl.org Subject: Re: calling a program from a perl script and redirecting to output to a file Thank you David. A typical output file comprises ~200 lines. Most of those files are useless and thus the arrays that contain theirs lines will occupy extra memory. I am running many such scripts concurrently which invoke similar processes several times so I'm wondering if there is a way to erase those arrays from memory upon completion of the execution. You can do undef @myout; but it really depends upon what system you are running under and how they handle the release of memory. This should cutdown, but you could also use brackets like: { my @myout = `program file`; # now process what is in @myout and either save to another arry which you want to write eventually or # write to a file with the necessary data that meets your criteria } after the }, the my @myout would be released thanks in advance, Thomas 2009/2/19 Wagner, David --- Senior Programmer Analyst --- CFS david.wag...@fedex.com -Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 08:27 To: beginners@perl.org Subject: calling a program from a perl script and redirecting to output to a file Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here Unless the output is trully large, I use somehting like: my @myout = `$apbs input.in`; Then I parse what is in the array. I have number of processes that I do this way. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
On Thu, Feb 19, 2009 at 10:20, mritorto mrito...@gmail.com wrote: owen, How do you use the List::Compare module is the same as array::compare? snip List::Compare can be found in CPAN*. Here is you program rewritten to use it (this is not what I would do): #!/usr/bin/perl use strict; use warnings; use List::Compare; #compares directories on 2 servers open my $atlas, , atlasdirectorylisting.txt or die could not open atlasdirectorylisting.txt: $!; open my $isis, , ISISdirectorylisting.txt or die could not open ISISdirectorylisting.txt: $!; my @atlas = $atlas; my @isis = $isis; my $comparison = List::Compare-new(\...@atlas, \...@isis); print $comparison-get_symmetric_difference; * http://search.cpan.org/dist/List-Compare/lib/List/Compare.pm -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
VBTK:DBI question
Could you give me a hints how to use VBTK:DBI module for SQL server 2008. I am trying to monitor DB in SQL server 2008. Does any one has email contact for Brent Henry, VBTK module creator. I tried vbtool...@yahoo.com, have not gotten an Reponses Thank you. Kamrul Hassan -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: calling a program from a perl script and redirecting to output to a file
-Original Message- From: Thomas Evangelidis [mailto:teva...@gmail.com] Sent: Thursday, February 19, 2009 08:27 To: beginners@perl.org Subject: calling a program from a perl script and redirecting to output to a file Dear Perl programmers, I want to run a program from a perl script and redirect the its output to a file. The programs is called apbs and takes 1 argument, so in unix shell I 'm simply typing the following: $apbs input.in $ output.txt # '' doesn't work here Unless the output is trully large, I use somehting like: my @myout = `$apbs input.in`; Then I parse what is in the array. I have number of processes that I do this way. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us When using the system function I get an error. Does anyone know how to achieve that in perl. thanks in advance, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Invalid conversion in sprintf %\
On 2/19/09 Thu Feb 19, 2009 7:56 AM, John W. Krahn jwkr...@shaw.ca scribbled: Thank you for reading the documentation to me but '%1\$s' is not the same as '%1$s'. True. However, I think the point should be made that %1\$s is in fact the same as '%1$s' Rob is using double-quotes in his program. I would suggest that Rob use single-quotes and avoid having to escape the dollar-signs. The q() and qq() forms are also useful at times. -- Jim Gibson -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
Chas. Owens wrote: On Thu, Feb 19, 2009 at 10:20, mritorto mrito...@gmail.com wrote: owen, How do you use the List::Compare module is the same as array::compare? snip List::Compare can be found in CPAN*. Here is you program rewritten to use it (this is not what I would do): We know. ;-) snip my @atlas = $atlas; my @isis = $isis; my $comparison = List::Compare-new(\...@atlas, \...@isis); print $comparison-get_symmetric_difference; It's worth noting that if the so called symmetric difference is sufficient, the same result is achieved if you use the approach suggested in perldoc -q difference.+arrays Actually, you only need one single hash: my %count; $count{$_}++ while $atlas; $count{$_}++ while $isis; print sort map { $count{$_} == 1 ? $_ : () } keys %count; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
On Thu, Feb 19, 2009 at 15:19, marc ritorto mrito...@gmail.com wrote: will this module work with activestate perl ? snip With ActivePerl you need to look at the build status page* to see if a given module works. It looks like it works with Perl 5.8, but not Perl 5.6. You should be able to install it with the PPM**. * http://ppm.activestate.com/BuildStatus/5.6.html for Perl 5.6 and http://ppm.activestate.com/BuildStatus/5.8.html for Perl 5.8 ** http://docs.activestate.com/activeperl/5.8/faq/ActivePerl-faq2.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Installing threads module from CPAN
Thanks zentara, I think use blib is to test modules before installing... In my case even make test was failing with the can't load threads.so error even though threads.so was existing at the path indicated in the error. Finally I could resolve the error by making following changes to the Makefile. The problem was, my OS is 64bit, perl installed at default system path is 32 bit but threads module (threads.so) I was compiling and installing locally was being linked to 64bit libraries. So I had to compile and link it in a 32bit mode. Added -m32 option on gcc for both compiler and linker and added -L/lib where my 32bit libraries (e.g. libpthreds.so) are present. Changed -march=opteron. Here is Makfile diff for threads-1.71 module [threads-1.71]$ diff Makefile Makefile.old 39c39 LDDLFLAGS = -m32 -shared -L/lib -L/usr/local/lib --- LDDLFLAGS = -shared -L/usr/local/lib 267c267 OPTIMIZE = -m32 -O2 -march=opteron -fprefetch-loop-arrays -funroll-loops -pipe --- OPTIMIZE = -O2 -march=pentium3 -fprefetch-loop-arrays -funroll-loops -pipe Thanks --Suhas use blib --Regards Suhas [Search HADOOP/PIG Information] http://produce.yahoo.com:8080/gogate/griduserportal.php -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Installing threads module from CPAN
Just to update further, I found 64bit perl installed on my machine and when I used it, I did not have to do any Makefile changes to compile and install the threads-1.71 module... it all worked fine. On 2/19/09 3:06 PM, Suhas Gogate gog...@yahoo-inc.com wrote: Thanks zentara, I think use blib is to test modules before installing... In my case even make test was failing with the can't load threads.so error even though threads.so was existing at the path indicated in the error. Finally I could resolve the error by making following changes to the Makefile. The problem was, my OS is 64bit, perl installed at default system path is 32 bit but threads module (threads.so) I was compiling and installing locally was being linked to 64bit libraries. So I had to compile and link it in a 32bit mode. Added -m32 option on gcc for both compiler and linker and added -L/lib where my 32bit libraries (e.g. libpthreds.so) are present. Changed -march=opteron. Here is Makfile diff for threads-1.71 module [threads-1.71]$ diff Makefile Makefile.old 39c39 LDDLFLAGS = -m32 -shared -L/lib -L/usr/local/lib --- LDDLFLAGS = -shared -L/usr/local/lib 267c267 OPTIMIZE = -m32 -O2 -march=opteron -fprefetch-loop-arrays -funroll-loops -pipe --- OPTIMIZE = -O2 -march=pentium3 -fprefetch-loop-arrays -funroll-loops -pipe Thanks --Suhas use blib --Regards Suhas [Search HADOOP/PIG Information] http://produce.yahoo.com:8080/gogate/griduserportal.php --Regards Suhas [Search HADOOP/PIG Information] http://produce.yahoo.com:8080/gogate/griduserportal.php -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
guys more questions isn't built in. I am using active state perl can u recommend any good perl books the ones I have aren't make for beginers like perl cookbook or perl in a nutshell remember I have no programming background I am an exchange admin will this compare module work with windows active state perl? marc On Feb 18, 8:33 pm, chas.ow...@gmail.com (Chas. Owens) wrote: On Wed, Feb 18, 2009 at 19:59, Gunnar Hjalmarsson nore...@gunnar.cc wrote: Chas. Owens wrote: snip This is not the best way to go about solving this problem (use diff or a module like Text::Diff*), If we are going to suggest a module, List::Compare would be more to the point IMO. snip No, the lines should not make it out of the files into arrays in the first case. Reading whole files into arrays is one of the reasons this code is bad. snip It is important to note that this algorithm only works if you care about unique lines. If you need to know that file1 has 5 lines of foo and file2 has 4 lines of foo, this code will not tell you that. Since the files contain file names from directory listings, that cannot be applicable to the problem at hand. snip Yes, but it is an important thing to note lest you try to use it for something else later. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
breaking-apart and printing an input file
I have a single input file with entries as follows: --snip-- USER1 [20090101] note bla bla bla bla bla bla USER2 [20090104] note bla bla bla bla bla bla --snip-- What I'm trying to do is create a single-argument script which displays all entries for a given user. So calling it as 'filter.pl user1' will print all entries for USER1. Here is what I've got so far: --- my $user = shift; # slurp file my $file = do { open my $fh, 'inputfile.txt' or die $!; local $/; $fh; }; if ( $file =~ /(^$user.*?)^$/smg ) { print $1; } --- Here's my thinking behind the non-functional regex. It matches a set of lines starting with a line which begins with $user, followed by all non-empty lines, and terminated with an empty line (^$). Running my script produces zero output. My questions are: 1. Is there a simpler way to approach/accomplish this? 2. If not, what's wrong with my regex? Thanks in advance for any help. /P -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: breaking-apart and printing an input file
pa...@compugenic.com wrote: I have a single input file with entries as follows: --snip-- USER1 [20090101] note bla bla bla bla bla bla USER2 [20090104] note bla bla bla bla bla bla --snip-- What I'm trying to do is create a single-argument script which displays all entries for a given user. So calling it as 'filter.pl user1' will print all entries for USER1. Here is what I've got so far: --- my $user = shift; # slurp file my $file = do { open my $fh, 'inputfile.txt' or die $!; local $/; $fh; }; if ( $file =~ /(^$user.*?)^$/smg ) { print $1; } --- Here's my thinking behind the non-functional regex. It matches a set of lines starting with a line which begins with $user, followed by all non-empty lines, and terminated with an empty line (^$). Running my script produces zero output. My questions are: 1. Is there a simpler way to approach/accomplish this? 2. If not, what's wrong with my regex? Thanks in advance for any help. I don't kno what results you're getting, but this works fine for me. The only change I would make is to change the 'if' to a 'while', otherwise only the first matching record will be found. There may be an issue with reading the entire file if it is at all large, in which case I recommend reading in 'paragraph' mode by setting the input record separator to the null string local $/ = ; after which each read from the file will return a single complete multi-line record, terminated by a blank line. HTH, Rob use strict; use warnings; my $user = 'USER1'; # slurp file my $file = do { local $/; DATA; }; if ( $file =~ /(^$user.*?)^$/smg ) { print $1; } __DATA__ USER1 [20090101] note bla bla bla bla bla bla USER2 [20090104] note bla bla bla bla bla bla -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl fork() system call
Hi Chuck: I don't think exec will do the right thing. According to perldoc.perl.org, exec will stop the current process to execute another one while system will do a fork() first, so system will be your right choice I think. This is a short example I did recently: ** main program starts here. if you system(another program in the foregroud) { you will have to wait until the program finishes. } elsif you system(another program in the backgroud) { you will get your main program run ahead without having to wait its returen } Hope this will give you some clue. On Thu, Feb 19, 2009 at 8:02 AM, Chas. Owens chas.ow...@gmail.com wrote: On Wed, Feb 18, 2009 at 12:14, Chuck c...@unity.ncsu.edu wrote: Hello, We have a GUI where, if a button is clicked, Putty (the remote access program) is launched using System(C:\\Progra~1\\Putty\\putty.exe); is launched. However, when this is executed, the original GUI freezes, and we cannot use it unless we close Putty. We tried using the fork() command like this: my $pid = fork() if ( $pid == 0 ) { System(C:\\Progra~1\\Putty\\putty.exe); exit 0; } Now, if we run it, we can use the original GUI while Putty is running, but when we close Putty, we get an error message along the lines of, The Perl Command Line Interpreter has stopped working and the GUI kills itself. Does anyone know what the problem might be, or how we can launch Putty without freezing the GUI or causing it to kill itself after closing Putty? Thanks a lot. Try replacing the system with exec*. The exec function will replace the currently running process (Perl) with the new one (Putty). * http://perldoc.perl.org/functions/exec.html
Re: breaking-apart and printing an input file
On Thu, Feb 19, 2009 at 22:42, pa...@compugenic.com wrote: I have a single input file with entries as follows: --snip-- USER1 [20090101] note bla bla bla bla bla bla USER2 [20090104] note bla bla bla bla bla bla --snip-- What I'm trying to do is create a single-argument script which displays all entries for a given user. So calling it as 'filter.pl user1' will print all entries for USER1. snip Your data is perfect for the paragraph mode* of readline: #!/usr/bin/perl use strict; use warnings; my $user = shift; my $regex = qr/\A$user/; local $/ = ''; while (my $record = DATA) { chomp $record; if ($record =~ /$regex/) { print $record\n; last; } } __DATA__ USER1 [20090101] note bla bla bla USER2 loves this user USER2 [20090104] note bla bla bla bla bla bla USER3 [20090107] note bla bla bla bla bla bla * http://perldoc.perl.org/perlvar.html#$/ -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Test::HTTPStatus
Dear All, I am testing the weblinks for connectivity using Test::HTTPStatus module. I could able to test 187 and in those 165 links are success and 22 links are failed. When I test manually by entering the weblink in the browser out of 22, 5 weblinks are working fine. I am not sure why this module is showing those 5 links as failure. Can somebody help in get it resolved. My code is as follows: unlink(linktest.log); $xfile = $ARGV[0]; open(OUT, linktest.log); use XML::XPath; use XML::XPath::XMLParser; use Test::HTTPStatus tests=1; $xp = XML::XPath-new(filename = $xfile); $nodeset1 = $xp-find('//xref/@href'); foreach $node1 ($nodeset1-get_nodelist) { $aid=XML::XPath::XMLParser::as_string($node1); $aid=~s!href=!!g; $aid=~s!!!g; $aid=~s! !!g; $a=http_ok( $aid, HTTP_OK ); sleep 10; print OUT $aid\n if ($a == 0); } close(OUT); Regards, Ganesh -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
DBI Placeholder Issue
Hi All, I want to query the database log of SQL Server using DBI:ODBC and I encounter a problem. I want to use select * from ::fn_dblog(null,null) to query the log, but DBI takes :: as placeholder and fails. As follows, use DBI; my $dbh = DBI-connect(dbi:ODBC:MyDSN) or die Can't connect: $DBI::errstr\n; my $query = qq{ select * from ::fn_dblog(null,null) }; my $sth = $dbh-prepare($query) ; $sth-execute( ) or die $dbh-errstr; I run the script and the output is: Can't rebind placeholder fn_dblog at F:\zDataBase\db.pl line 29. How to fix it ? Best regards! Thomas Yan
Re: Perl fork() system call
thanks for the help, everyone. We found a way that works...we used Win32::Process::Create. On Feb 18, 7:02 pm, chas.ow...@gmail.com (Chas. Owens) wrote: On Wed, Feb 18, 2009 at 12:14, Chuck c...@unity.ncsu.edu wrote: Hello, We have a GUI where, if a button is clicked, Putty (the remote access program) is launched using System(C:\\Progra~1\\Putty\\putty.exe); is launched. However, when this is executed, the original GUI freezes, and we cannot use it unless we close Putty. We tried using the fork() command like this: my $pid = fork() if ( $pid == 0 ) { System(C:\\Progra~1\\Putty\\putty.exe); exit 0; } Now, if we run it, we can use the original GUI while Putty is running, but when we close Putty, we get an error message along the lines of, The Perl Command Line Interpreter has stopped working and the GUI kills itself. Does anyone know what the problem might be, or how we can launch Putty without freezing the GUI or causing it to kill itself after closing Putty? Thanks a lot. Try replacing the system with exec*. The exec function will replace the currently running process (Perl) with the new one (Putty). *http://perldoc.perl.org/functions/exec.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl fork() system call
Hi Chuck, Chuck wrote: We have a GUI where, if a button is clicked, Putty (the remote access program) is launched using System(C:\\Progra~1\\Putty\\putty.exe); is launched. However, when this is executed, the original GUI freezes, and we cannot use it unless we close Putty. We tried using the fork() command like this: my $pid = fork() if ( $pid == 0 ) { System(C:\\Progra~1\\Putty\\putty.exe); exit 0; } I don't really know much about GUIs with Perl, but I did look into this for a web server running modperl and you might find something helpful there. Here are two links I bookmarked: http://www.perl.com/pub/a/2003/01/07/mod_perl.html http://modperlbook.org/html/10-2-3-Detaching-the-Forked-Process.html What I do is: - use POSIX 'setsid'; $SIG{CHLD} = 'IGNORE'; my $kid = fork; if (!defined $kid) { ## could not fork } elsif ($kid == 0) { $SIG{CHLD} = 'DEFAULT'; setsid () or die Can't start a new session: $!; ## run system and then exit } ## Parent process continues from here - The above is abbreviated from what I have, but I think you can look up setsid, $SIG{CHLD}, etc. to see if it applies to your GUI system. Good luck! Ray -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/