Re: About staying brushed up on perl
I am now 73 years old and retired one year ago. I used Perl extensively from 1998 until I retired. It can be hard to remember all the tricks, even when you use or write Perl often. When I learned or developed a useful technique, I would keep the program or a bit of it around. I have lots of old programs and pieces of programs. I never got so systematic as to index them for the particular techniques. When I would leave a job, I would take with me a couple of what I considered to be the best or most useful programs I had written. This might not have been totally legal, but I did not use any previous employer's programs for a new employer. I just kept the programs in my archive of programming technique samples. My most recent Perl project was analyzing a .csv file from a financial consultant. I moved some assets from him to another investment firm. The consultant got mad at me and would not provide a useful report. He just sent a .csv file with dates and amounts, which I analyzed with a Perl program. I also highly recommend the O'Reilly books on Perl. Good luck with Perl. Marilyn On Jul 21, 2014, at 6:34 AM, Shawn H Corey shawnhco...@gmail.com wrote: On Mon, 21 Jul 2014 15:01:10 +0200 mimosin...@gmail.com wrote: I have self-learned Perl about a couple of years ago and I am also having a similar use of Perl, so I often forget how I did things. I must also say that I am about to be 50 years old next December and I do not have any technical education as my degree is in psychology. I use http://perlweekly.com/ to see what is going on, http://perlmaven.com/ to remember how things are done and O'Reilly if I need more in-depth understanding on a specific issue. Cheers! Welcome to Perl. Here are some links you might find useful: * official site http://www.perl.org/ * beginners' help http://learn.perl.org/faq/beginners.html * advance help http://perlmonks.org/ * documentation http://perldoc.perl.org/ * news http://perlsphere.net/ * repository http://www.cpan.org/ * blog http://blogs.perl.org/ * regional groups http://www.pm.org/ * videos http://perltv.org/ -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Nature of this list
The F-bomb is totally unnecessary. Such language is for teenagers who do not yet know how to communicate displeasure effectively. Please grow up. Personally, I am finding this discussion fascinating. I have often wondered why the academics at IBM would attack each other's presentations. It appears that part of the process of getting a PhD is learning to give and take intense attacks. This discussion is most enlightening. Marilyn On Apr 23, 2011, at 12:00 PM, Brian Fraser wrote: Please people. I urge you all to kindly fuck off. This is getting ridiculous. You are arguing about *tone*. Who gives a flying fuck about tone if the post has substance? Are we fucking two? Are our egos so fragile that we can't take the slightest of drubbings? So sensitive that a word in caps can start this kind of shitstorm? (Apparently yes, but bear with me for a sec) Tone trolls, the lot of you. Yes, being nice is fine and all, and it's a beginners list, so handholding should be the aim. And rudeness for rudeness sake is utterly counterproductive. But I've been on this list for a while now, and I can't recall a single instance of someone being rude when replying a question. ...I'll be the first to admit that my memory is crap, but nevertheless, until someone has provided links to substantiate these claims, please drop the strawman. On the topic of tone, if an error is so egregious that it must be corrected, strong language sometimes is needed to drive the point. Personally, I still wouldn't condone that kind terseness... When directly answering the beginner. But answers themselves? That's an entirely different domain. By answering, you are claiming to be an expert; As an expert, you are opening your answer and code to full scrutiny. If you choose to be the kind of teacher who will always answer with a smile and kindly nudge people into enlightenment, good for you. But spare the rest of us of the lecture. You'll find that not wasting your time trying to control how others communicate can be quite freeing. :) (A side note for Tiago and Lali and any other PhD student and/or scientist out there: Just mention your situation and you are assured, to the best of my ability, a hand-holding reply from me. Which may turn out to be respectful silence as I'm not an expert, but well. I have a soft spot for science, which can probably be traced back to a math or science teacher (or blogger) that I appreciate :p) Brian. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to set LD_LIBRARY_PATH
On May 29, 2010, at 6:24 AM, Paul Johnson wrote: On Fri, May 28, 2010 at 11:23:32AM -0700, Marilyn Sander wrote: On May 28, 2010, at 9:33 AM, Paul Johnson wrote: On Fri, May 28, 2010 at 06:14:38AM -0400, John Scoles wrote: You will have to set those values before your modules load. So you should stick them in the BEGIN and that should work ... except where it doesn't, such as on Solaris for example. Here, LD_LIBRARY_PATH (at least) really does need to be set before the process starts. You can do this by writing a shell wrapper, or re-execing your perl script if the value is not already set. Have you considered doing a require instead of a use. With require, the loading is done at run time, and would be governed by the setting of LD_LIBRARY_PATH, at the time the require statement is executed. Just set LD_LIBRARY_PATH before doing the require. I'm afraid that you may have misunderstood what I wrote. There are times when you really do need to set the variable before the process starts. I did not misunderstand what you wrote. My reasoning was that the thing being loaded is a shared object (.so file). The system loader (ld) has to be invoked for loading a shared object. That seems to me to require a separate process, with an environment stack inherited from the Perl process that invokes it. I was also assuming that setting an environment variable at run time would set the environment for the Perl process that is executing the Perl program. However, I did not test it. I will test it and see what happens. --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to set LD_LIBRARY_PATH
On May 28, 2010, at 9:33 AM, Paul Johnson wrote: On Fri, May 28, 2010 at 06:14:38AM -0400, John Scoles wrote: You will have to set those values before your modules load. So you should stick them in the BEGIN and that should work ... except where it doesn't, such as on Solaris for example. Here, LD_LIBRARY_PATH (at least) really does need to be set before the process starts. You can do this by writing a shell wrapper, or re-execing your perl script if the value is not already set. You're using linux and I'm not sure if this sort of messing about is required there. http://www.compuspec.net/reference/language/perl/BEGIN_and_END.shtml cheers John Scoles On Fri, May 28, 2010 at 3:45 AM, newbie01 perl newbie01.p...@gmail.comwrote: Hi all, Can someone advise how to set LD_LIBRARY_PATH from within the Perl scripts? If I set LD_LIBRARY_PATH from the command line, all is okay [oracle ~]$ perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,\n;' Can't load '/oracle/product/db/11.1/perl/lib/site_perl/5.8.3/x86_64-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.11.1: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi/DynaLoader.pm line 230. at -e line 1 Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1. [oracle ~]$ export LD_LIBRARY_PATH=/oracle/product/db/11.1/lib [oracle ~]$ perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,\n;' 1.15 But if I do the following instead in the Perl script, it does not work? How to set the LD_LIBRARY_PATH then? $ENV{ORACLE_HOME}=$ORACLE_HOME; $ENV{ORACLE_SID}=$ORACLE_SID; $ENV{PATH}=$ORACLE_HOME/bin:$PATH; $ENV{LD_LIBRARY_PATH}=$ORACLE_HOME/lib; FYI, the script is to run from a cron which is why am setting LD_LIBRARY_PATH in the script. Any response will be very much appreciated. Thanks in advance. Have you considered doing a require instead of a use. With require, the loading is done at run time, and would be governed by the setting of LD_LIBRARY_PATH, at the time the require statement is executed. Just set LD_LIBRARY_PATH before doing the require. --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to get environment variables from child shell
On May 27, 2010, at 4:58 PM, Jim Gibson wrote: On 5/27/10 Thu May 27, 2010 4:51 PM, Bob Sadri bob.m.sa...@gmail.com scribbled: Hi I have a perl script that calls a csh script. The csh script sources some environment variables (among others). When the control comes back to my perl script I like to use the environment variables set in the csh script. However, since this has happened in the child shell environment I am not able to see the variables. Can someone help me with this problem? Consult the advice given by 'perldoc -q environment'. Short answer: can't be done. Well, if you are allowed to modify the csh script, you can make it print the variables to a file or stdout, and capture that output. If you know what file it sources, you could read that file and get the variables. I would say that if your Perl script needs to know what environment the csh script is using, and it is part of a larger application that includes the csh script, then the environment-setting should be made a public interface that is accessible to your Perl script. But if you are just trying to snoop on what the csh script is doing, you are out of luck. --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Location of Perl libraries
Hi, Perl Experts. I'm writing some Perl scripts that are for driving the build of some software for my company. The build runs on Windows machines. We have several build machines, and they will all use the same scripts and same Perl modules. Now, I'm not a Windows person; I'm much more accustomed to UNIX/Solaris/Linux and to having automounted directories for software. I would like to put these Perl scripts and modules on a network drive, and have all the build machines (which I control fully) map the same drive to the location of the libraries. The drive would be laid out as path-to-perl/bin and path-to-perl/lib. The top script would be invoked as perl drive:\path-to-perl\bin\script-name, and each top script would unshift path-to-perl/lib onto @INC. Is that too non-Windows-like? Would it weird out my successor(s) in this job? Another group has a large number of Windows build machines, and they install all their Perl modules in C:\Perl\site, and the Perl scripts themselves in C:\bat. Which means, whenever they change the build software (which is frequently), they have to re-install on lots of machines. What would be the preferred practice here? Please note, the scripts are not at all for end users; they are only for the nightly build system. thanks, --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Location of Perl libraries
On May 26, 2010, at 3:35 PM, Shawn H Corey wrote: On 10-05-26 05:41 PM, Marilyn Sander wrote: What would be the preferred practice here? See `perldoc lib` -- Just my 0.0002 million dollars worth, Shawn Thanks, this document just explains about @INC. I already know how to use @INC. My question was about normal, standard, or best practice for placement of scripts and Perl libraries on Windows. The default setup for ActiveState is to put site-specific stuff into c:\Perl\site\lib. I would rather use a location on the network, mapped to a network drive. I know how to do that, I just want to know if Windows people would find that weird or objectionable. thanks, --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: system() call in END() subroutine overrides script exit value
I On May 17, 2010, at 11:21 AM, John W. Krahn wrote: John W. Krahn wrote: Kelly Jones wrote: I did this in tcsh: perl -le 'exit(2); sub END {system(date);}' ; echo $status Mon May 17 11:09:43 MDT 2010 0 In other words, the return value of the date command in an END subroutine overrides my desired exit value. How do I fix this? I want to tell Perl: if I explicitly do exit($foo), I want the script to exit with status $foo? This is probably what you want: $ perl -le' END { system date; $? = 2 } ' ; echo $? Mon May 17 11:01:37 PDT 2010 2 Or don't use something that sets $? in the END block: $ perl -le' exit 2; END { print scalar localtime } ' ; echo $? Is it possible to set $?, as in { my $exit = $?; system (do something); $? = $exit; } or ... { my $exit = $? system (do something); return $exit; } I'm having a bit of trouble with a DESTROY method on a object that needs to clean up external persistent data when an object is no longer referenced. I inherited the code, and the program is not cleaning up objects before exiting. The DESTROY method does the cleanup on exit, and changes the return code. What would be the right way to change that DESTROY method? thanks, --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl rounding errors?
On Apr 26, 2010, at 11:22 AM, Uri Guttman wrote: JWK == John W Krahn jwkr...@shaw.ca writes: i must have not see the OP's reply yet so this is mostly for him. This is the routine as it looks now (I would be happy to hear about errors or improvements that you might see) sub round { my $number = shift; if ( $number == 0 ) { return 0.00; } that is no different than returning 0. if ( length( $number ) = 4 ) { return $number; } my $int = int( $number ); # Get the whole number my $dec = $number - $int; # Get the decimals only $dec = sprintf( %.15f, $dec ) * 1000; that will introduce more errors. you can just edit the text if you want to mung the decimal point accurately. you are converting between numbers and text back and forth for no reason. my @digits = split( //, $dec ); my @reverse_digits = reverse( @digits ); my $number_of_digits = $#reverse_digits - 1; this is insane code. my $remember = 0; my $tracker = 0; for( my $x = 0; $x = $number_of_digits; $x++ ) { $reverse_digits[$x] = $reverse_digits[$x] + $remember; my $result = $reverse_digits[$x] + 5; if ( $result = 10 ) { $remember = 1; } else { $remember = 0; } $tracker = $x; } if ( $reverse_digits[$tracker] = 10 ) { $reverse_digits[$tracker] = $reverse_digits[$tracker] - 10; $reverse_digits[$tracker + 1]++; if ( $reverse_digits[$tracker + 1] == 10 ) { $reverse_digits[$tracker + 1] = 0; $int++; } } my @reordered_digits = reverse(@reverse_digits); splice( @reordered_digits, 2 ); my $decimal_amount = join( '', @reordered_digits ); return $int.$decimal_amount; i can't see this code making any sense or doing the 'right' thing. you need to learn how to let perl work for you. the classic way to round is to add .5 to the right decimal spot and then truncate at the right spot. have you tried that? also perl does rounding just fine. the problem is that you don't know what perl thinks your numbers really are when you only print 2 decimal digits. print more (as you do in that insane code) and you will see. finally as others have stated, USE integers for money math. never use floats. then you will never have this problem. uri Or use COBOL or PL/I ;-). Seriously, though, you need to be using fixed-point arithmetic, which in Perl is only available as integer arithmetic. Doing it in cents is not enough--it has to be carried out to the tenth of a cent. To round, add 5 to the low-order digit, which represents a tenth of a cent, then round off the resulting low-order digit. You do need to keep track of the scale so you can put the decimal point in the right place when you write out the values. Even that method could result in some inaccurate rounding if the computer keeps integers in binary but you expect your rounding to be done in base 10. I did a quick program a while back to compute stock basis. My proof results were a few cents off from those of the stock broker. I attribute that to the fact that I was using floating point and the standard rounding algorithm, instead of converting to fixed-point integer arithmetic. It didn't matter because I only needed the values for my tax returns, and a few cents has no negligible effect on the bottom line. Since you are using real accounting data, it really has to be accurate. For that, you need fixed-point currency calculations and a way to round in base 10. --Marilyn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Treatment of Windows paths in Activestate Perl
Does anyone have insight into this situation? On one Windows 2003 server system, backslashes in path names in arguments to Perl are getting translated to forward slashes. On other Windows 2003 systems, with the exact same version and build of ActiveState Perl installed, the conversion to forward slashes does not happen. I've checked the PATH and the file associations. Perl is in all cases coming from C:\Perl\bin\perl.exe. I examined the registry entries in HKLM\SOFTWARE\ActiveState, and they are all identical. The weird thing is, the Perl on this machine behaved like the Perl on all the other machines until some time in the middle of last week. Then it changed. Drove me crazy for a couple of days until I wrote the following test case and verified the new behavior. TIA, Marilyn Sander type tryperl.pl for $i ( 0.. scalar(@ARGV) -1 ) { $arg=$ARGV[$i]; print argument $i is $arg\n; } perl tryperl.pl E:\test_downloads H:\no_such_directory D:/whatever argument 0 is E:/test_downloads argument 1 is H:/no_such_directory argument 2 is D:/whatever perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 21 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 816 [255195] provided by ActiveState http://www.ActiveState.com Built Mar 1 2006 18:00:52 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using man perl or perldoc perl. If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl
Or just open Windows Explorer and see if the file is there. If it isn't, search for it. --Marilyn On Mar 31, 2007, at 6:54 PM, yitzle wrote: [error] client [127.0.0.1] OS3 The system cannot specified the path specified: *C:\Program Files\Apache Group\Apache2\cgi-bin\first.pl *This means the server is trying to access a file that that path and can not find it. If you ensure that the file is at that path, it ought to work. To test if the file is there, run the following line: perl C:\Program Files\Apache Group\Apache2\cgi-bin\first.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: To Reference or not to reference
Chas, You mention an issue that i've been pondering for a while. When and why should you use an OO style instead of a hash? If your basic data structure (or several) is a hash, what is to be gained by refactoring as OO? Isn't OO just a large amount of syntactic sugar surrounding some simple data constructs? I'm not being facetious or sarcastic. I characterize OO as syntactic sugar only as a straw man to knock down. I really would like to know what people see as the advantage to OO in this situation. thanks, --Marilyn Sander On Mar 29, 2007, at 5:57 AM, Chas Owens wrote: On 3/29/07, Dukelow, Don [EMAIL PROTECTED] wrote: I've written a Perl program that declares a hash at the top of the program %myHask;. It has worked great until now when one sub program seams to be making its own copy of the hash. I can find no typo's or anything but there my still be one there. My question is would it be better to pass the global hash by reference to each sub program to cut down on possible typo errors or just leave it global and fix the problem I have? Don Dukelow I can say with near 100% certainty that passing a ref is better than using a global. Also, if you are finding your self writing code that is focused around a hash that you are calling a number of functions on then what you are really doing is writing OO code in a non-OO fashion. Consider refactoring the code as object based instead of hash based. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: hi please clarify my doubts
Devaraja, Is this a question about vperl? You speak of generating verilog code. Is the instantiation you speak of the instantiation of your block that is defined in verilog? What do you mean by the instantiation part of the perl script? --Marilyn Tom Phoenix wrote On 02/14/06 09:49,: On 2/13/06, DEVARAJA AP [EMAIL PROTECTED] wrote: i wrote a perlscript to generate a verilog code with instantiations .in this after instantiation, the ports getting as eg module_name name(.a(a),.b(b),...) but for connection sakeif want to connect a to some k and b to some p (say).here we wanted to change those names manually. is ther any way to do trhis automatically in the instantiation part of the perl script itself. Almost certainly, what you want is possible. Perl is very versatile. Unfortunately, I cannot understand what you are asking about. It may help if you include the Perl code that you're talking about. If another language is better for you than English, feel free to try that one. At a guess, maybe you want something like this code. Or maybe not... if ($alternate_site) { $port = 'k'; } else { $port = 'a'; } Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Marilyn E. Sander[EMAIL PROTECTED] Database (CM) Engineer Phone (408)616-5651 internal 45651 ~ NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Continuing the Basic Question
On Feb 9, 2006, at 2:18 PM, Avinash Sridhar wrote: Hello, I installed ActivePerl, then wrote up a sample helloworld.pl script, stored it on the desktop, then ran this command from the cmd prompt. C:\Documents and Settings\Administrator perl C:\Documents and Settings\Administrator\Desktop\ helloworld.pl i.e., perl path name\ filename.pl (is this right?) I get this prompt from the interpreter Can't open perl script hellowowrld.pl: No such file or directory Notice the spelling of the .pl script. I think you made a typo when trying to run it. --Marilyn What is it that I could be overlooking. Thanks for responses. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: help with matching
Hello, Rob. On Nov 9, 2005, at 10:49 AM, Rob.Savino wrote: I'm working on a simple script to get a list of users who do not exist while () { At this point, $_ ends with \n. $user = system(echo $_); This statement will set $user to the returned value from system(), which will be a numeric two-byte return code. $result = system(dsquery user -samID $_); $result at this point will also be a two-byte return code. It will likely be non-zero, because you are querying for a value that has a \n at the end of the actual value you really wanted to query for. } if (!$result) { print $user\n; } Here is my problem, dsquery user -samID should return nothing if a user does not exist. I was hoping the script would print $user only if there was no $result from dsquery user -samID. However, not only does it print every $user regardless of the was not $result, it also prints every $result. Can someone tell me why this is? Thanks, Rob --Mariyn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: system command help
On Nov 9, 2005, at 4:52 PM, Pablo Wolter wrote: The system function call returns a boolean value as return value, I don't remember if 1 is for fail and 0 for success or viceversa. Actually it is not a boolean value. It is a two-byte value, and each byte is an integer. You need to look up the system() function in some Perl documentation. If you get two bytes of zero back, that means system() and the command it invoked ran successfully. If you get a non-zero value, the lower byte indicates what error was found in the Perl run-time; the upper byte is the return code from the command executed by system(). --Marilyn I think your mistake is the lack of the test construction like if, so if (system($addgroup \$group\) == 0) { ... do something ... } I'm not in a box with perl to test this but something like that could work. Pablo. On 11/9/05, heena s [EMAIL PROTECTED] wrote: hi, is there any mistake in the script: #ADDING A TOOL GROUP system($addgroup \$group\) == 0 or die system @args failed: $? log_message(the group $group added); thanks - Yahoo! FareChase - Search multiple travel sites in one click. -- (o_ Pablo Wolter //\ Usuario #284649 V_/_ Debian Sid Kernel 2.6.8 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl/sh/bash scripts and emacs
Thanks, John. That did it. --Marilyn On Oct 29, 2005, at 10:11 PM, John W. Krahn wrote: Marilyn Sander wrote: thank you very much for the trouble you have taken with your answer. I acknowlege that our script is not the same as the example in Programming Perl. We really need to have the leading bash code there to choose what directory to execute Perl from. My question is still, is there a way to have that leading bash code and still have emacs see the file as a Perl script. I agree the documentation you've quoted does not say that it's possible. I just thought that the example in Programming Perl suggested there ought to be a way to do it. I've been guessing and trying different combinations, since there is no explicit rule or example.If I try #!/bin/bash -- # -*- perl -*- -x Perl gives the error message Can't emulate -x on #! line. The documentation you've quoted does not say explicitly that it's possible to construct this sort of script and have emacs recognize it. Perhaps it isn't. Do you know whether it is possible, and if so, how to do it? Please note, I am not an emacs user. The emacs user in question doesn't know how to do this, either. I am not an emacs user either but I would assume from reading the docs that you could do something like this: #!/bin/bash # shell code here exec $perl -x $0 ${1+$@} #! -*- perl -*- -w # perl code here __END__ something else here John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl/sh/bash scripts and emacs
Hello, John. thank you very much for the trouble you have taken with your answer. I acknowlege that our script is not the same as the example in Programming Perl. We really need to have the leading bash code there to choose what directory to execute Perl from. My question is still, is there a way to have that leading bash code and still have emacs see the file as a Perl script. I agree the documentation you've quoted does not say that it's possible. I just thought that the example in Programming Perl suggested there ought to be a way to do it. I've been guessing and trying different combinations, since there is no explicit rule or example.If I try #!/bin/bash -- # -*- perl -*- -x Perl gives the error message Can't emulate -x on #! line. The documentation you've quoted does not say explicitly that it's possible to construct this sort of script and have emacs recognize it. Perhaps it isn't. Do you know whether it is possible, and if so, how to do it? Please note, I am not an emacs user. The emacs user in question doesn't know how to do this, either. thanks again, --Marilyn PS You've made some useful suggestions in the code below and also asked why I've done things certain ways. I've inserted answers. On Oct 29, 2005, at 3:51 AM, John W. Krahn wrote: Marilyn Sander wrote: Not sure how much of a beginner question this is. I've been searching mail archives and can't find anything about it. I've embarrassed myself by giving advice based on my reading of the Camel book, but the advice doesn't work. In the Camel book Programming Perl, Chapter 19 is a chapter on using the Perl command line. One example there is to use #!/bin/sh -- # -*- perl -*- eval 'exec perl -S $0 ${1+$@}' if 0; The explanation says that the presence of -*- perl -*- on the shebang line causes perl not to pay attention to that line, but does cause emacs to treat the script as a perl file. That is not exactly what the book says. QUOTE Parsing of #! switches starts from where perl is first mentioned in the line. The sequences -* and - are specifically ignored for the benefit of emacs users, so that, if you're so inclined, you can say: #!/bin/sh -- # -*- perl -*- -p eval 'exec perl -S $0 ${1+$@}' if 0; and Perl will see only the -p switch. The fancy -*- perl -*- gizmo tells emacs to start up in Perl mode; you don't need it you don't use emacs. The -S mess is explained later under the description of that switch. /QUOTE What that means is that the system sees that the first two characters are '#!' and feeds the script to the program following those two characters, in this case the Bourne shell. The shell reads the first line and deals with any switches following the program name (the first switch -- means turn off further switch processing) then runs the code on the second and subsequent lines. The second line runs perl with the name of the current script ($0) as the perl program and the rest of the command line (${1+$@}) as arguments to that program. When perl reads the script it sees 'perl' on the first line and processes every thing after that (-*- -p) as switches for perl. But we'd like to be able to use sh or bash to locate one of several okay versions of Perl. The path to Perl differs depending on what installation it is run in. We cannot just use the user's path or environment, because these scripts are used in strictly-managed configuration management/QA/build/release processes. Each one has to use a particular version and installation of Perl and no other. We have got something that works quite well, except that an emacs user complains that emac doesn't recognize the script header as Perl, and instead provides shell highlighting instead of Perl highlighting. Hence my question is, how do we accommodate the emacs user? The following code works well (pathname specifics changed for confidentiality): #!/bin/bash -- # perl1=/path1/perl perl2=/path2/perl if [ -x $perl1 ] then perl=$perl1 elif [ -x $perl2 ] then perl=$perl2 else echo Unable to find perl, contact local suport person exit 2 fi exec $perl -x $0 $@ #!/dummydir/perl -w $myname=`basename $0` ;chomp $myname; perldoc File::Basename Yes, I know that's available. I didn't use it here. $mydir=`dirname $0` ; chomp $mydir; perldoc FindBin I'll look this one up. $mydir=`(cd $mydir; pwd)`; chomp $mydir; What Why perldoc -f chdir perldoc Cwd Thank you. the $RealBin exported from FindBin looks like it would do the trick in this case, since I am computing the path where the script is located. However, the $mydir computation can be used to compute the absolute path to any directory at run time. We use it often to record absolute paths in log files created during tests and builds, when we suspect the user could have changed $PATH or inserted a symlink to a control file or program. print I am $myname in directory
Perl/sh/bash scripts and emacs
Not sure how much of a beginner question this is. I've been searching mail archives and can't find anything about it. I've embarrassed myself by giving advice based on my reading of the Camel book, but the advice doesn't work. In the Camel book Programming Perl, Chapter 19 is a chapter on using the Perl command line. One example there is to use #!/bin/sh -- # -*- perl -*- eval 'exec perl -S $0 ${1+$@}' if 0; The explanation says that the presence of -*- perl -*- on the shebang line causes perl not to pay attention to that line, but does cause emacs to treat the script as a perl file. But we'd like to be able to use sh or bash to locate one of several okay versions of Perl. The path to Perl differs depending on what installation it is run in. We cannot just use the user's path or environment, because these scripts are used in strictly-managed configuration management/QA/build/release processes. Each one has to use a particular version and installation of Perl and no other. We have got something that works quite well, except that an emacs user complains that emac doesn't recognize the script header as Perl, and instead provides shell highlighting instead of Perl highlighting. Hence my question is, how do we accommodate the emacs user? The following code works well (pathname specifics changed for confidentiality): #!/bin/bash -- # perl1=/path1/perl perl2=/path2/perl if [ -x $perl1 ] then perl=$perl1 elif [ -x $perl2 ] then perl=$perl2 else echo Unable to find perl, contact local suport person exit 2 fi exec $perl -x $0 $@ #!/dummydir/perl -w $myname=`basename $0` ;chomp $myname; $mydir=`dirname $0` ; chomp $mydir; $mydir=`(cd $mydir; pwd)`; chomp $mydir; print I am $myname in directory $mydir\n; print My options are:\n; for $a ( @ARGV ) { print $a ; } $onlyonce=1; print \n; exit 0; --- Perl gets control, skips the bash code, finds the second shebang line, honors the -w flag, and runs the script. But if we change the initial shebang line to #!/bin/bash -- # -*- perl -*- then Perl does not skip the bash code, and gives lots of error messages. So it looks like the advice in the Camel book is no good. Either that or I've forgotten how to read a technical manual. Can someone help? thanks, --Marilyn Sander -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response