passing arguments to perl function with - in the string
Hi Sorry for the silly question, but thought someone might help here.(tried googling but this may too silly a beginners question for anyone to have answered previously) I need to pass argument to a function like this -chan_range => "$chs-$che" Normally when this used which works -chan_range => "1-24" However, when I try to put variable values instead of a scalar string, I get compilation errors (the errors are in different part of the code which is completely clueless) What is the correct way to pass the values with variable names and - in the string? I tried using \" and without the " also, but nothing helped. Thanks in anticipation, Regards, Satya
RE: passing arguments to perl function with - in the string
Hi Brandon, Igor, Shawn Thank you very much for your replies. Appreciate your time and help. I later realized that the error was creeping not due to the - or any other character in the string, but a ' character that was introduced at the end of the line by mistake. The horror was that the perl compiler pointed at a code some 1000s of lines below this line for the error which was completely confusing. Now I learnt how small mistakes can take hours to resolve and will be careful in future. Thanks, Regards, Satya P.S : unfortunately, I cant provide more details due to the IP restrictions, sorry about that, hope you understand, otherwise would have posted the code in the first go. -Original Message- From: Brandon McCaig [mailto:bamcc...@gmail.com] Sent: 29 November 2011 15:15 To: Nemana, Satya Cc: beginners@perl.org Subject: Re: passing arguments to perl function with - in the string On Tue, Nov 29, 2011 at 08:12:29AM -0500, Nemana, Satya wrote: > Hi Hello: > I need to pass argument to a function like this -chan_range => > "$chs-$che" > > Normally when this used which works -chan_range => "1-24" > > However, when I try to put variable values instead of a scalar string, I > get compilation errors (the errors are in different part of the code > which is completely clueless) There's nothing special about interpolating a string with a '-' character in it. That should work fine. Tell us the actual errors that you are getting and we can help you to understand them. > I tried using \" and without the " also, but nothing helped. You seem to be struggling with Perl syntax at a basic level. Perhaps you would benefit from reviewing perlsyn and/or perldata. perldoc perlsyn perldoc perldata (Or look them up online) Regards, -- Brandon McCaig Castopulence Software <https://www.castopulence.org/> Blog <http://www.bamccaig.com/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say' -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
How to compile just the current perl module, ignoring all the other included modules
Hi Gurus I have to compile a perl module which includes a lot of other modules. The other modules will not change during compilations of my current module. Only my current module keeps on changing. The compiler however starts compiling from all the modules included in the current module with the use directive and the dependent modules. Is there any way to work around this intelligence of the perl compiler to ignore the compilation on the other modules and just compile the current program/module? I want these errors if any to be only caught in the run time. (although it will not happen because ultimately I will compile the complete modules to run the program) Thanks, Regards, Satya
RE: How to compile just the current perl module, ignoring all the other included modules
Hi Shawn I tried perl -c also with the same results. It takes 4-5 minutes to know that I missed a " some where. It is very painful. Is there no other way? Thanks, Regards, Satya -Original Message- From: Shawn H Corey [mailto:shawnhco...@gmail.com] Sent: 23 January 2012 16:38 To: beginners@perl.org Subject: Re: How to compile just the current perl module, ignoring all the other included modules On 12-01-23 11:20 AM, Nemana, Satya wrote: > Hi Gurus > > I have to compile a perl module which includes a lot of other modules. > The other modules will not change during compilations of my current module. > Only my current module keeps on changing. > The compiler however starts compiling from all the modules included in the > current module with the use directive and the dependent modules. > Is there any way to work around this intelligence of the perl compiler to > ignore the compilation on the other modules and just compile the current > program/module? > I want these errors if any to be only caught in the run time. > (although it will not happen because ultimately I will compile the > complete modules to run the program) > > Thanks, > > Regards, > Satya > Perl has to compile and run the modules yours depends on to have the correct context. Without them, it cannot determine if your module is correct. Try: perl -c MyModule.pm -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. Strength is not a measure of the body. It's a measure of the heart. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: How to compile just the current perl module, ignoring all the other included modules
Hi Shawn How do I use this option of -MO=Deparse when executing a perl script with an embedded #! Prompt? Our scripts start with the line #!/ats/bin/perl -w I tried adding the parameters here, but got the following errors Too late for "-MO=Deparse" option at ./startAutomation line 1. BEGIN { $^W = 1; } Then there are a host of other environment variables set before executing the functions in the modules by a call to unless ( my $return_val = do $test_suite_list_file ) { die "ERROR: Couldn't parse test suite file \"$test_suite_list_file\": $@\n" if $@; die "ERROR: Couldn't 'do' test suite file \"$test_suite_list_file\": $!\n" unless defined $return_val; die "ERROR: Couldn't run test suite file \"$test_suite_list_file\": $!\n" unless $return_val; is there other way of using the option -MO=Deparse?? Thanks, Satya -Original Message- From: Shawn H Corey [mailto:shawnhco...@gmail.com] Sent: 23 January 2012 18:25 To: beginners@perl.org Subject: Re: How to compile just the current perl module, ignoring all the other included modules On 12-01-23 12:38 PM, Nemana, Satya wrote: > I tried perl -c also with the same results. > It takes 4-5 minutes to know that I missed a " some where. > It is very painful. > Is there no other way? That's very unusual, most scripts take only a few seconds to compile. Try: perl -MO=Deparse MyModule.pm -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. Strength is not a measure of the body. It's a measure of the heart. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: How to compile just the current perl module, ignoring all the other included modules
Hi Rob All I got from this exercise is ./startAutomation syntax OK and a complete print of the startAutomation perl file with the fully qualified function names, all the variables used in the program at the beginning of the program. From the time command output, as used in the command "time /ats/bin/perl -w -MO=Deparse ./startAutomation " I have 92.765u 110.414s 3:24.11 99.5% 0+0k 0+0io 0pf+0w How do I know module wise, how much time perl is taking for compiling each of the modules and where perl is spending time in the compilation? How do I enable more verbose in the compilation or execution of the program? Thanks, Satya -Original Message- From: Rob Dixon [mailto:rob.di...@gmx.com] Sent: 27 January 2012 15:19 To: beginners@perl.org Cc: Nemana, Satya Subject: Re: How to compile just the current perl module, ignoring all the other included modules On 27/01/2012 12:58, Nemana, Satya wrote: > Hi Shawn > > How do I use this option of -MO=Deparse when executing a perl script > with an embedded #! Prompt? > > Our scripts start with the line > #!/ats/bin/perl -w > > I tried adding the parameters here, but got the following errors > > Too late for "-MO=Deparse" option at ./startAutomation line 1. > BEGIN { $^W = 1; } > > Then there are a host of other environment variables set before > executing the functions in the modules by a call to > > unless ( my $return_val = do $test_suite_list_file ) { > die "ERROR: Couldn't parse test suite file \"$test_suite_list_file\": > $@\n" if $@; > die "ERROR: Couldn't 'do' test suite file \"$test_suite_list_file\": > $!\n" unless defined $return_val; > die "ERROR: Couldn't run test suite file > \"$test_suite_list_file\": $!\n" unless $return_val; > > is there other way of using the option -MO=Deparse?? No, the module has to be mentioned on the comnmand line, but you can say /ats/bin/perl -w -MO=Deparse prog.pl which will have the desired effect. You can also add the additional files in the same command if necessary using the -f option like this /ats/bin/perl -w -MO=Deparse -f file1.pl -f file2.pl prog.pl Also you should be using use warnings; instead of -w in the #! line. HTH, Rob
RE: How to compile just the current perl module, ignoring all the other included modules
Hi Timothy Thank you,(sounds like a silver bullet J ) will give it a try and post the results. Regards, Satya From: timothy adigun [mailto:2teezp...@gmail.com] Sent: 27 January 2012 16:46 To: Nemana, Satya Cc: Rob Dixon; beginners@perl.org Subject: Re: How to compile just the current perl module, ignoring all the other included modules what you want I mean! thanks On Fri, Jan 27, 2012 at 5:45 PM, timothy adigun <2teezp...@gmail.com> wrote: Hi Satya, On Fri, Jan 27, 2012 at 5:29 PM, Nemana, Satya wrote: Hi Rob All I got from this exercise is ./startAutomation syntax OK and a complete print of the startAutomation perl file with the fully qualified function names, all the variables used in the program at the beginning of the program. >From the time command output, as used in the command "time /ats/bin/perl -w -MO=Deparse ./startAutomation " I have 92.765u 110.414s 3:24.11 99.5% 0+0k 0+0io 0pf+0w How do I know module wise, how much time perl is taking for compiling each of the modules and where perl is spending time in the compilation? I think the module you need is Benchmark. Please do on CLI: perldoc Benchmark. Am sure you get want to want! How do I enable more verbose in the compilation or execution of the program? Thanks, Satya -Original Message- From: Rob Dixon [mailto:rob.di...@gmx.com] Sent: 27 January 2012 15:19 To: beginners@perl.org Cc: Nemana, Satya Subject: Re: How to compile just the current perl module, ignoring all the other included modules On 27/01/2012 12:58, Nemana, Satya wrote: > Hi Shawn > > How do I use this option of -MO=Deparse when executing a perl script > with an embedded #! Prompt? > > Our scripts start with the line > #!/ats/bin/perl -w > > I tried adding the parameters here, but got the following errors > > Too late for "-MO=Deparse" option at ./startAutomation line 1. > BEGIN { $^W = 1; } > > Then there are a host of other environment variables set before > executing the functions in the modules by a call to > > unless ( my $return_val = do $test_suite_list_file ) { > die "ERROR: Couldn't parse test suite file \"$test_suite_list_file\": $@\n" if $@; > die "ERROR: Couldn't 'do' test suite file \"$test_suite_list_file\": $!\n" unless defined $return_val; > die "ERROR: Couldn't run test suite file > \"$test_suite_list_file\": $!\n" unless $return_val; > > is there other way of using the option -MO=Deparse?? No, the module has to be mentioned on the comnmand line, but you can say /ats/bin/perl -w -MO=Deparse prog.pl which will have the desired effect. You can also add the additional files in the same command if necessary using the -f option like this /ats/bin/perl -w -MO=Deparse -f file1.pl -f file2.pl prog.pl Also you should be using use warnings; instead of -w in the #! line. HTH, Rob -- Tim -- Tim
Perl coding standards
Hi Gurus Is there a website /document which you recommend for learning perl coding standards? I understand googling will give a good number of results, but want some useful ones which are practically followed and useful. Regards, Satya
RE: Perl coding standards
Timothy, Shlomi Fish, Rob, jbiskofski , Thank you for your directions and inputs. I am going through them now. Regards, Satya From: timothy adigun [mailto:2teezp...@gmail.com] Sent: 01 February 2012 05:41 To: Shlomi Fish Cc: Nemana, Satya; beginners@perl.org Subject: Re: Perl coding standards Hi Satya, Plus you can also look at Effective Perl Programming [Second Edition] by Joseph N. Hall, Joshua A. McAdams and brian d foy. On Tue, Jan 31, 2012 at 7:24 PM, Shlomi Fish wrote: Hi Satya, On Tue, 31 Jan 2012 10:38:08 -0500 "Nemana, Satya" wrote: > Hi Gurus > > > > Is there a website /document which you recommend for learning perl > coding standards? > > I understand googling will give a good number of results, but want some > useful ones which are practically followed and useful. > In addition to what other people said, there's: http://perl-begin.org/tutorials/bad-elements/ A warning in place is that it's a page I've written on a site maintained primarily by me. I borrowed a lot of advice from Damian Conway's Perl Best Practices and other sources, and included some of my own. I've omitted some stuff that, while I follow, is more controversial or I think is more a matter of taste. Also see: * http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-embracing-idioms.html * http://www.modernperlbooks.com/mt/2009/10/from-novice-to-adept-on-answers-to-smart-questions.html Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Rethinking CPAN - http://shlom.in/rethinking-cpan There is no IGLU Cabal. The problem of founding an IGLU Cabal has been proven, in a surprise move, to be equivalent to the question of existence of God, fully‐tolerant religions and NP‐complete oracles. — Omer Zak Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- Tim
one liner for removing string from an element of string array
Hi I have written a small program like this to just print file2 from the second element of the array by removing the .template from the entry (the name file2 can change and can be longer or shorter) use strict; use Data::Dumper; use warnings; my @templates = ( "/a/b/c/d/e/f/file1.template", "/a/b/c/d/e/f/file2.template" ); my @tokens=split( /\//, $templates[1]); print("\n".substr($tokens[$#tokens],0,-9)); However I want this to be more efficient and want to do this in a single line as I have to do this several times. How can I do that? TIA, Regards, Satya -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: one liner for removing string from an element of string array
Ron, Shlomi, I realized I haven’t thanked you. Thanks, Regards, Satya P.S : I am not a fan of one liners but as a beginner of perl there are many others out there who want to see the power of perl to do that in one line, it is just a way to be a fan of the language and then things get improved automatically since you love it. -Original Message- From: Shlomi Fish [mailto:shlo...@shlomifish.org] Sent: 13 July 2012 17:00 To: Nemana, Satya Cc: beginners@perl.org Subject: Re: one liner for removing string from an element of string array Hi Satya, On Fri, 13 Jul 2012 15:38:20 + "Nemana, Satya" wrote: > Hi > > I have written a small program like this to just print file2 from the second > element of the array by removing the .template from the entry (the name file2 > can change and can be longer or shorter) > > use strict; > use Data::Dumper; > use warnings; > > my @templates = ( > "/a/b/c/d/e/f/file1.template", > "/a/b/c/d/e/f/file2.template" > ); > > my @tokens=split( /\//, $templates[1]); > print("\n".substr($tokens[$#tokens],0,-9)); > > However I want this to be more efficient and want to do this in a single line > as I have to do this several times. > How can I do that? > See File::Basename - http://perldoc.perl.org/File/Basename.html . In the future, you may wish to use regular expressions for similar tasks: http://perl-begin.org/topics/regular-expressions/ Regarding achieving stuff in one line, see: http://www.shlomifish.org/humour/fortunes/show.cgi?id=newline-prices and if you're so concerned about that, you can always write subroutines to encapsulate commonly done tasks. Regards, Shlomi Fish > TIA, > > Regards, > Satya > > > -- - Shlomi Fish http://www.shlomifish.org/ Escape from GNU Autohell - http://www.shlomifish.org/open-source/anti/autohell/ Beliefs are what divide people. Doubt unites them. — http://en.wikiquote.org/wiki/Peter_Ustinov Please reply to list if it's a mailing list post - http://shlom.in/reply .
suggestions for perl program to make excel graph out from top output
Gurus, I want to write a perl program that captures top output in linux and makes nice graphs out of them(Microsoft excel) Are there ready to use modules for this which will help in writing the program? Any suggestions for inspirations? Search in cpan for top is resulting in a lot of results, most of which are irrelevant, are there smarter ways to search? Regards, Satya -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
variable definition error not caught when using strict and warnings
Hi I am a little confused with this program Program: use strict; use warnings; if ($999 == 1056) { print ("\nequal"); } else { print ("\nnot equal"); } What I expect: Perl to throw me an error as $999 variable is not defined, but perl executes the code with a warning.(I don't expect the code to compile at all) Output: Use of uninitialized value in numeric eq (==) at wrong1.pl line 4. not equal However, if I replace $999 with $num (which is not defined or initialized), I get the following error Global symbol "$num" requires explicit package name at wrong1.pl line 4. Execution of wrong1.pl aborted due to compilation errors. What is happening with the top program? Thanks in advance sn
RE: variable definition error not caught when using strict and warnings
From: Rob Dixon [rob.di...@gmx.com] Sent: 09 November 2012 17:17 To: beginners@perl.org Cc: Nemana, Satya Subject: Re: variable definition error not caught when using strict and warnings On 09/11/2012 17:08, Nemana, Satya wrote: > Hi > > I am a little confused with this program > > Program: > use strict; > use warnings; > > if ($999 == 1056) > { > print ("\nequal"); > } > else > { > print ("\nnot equal"); > } > > What I expect: Perl to throw me an error as $999 variable is not defined, but > perl executes the code with a warning.(I don't expect the code to compile at > all) > > Output: > Use of uninitialized value in numeric eq (==) at wrong1.pl line 4. > > not equal > > > However, if I replace $999 with $num (which is not defined or initialized), I > get the following error > > Global symbol "$num" requires explicit package name at wrong1.pl line 4. > Execution of wrong1.pl aborted due to compilation errors. > > What is happening with the top program? Hello Satya The variable $999 holds the 999th capture from the most recent regular successful expression match. Since you have no regular expressions in the program it is left undefined. It would be very unusual to have so many captures in a regex but Perl does support it. Rob Hi Rob Thank you. I will give a read of the perl regular expression manual. Actually $999 resulted in a typo was i wanted to compare another variable with 999. Not from a regular expression. But it took a while for me to find the culprit as the intended code was never hit. I was trying to understand why I never got an error during the compile itself. Thanks for answering. Regards, Satya -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
how to make perl program run continue when i press control+s to pause screen output
Hi I am having a slight difficulty in getting this accomplished. When my perl program keeps running, I sometimes need to pause the screen output and check some things on the output. But, I want my program to still keep running while I pause the screen. (using ctrl+s on putty) But the program also is pausing.(I tested this with a simple program which prints number from 1-100 sleeping 1 second after each print , but the main program I am trying to get this working is much complex, so will try things here first before modifying the original program) Test Code : use strict; use warnings; for (my $i=1; $i <= 200; $i++) { print "\ni is $i"; sleep 1; } Please, could someone throw some light on which areas of perl to look at for this. I am not looking for a program, but specific areas where I have to do the reading. I will come back with the program once I can make out what to do for any suggestions. Thanks, Satya
RE: how to make perl program run continue when i press control+s to pause screen output
Thanks Travis, Shlomi , Shawn, Luca, and James. The program pauses i.e does not run further when I press Cntrl –S When I press Ctrl-Q again, the program resumes excactly where it was when I hit cntrl-q. It is not a deamon, but a simple automation program and it is single threaded , goes on sequentially. I need to try out the programs that you suggested . However I don’t accept that the program will be running in the background when I press Ctrl+s. In the below example, once I start the program after seeing “i is 5” on the output, if I do ctrl+s, the output resumes at I is 6 even if I press ctrl+q after a minute or so. I expect it to print out till say i=65 during the 1 minute and I see the output all at once when I do ctrl+q I tried out a simple shell program and it also seems to be the same.(as the perl one) Is it that if the program is multi threaded or something like that that the program will keep to print even though I have paused the screen? So, when I press ctrl+q again all the buffered output is emptied out first and then the current output from the program. May be!! Sorry if it is out of topic for this forum. From: Travis Thornhill [mailto:madslashers2...@yahoo.com] Sent: 06 June 2013 17:04 To: Nemana, Satya Cc: beginners@perl.org Subject: Re: how to make perl program run continue when i press control+s to pause screen output On Jun 5, 2013, at 4:18, "Nemana, Satya" mailto:snem...@sonusnet.com>> wrote: Hi I am having a slight difficulty in getting this accomplished. When my perl program keeps running, I sometimes need to pause the screen output and check some things on the output. But, I want my program to still keep running while I pause the screen. (using ctrl+s on putty) But the program also is pausing.(I tested this with a simple program which prints number from 1-100 sleeping 1 second after each print , but the main program I am trying to get this working is much complex, so will try things here first before modifying the original program) Test Code : use strict; use warnings; for (my $i=1; $i <= 200; $i++) { print "\ni is $i"; sleep 1; } Please, could someone throw some light on which areas of perl to look at for this. I am not looking for a program, but specific areas where I have to do the reading. I will come back with the program once I can make out what to do for any suggestions. Thanks, Satya Your program should still be running, and it should still accept keyboard input. After ctrl-s, you just can't see any input/output. Try ctrl-q to recover.