Re: Counting specific elements in a XML object
Chas Owens wrote: If we are going to pick nits then it should be grep -c employee fn Note that grep -c counts matching *lines*. There is no formal requirement that these elements appear on separate lines. Here's a slightly more complex Perl one-liner that counts *occurences* perl -lne '$n++ for /employee/g; END {print $n}' somefile.xml -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Clearing tables...
Sky Blueshoes wrote: What is the sequel statement to clear an entire table using DBI? It depends on your database, but typically: $dbh-do('delete from some_table'); Some databases support TRUNCATE: $dbh-do('truncate some_table'); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: multistring replacement
Chas Owens wrote: On 3/8/06, Eugeny Altshuler [EMAIL PROTECTED] wrote: snip local $/; # to slurp the file at once my $joined=; ... Be careful with the setting of $/. In small scripts like this one it is not very dangerous, but in larger scripts in can cause all manner of bugs if not properly localized: my $joined; { local $/ = undef; $joined = ; } I like to write this like: my $joined = do { local $/; }; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: the way to get current index of an array
[EMAIL PROTECTED] wrote: hi, perlers, Is there a simple way to get the current index of an array in loop statement? the procondition is you cannot get this information from array element. For example #!usr/bin/perl my @arr = qw/a b c d e/; for(@arr) { print The No.?? element is $_\n; } There is no built-in method for determining the array index, because for() and foreach() can iterate over things other than arrays. So you have to keep track of the index yourself, either by iterating over indexes like John showed, or keeping a separate variable: my $i = 0; for (@arr) { print The current element $_ is index $i\n; } continue { $i++; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Array of arrays
Tommy Grav wrote: print $refstars[1][0] ; # - This is line 38 However this code returns an error I do not understand Missing right curly or square bracket at refstar.pl line 38, at end of line syntax error at refstar.pl line 38, at EOF Execution of refstar.pl aborted due to compilation errors. Actually, that's only line 20 of what you posted. The code you posted compiles without error, so the problem is somewhere else. The error message is farily self-explanatory; you appear to have an opening brace somewhere that isn't closed. -- Well I can't stop here all day...I'm on a cycling tour of North Cornwall! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: survive with exec
a b wrote: Here i want to execute one and then execute another but don't wait for previous command i.e.something in background but im unable to do it. see: perldoc -q 'How do I start a process in the background?' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: print_r in Perl
Johannes Ernst wrote: I realize why it does that. I'm asking whether I can have something higher-level that works for objects on the abstraction level where one usually looks at an object. Data::Dumper is designed to produce Perl source code that can be eval'd to reconstruct the object. So it can't easily produce exactly what you're looking for. By messing around with $Data::Dumper::Terse and $Data::Dumper::Bless, you can get pretty close though. Otherwise, take a look at the source code for the _dump method and tweak it around to get the results you're after. -- Well I can't stop here all day...I'm on a cycling tour of North Cornwall! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: :: and -
Ken Perl wrote: what is the difference of :: and - in this statements? $authInstance = Operation::Auth::getInstance($session,$u-authMethod,$u-userId) This is a subroutine call, passing 3 arguments. $authInstance = Operation::Auth-getInstance($session,$u-authMethod,$u-userId) This is called a class method invocation. Perl will look for a getInstance sub in package Operation::Auth and its ancestors (via @ISA), and finally in package UNIVERSAL. If no sub is found, it will look for an AUTOLOAD sub using the same procedure and invoke it. Once a sub is found, it will be called with the string 'Operation::Auth' as the first argument, followed by the three remaining arguments. -- Well I can't stop here all day...I'm on a cycling tour of North Cornwall! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: whereis the socket mailing list
Jeff Pang wrote: The question I want to know is,when the 'close()' call happened,if it should generate a 'FIN' and send it to another end?If it's true,then at the server end,when it receive the 'EOF' coming from client,it can delay for some time to call 'close()',so the 'FIN' should not be sent to client immediately,is it? Once you call close(), you're done with the connection. The kernel handles the various packets associated with terminating the connection. When the server sees EOF, it can call close() immediately if it doesn't need to send any more data. Again, the kernel will handle the details. shutdown() is only needed if you want to tell the other side you're done sending, but you need to be able to keep receiving data. If you're interested in learning more, I *very highly* recommend you buy and read Stevens' Unix Network Programming, Volume 1 (http://www.amazon.com/gp/product/0131411551). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: connect to oracle server
jm wrote: i've asked oracle's forums and gotten nothing useful, so hopefully someone here can help... i have scripts that connect to mysql; they need to connect to an oracle server. i've tried installing DBD::Oracle from cpan, and get an error message about The ORACLE_HOME environment variable value (/usr/lib/oracle/10.2.0.1/client/lib) is not valid. - this after installing oracle's instantclient-basic and instantclient-sqlplus. my question is, what oracle software (the absolute minimum necessary) do i need to install in order for scripts to connect to an oracle server? and if i did install the proper programs (all of them) what/where do i need to go to find the missing steps to get it all working? I think you have enough software. If you can run SQL*Plus, you should be OK. Try using just /usr/lib/oracle/10.2.0.1 or /usr/lib/oracle/10.2.0.1/client as your ORACLE_HOME. Also, be sure to look at the README's with the DBD::Oracle package. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: connect to oracle server
jm wrote: On 2/9/06, Bob Showalter [EMAIL PROTECTED] wrote: I think you have enough software. If you can run SQL*Plus, you should be OK. Try using just /usr/lib/oracle/10.2.0.1 or /usr/lib/oracle/10.2.0.1/client as your ORACLE_HOME. Also, be sure to look at the README's with the DBD::Oracle package. trying /usr/lib/oracle/10.2.0.1 gives me ... Unable to locate an oracle.mk, proc.mk or other suitable *.mk file in your Oracle installation. ... different error, but no .mk files are included in the downloads i installed. i found a different point of contact in oracle, i'm also asking there to see if this new person might have something useful but if there are any other suggestions, don't hesitate *s* I guess I was wrong. I'm not sure exactly what you need to have installed. Those .mk files are used to link the Oracle libs into the DBD::Oracle extension. I would read the README's that come with DBD::Oracle over very carefully, and then find the dbi-users list (Try http://dbi.perl.org). I *think* that oracle.mk is used to link the server, and proc.mk is used to link the Pro*C precompiler. Is there an option within your installer to install Developer or Programmer stuff? You might try that. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Saving Content of HTTP::Response Directly To Disk
Stephen Le wrote: I'm writing a download manager in Perl and using the LWP library of Perl modules. Is there any way I can save the contents of a HTTP::Response object directly to disk? I don't want particularly large requests to be cached into memory. Yes. Look at the documentation for LWP::UserAgent. You can supply a :content_file option to the get() method: my $resp = $ua-get($url, :content_file = 'file.dat'); HTH, Bob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: scope of the variable?
[EMAIL PROTECTED] wrote: ... My question is how to access $dbaccess variable (object) defined and initialized in test.pm within test2.pm module? If $dbaccess is delared with 'my' in test.pm, you cannot directly access it from another file. You have two basic options: 1. Provide an accessor function in test.pm that returns the object: sub dbaccess { $dbaccess } 2. Change the variable to a global (symbol table) variable. You can optionally use the Exporter module to allow the symbol to be exported to other namespaces: Test.pm --- package Test; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw($dbaccess); our $dbaccess; ... main.pl --- use Test qw($dbaccess); print $dbaccess-some_method; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Quoting question
Michael Weber wrote: Greetings! I am not completely understanding how perl parses quotes. Here is the line I want to execute: exec $command $cmd_msg; The variable $command is an executable shell script test.sh The problem comes in the $cmd_msg variable. This contains a line from my log file: Nov 13 11:54:31 fw-3 sshd(pam_unix)[19906]: authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=82-148-208-172.fiber.unet.nl The shell script blow up on the parenthesis: sh: -c: line 0: syntax error near unexpected token `(' How can I quote the exec line above so what gets passed to /bin/sh is the log file line contained in double quotes? Simplistic, but possibly risky: exec qq[$command $cmd_msg]; Much better, IMO: exec $command \Q$cmd_msg; Or even better, bypass the shell by using the list form of exec(): exec $command, $cmd_msg; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: return values evaluating to true
radhika wrote: Hi, I have a snippet of code as below. Even when I return 0 or '', why does @blocks evaluate to true? If rows returned are 0, then if(@blocks) should evaluate to false, correct? ... sub do_something { my @row = @_; return @row if(@row); return ''; } @blocks = do_something(); if([EMAIL PROTECTED]) When you return '', the @blocks array contains a single element with the value ''. When you test an array with if(), you're evaluating the array in scalar context, which returns the number of elements. So if([EMAIL PROTECTED]) is saying if the @blocks array doesn't contain any elements But it *does* contain the single '' element. Your solution is to use: return (); or just return; This will cause @blocks to receive an empty list and your test will work as you intend. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: file test
hien wrote: dear all, i am trying to check if there are any files named file* (e.g. file_001.txt file1.doc) in my directory. if( -e file* ) { print(true\n); } # this doesn't work else { print(false\n); } if( -e m/^file/ ) { print(true\n); } # this doesn't work either else { print(false\n); } Ouch, there's the dreaded doesn't work! (c.f. http://perl.plover.com/Questions4.html) Fortunately, you told us what you are after, so the question can be answered. -e only takes a single filename. You need a glob: print Found! if glob('file*'); Or the slightly deprecated: print Found! if file*; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: still confused on how to locally install perl modules without administrative privileges on windows (activestate 5.6.1 build 630)
Wolcott, Kenneth A wrote: Hi; It would be really nice if there was a clear, precise, concise, accurate and simple instruction of how to install Perl modules locally (non-privileged accounts) on Windows systems. http://www.cpan.org/misc/cpan-faq.html#How_install_Perl_modules really doesn't help me perform local (non-privileged) module installs on Windows... http://search.cpan.org/~jhi/perl-5.8.0/pod/perlmodinstall.pod This doesn't really help either... Try these instead: http://www.cpan.org/misc/cpan-faq.html#How_install_private http://www.cpan.org/misc/cpan-faq.html#How_use_private -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Simplest Way
Gladstone Daniel - dglads wrote: What would be the simplest way to remove leading and trailing blanks from a user input? To remove just blanks (but preserving possible trailing newline): s/^ +//, s/ +$// for $input; To remove all whitespace: s/^\s+//, s/\s+$// for $input; I like this idiom, because you can easily trim several variables at once: s/^\s+//, s/\s+$// for $foo, $bar, $baz; s/^\s+//, s/\s+$// for @array; s/^\s+//, s/\s+$// for values %hash; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: retrieving from opendbm
Anders Stegmann wrote: Hi! Why doesn't this work? Aargh! *Please* see http://perl.plover.com/Questions4.html You're expecting us to read your mind, so here goes... use strict; use warnings; my %result_hash = qw(foo bar); dbmopen(%result_hash, BB, 0666); BB needs to be quoted, and the syntax is not supported here. This statement clobbers whatever was previously in %result_hash. If you want to add stuff to the dbm file, open it first, then add the stuff. Error checking? dbmclose(%result_hash); dbmopen(%result_hash, BB, 0666); Need quotes around BB, and need error checking. while (my ($key,$val) = each %result_hash) { print $key,\n; Again, you need quotes here. } dbmclose(%result_hash); Note that dbmopen/dbmclose are deprecated in favor of the tie syntax. see e.g., perldoc DB_File -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Combine multiple lines into one line
Andrej Kastrin wrote: Hi all, I have the file, which looks like: *RECORD* *ID* 001 *TITLE* Here is title number one. *ABSTRACT* First sentence of the abstract. Second sentence of the abstract... Second line of the abstract. *RECORD* *ID* 002 *TITLE* Here is title number one. *ABSTRACT* First sentence of the abstract. Second sentence of the abstract... Second line of the abstract. Is there any simple way to transform this file to look like: *RECORD* *ID* 001 *TITLE* Here is title number one. *ABSTRACT* First sentence of the abstract. Second sentence of the abstract. Second line of the abstract. A one-liner: $ perl -lp0e 's/\n(?!\*[A-Z]+\*)/ /g' myfile.dat How it works: 1. Read input in paragraph mode (-0) option 2. Join any line that does not begin with *LETTERS* with the preceding line. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SOLVED Re: Obtaining complete Unix command line that evoked script as string
Grant Jacobs wrote: I want is the whole command *line*, not the portion of it that evoked the script, the latter being the individual *command* within the command line--confusing enough ;-) ? If I issue the example I gave in my OP: echo -n Starting... ; more some-stuff | \ doStuff.pl - 3 save-here.out ; echo done. Within doStuff.pl I want to obtain the command line, i.e. everything from echo through to 'done.', or at least everything from more through to save-here.out. (As I wrote in my OP: everything including pipes and redirects, etc.) Its the reason I gave this extended example command line as an example, including it spanning lines. That information is known only to the shell. The shell does a lot of processing of any given command line before invoking the program(s) specified. Unless the shell you're using has some mechanism for exporting that information (e.g. a history file), you're out of luck. Any solution will be specific to the particular shell you're using. Unix::PID knows only about the stuff that ps(1) knows, which is from the information passed to execve(2) when the program is launched. Pipe chars, redirection, etc. are all shell metachars that have no meaning to the kernel itself. I'm with JupiterHost; what exactly are you trying to accomplish here? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: why a.pl is faster than b.pl
Jeff Pang wrote: Hi,bob, You said: 3. It will probably be faster to use a single regex of the format: /pata|patb|patc|patd/ In fact maybe you are wrong on this. Darn. First time this year :-) Based on my test case,the RE written as below: /pata/ || /patb/ || /patc/ || /patd/ is much faster than yours. OK. Perhaps its due to backtracking. Go with what works! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: why a.pl is faster than b.pl
Jeff Pang wrote: hi,lists, I have two perl scripts as following: a.pl: #!/usr/bin/perl use strict; my @logs = glob ~/logs/rcptstat/da2005_12_28/da.127.0.0.1.*; foreach my $log (@logs) { open (HD,$log) or die $!; while(HD){ if ( ($_ =~ /×¢²á/o) || ($_ =~ /Õ÷ÎÄ/o) || ($_ =~ /Ê¥µ®¿ìÀÖ/) || ($_ =~ /ӦƸ/o) || ($_ =~ /�ø�¨/o) || ($_ =~ /·¢»õ/o) || ($_ =~ /±±¾©/o) || ($_ =~ /×Ê��/o) || ($_ =~ /�Å�¢/o) || ($_ =~ /�ãɽ/o) || ($_ =~ /°Ù�ò/o) || ($_ =~ /Ãâ·Ñ/o) ) { print $_; } } close HD; } b.pl #!/usr/bin/perl use strict; my $ref = sub { $_[0] =~ /×¢²á/o || $_[0] =~ /Õ÷ÎÄ/o || $_[0] =~ /Ê¥µ®¿ìÀÖ/o || $_[0] =~ /ӦƸ/o || $_[0] =~ /�ø�¨/o || $_[0] =~ /·¢»õ/o || $_[0] =~ /±±¾©/o || $_[0] =~ /×Ê��/o || $_[0] =~ /�Å�¢/o || $_[0] =~ /�ãɽ/o || $_[0] =~ /°Ù�ò/o || $_[0] =~ /Ãâ·Ñ/o }; my @logs = glob ~/logs/rcptstat/da2005_12_28/da.127.0.0.1.*; foreach my $log (@logs) { open (HD,$log) or die $!; while(HD){ print if $ref-($_); } close HD; } I run the 'time' command to get the running speed: time perl a.pl /dev/null real0m0.190s user0m0.181s sys 0m0.008s time perl b.pl /dev/null real0m0.286s user0m0.278s sys 0m0.007s Why the a.pl is faster than b.pl? I think ever the resulte should be opposite.Thanks. Well, the time differences aren't dramatic. But off hand, I would say that a.pl is faster because no subroutine call is involved. A couple of other observations: 1. /o is useless on these regexes, since they don't interpolate any variables. 2. $_ is the default target for the m// operator, so $_ =~ /regex/ can be replaced with simply /regex/ 3. It will probably be faster to use a single regex of the format: /pata|patb|patc|patd/ If the alternation can stay inside the regex code rather than happening out at the Perl opcode level, it might be faster. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reading the built-in number variables
[EMAIL PROTECTED] wrote: The issue: I have a routine which builds a regex and 'knows' which paren matches to use afterwords. For instance after a line such as: use strict; my $data =~ m/^(\S+)\s+((\S+\s+)?(\S+))$/; the routine 'knows' it wants $1 and $4. Another pass through the regex will be different and the variables might be $2 and $5 for that regex. The needed variable numbers are in an array: my @indexes; @indexes = (1, 4); for the first example above and: @indexes = (2, 5); for the second example above. The question: Is there a way to reference the built-in variables: $1, $2, ... in a programmatic manner? Something like: @values; push @values,${$_} foreach(@indexes); which didn't work for me, but you get the idea. That should work if @indexes contains numbers like @indexes = (1, 3); You'll also need to disable strict refs: no strict 'refs'; However, another approach would be to do your regex match in list context, and place the captured substrings into an array that you can index: my @fields = $data =~ m/^(\S+)\s+((\S+\s+)?(\S+))$/; @values = @[EMAIL PROTECTED]; Here the first match is at index 0 (i.e. $1 is @values[0]) Yes, I already thought of a subroutine with a big ifels ladder that hard codes a test for $1, $2, ... but there has to be a more eloquent solution than this. Thanks, Don -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Am a newbie ....
Brahadambal S wrote: Hi, Could anyone tell me how to execute a .bat or .exe file through Perl? i.e, the perl code should invoke the executable. Thanks so much for your help(in advance). Perl has two standard ways: 1) system() function, which executes an external program and returns its exit status. This is documented under perldoc -f system 2) backticks (e.g. $result = `someprog`), which executes an external program and captures its output. This is documented under perldoc perlop. A qx// is a synonym for backticks. Both of these wait for the spawned process to terminate before returning. If you want to execute the process asynchronously, the standard Unix approach is to use fork/exec or pipe open. I think these may be emulated on Windows by ActiveState's perl, and there's also a Win32::Process module that uses Windows API's for process spawning. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sort files by creation time
Randal L. Schwartz wrote: Jeff == Jeff Pang [EMAIL PROTECTED] writes: Jeff and we can use the _ handle to avoid stat'ing twice. Jeff Sorry,I don't know what is _ handle.Who help explain with it please,thanks. It's documented. I refuse to retype the docs for a thing. :) Specifically, see perldoc -f stat It's not always easy to figure out *where* something is documented :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sort files by creation time
Brian Volk wrote: Of course I have one more rookie question and a reference to a perldoc is just fine. :~) If I use the following code, why do I not need to declare the $a and the $b w/ my? Correct. This is explained in perldoc perlvar: $a $b Special package variables when using sort(), see sort in perlfunc. Because of this specialness $a and $b don't need to be declared (using use vars, or our()) even when using the strict 'vars' pragma. Don't lexicalize them with my $a or my $b if you want to be able to use them in the sort() com- parison block or function. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sort files by creation time
Brian Volk wrote: Hi All~ I'm using the glob function to grab all the files in a given directory and then using crontab to check it every 5 minutes. Once I have the files I'm using the diamond operator to read every line in every file and *do something* if the line matches. Here's my questions: Given directory: File 1 - in dir at 9:01 File 2 - in dir at 9:02 File 3 - in dir at 9:03 I would like to process the File 1 first then File 2 and then File 3. Each file contains data that I need to print for that order. If I can process the orders (File 1, File 2, File 3) according to the time they entered the given dir (first in/first out) the data will print off in the correct sequence. This will load @ARGV with the files in the current directory sorted oldest - newest: @ARGV = map $_-[0], sort { $b-[1] = $a-[1] } map [ $_, -M ], grep -f, # get only plain files *; How it works is left as an exercise for the reader :-) -- 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 running some scripts
Gomez, Juan wrote: Hi In VB is there a way to execute a perl script ? This isn't really a Perl question; you'll get a better response on a VB list. I think the function you want is called Shell(), but I'm not positive. (If your Perl script is a CGI script on a web server, then the correct question is How do I make an HTTP request from VB?, the answer to which I haven't the foggiest.) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to promote the efficiency
John W. Krahn wrote: if ( $2 128 ) { $low{ $1 }++; } else { $high{ $1 }++; } $total{ $1 }++; Why track all three? You could just track (say) low and total, and derive high as (total - low) at print time. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: chop/chomp/?
Frank Bax wrote: What's the correct way to trim trailing newlines from a text file that might be either DOS or UNIX format for newlines? The docs (and my experience) is that chomp only works properly if the text file is native to the current operating system? I'm running on *bsd system. This will strip trailing CRLF or LF: $line =~ s/\r?\n$//; I dunno what binmode has to do with anything here. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Parameterizing a module
[EMAIL PROTECTED] wrote: I see. Thanks Shawn. Since we are at it, would you mind explaining a little bit about the significance of our keyword. I have never understood it properly. Most books that I referred to say that it's a lexically-scoped global variable. What does that mean? I understand global variables to be the ones which are accessible to all perl program units (modules, packages or scripts). But then, what is so lexically-scoped about it? our is a declarative statement. It works like this: use strict; package Foo; $bar = Hello; Running perl -c on above gives the following error: Global symbol $bar requires explicit package name This error is only raised if use strict is in effect (which it always should be!) $bar is a global variable in the package Foo, so it's fully qualified name is $Foo::bar, so let's fix the program: use strict; package Foo; $Foo::bar = Hello; Ok, now this compiles without error. Now add this: use strict; package Foo; $Foo::bar = Hello; our $bar; print $bar;== prints Hello All the our statement does is to tell Perl that from this point forward, I want to be able to refer to the global variable $Foo::bar by the short name $bar. That's it. The declaration is lexically-scoped, which means you can refer to $Foo::bar as simply $bar at any point between the our statment and the end of the innermost enclosing block, file, or eval. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how to sleep 100 miliseconds?
TOKO wrote: hi. I'm new at perl and am looking for solution of let script sleep for few miliseconds. I tried sleep(0.1); but it does not work :) as I thought. Easist way IMO is to use Time::HiRes: use Time::HiRes qw(sleep); sleep(0.1); than I found this solution: select undef, undef, undef, .01; but it freezes script and it does not continue. Strange, that should work. What platform are you on? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: which is more effective between map and foreach?
Jennifer Garner wrote: Hi,lists, I have a small script,when it run,it generate much more lines and put them into a file. The code for printing I writed: map { print RESULT $_,:,$ips{$_},\n } sort { $ips{$b} = $ips{$a} } keys %ips; I would write it like this: print RESULT $_:$ips{$_}\n for sort { $ips{b} = $ips{$a} } keys %ips; Certainly, I can write that code with foreach style. I want to know which method is more effective between foreach and map? I don't know without benchmarking, but map() is typically used to build a resulting -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: number of spaces in a given sentence using regular expression.
[EMAIL PROTECTED] wrote: ... please give me the answers of these questions. Chris Devers will be along shortly... :~) -- 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 + OpenSSL
[EMAIL PROTECTED] wrote: Can anyone shed some light on why this doesn't work? $certificate = /some/where/file.pem; $encoded = ' . sha1($_) . '; $signed = system(`openssl rsautl -certin $certificate -encrypt -in $encoded`); $signed doesn't end up as a certificate signed value, it ends up as this number 65280. See: perldoc -q Why can't I get the output of a command with system()? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Find Error Message
[EMAIL PROTECTED] wrote: I am getting an error message - Can't stat c:*.*: No such file or directory find(\BadNames,c:\\*.*); What should the find statement look like? The argument should be a directory name (or multiple directories), not a glob pattern. So use C:\\, or c:/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: New on Mail::Send
ZHAO, BING wrote: I don't care how the perl is developing and where perl is going. I am doing stuff way fancier than what you can imagine. I am current doing a project with web input and data anaylysis and email feedback. You're right, that's *way* fancier than I can imagine! I'll not trifle with you futher. Best wishes. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Hi All
Shawn Corey wrote: ...searching perldoc really, really sucks. The only search available is `perldoc -q keyword` and it only searches the FAQs and then, only their questions. That's right, only the questions; the answers are skipped! Here's a 3-line shell script I use to grep through the core documentation. #!/bin/sh poddir=$(dirname $(perldoc -l perl)) grep -r $@ $poddir/*.pod Example (on FreeBSD 5.4): $ podgrep -iwl gethostbyname /usr/local/lib/perl5/5.8.7/pod/perlfaq9.pod /usr/local/lib/perl5/5.8.7/pod/perlfunc.pod /usr/local/lib/perl5/5.8.7/pod/perlipc.pod /usr/local/lib/perl5/5.8.7/pod/perlos390.pod /usr/local/lib/perl5/5.8.7/pod/perlport.pod /usr/local/lib/perl5/5.8.7/pod/perltoc.pod /usr/local/lib/perl5/5.8.7/pod/perltoot.pod /usr/local/lib/perl5/5.8.7/pod/perlvms.pod But I agree that a Google search like gethostbyname site:perldoc.perl.org is superior. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to do dos2unix for entire directory
Santosh Reddy wrote: I want to convert all the files which are in dos format to UNIX format. perl -pi -e 's/\cM$//' * -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: follow-up questions on Mail::Send
ZHAO, BING wrote: But for Mail::Send, I downloaded this huge file MailTools-1.67. I dug several modules out like Send.pm, Mailer.pm etc and saved them in the current directory. Well, that's not how you install modules. Read the README inside the MailTools tarball. And read perldoc perlmodinstall. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: follow-up questions on Mail::Send
ZHAO, BING wrote: Oh, I indeed did what you'll just told me to do: 1. I first downloaded this MailTools-1.67.tar.gz 2. ungziped it 3. cd MailTools-1.67 4. Moreed Readme, followed the instructions, until the last step, make install failed, still lots of files including a lib/ were generated. Are you on Unix? I'm assuming you are. You need to run make install as root. If you don't have root access, you need to read the following: perldoc -q 'How do I keep my own module/library directory?' I am just perl beginner and doing bioperl most of time and it would cost me 6 months at least to read the Camel book. Then I would understand what the modules really are saying. I don't believe anyone cares how the modules are coded, just trying to get them to work in your script. That's exactly what I am doing. And no, it didn't work. help me and tell me what I did was wrong. Tell you the truth, I don't understand how the Mail::Send is coded, nor I believe many of people in this list do, nor anyone in this list cares how Mail::Send is coded. What you're doing wrong is failing to learn how to properly install modules. You'll save yourself a lot of headaches if you get this process down pat. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: refs and variables
The Ghost wrote: my %hash = ( foo = 'bar' ); my $name='hash'; my $key='foo'; print $name{$key}; how can I get that to print bar? You can't, given the way you've set up %hash and $name. You're trying to take a soft reference to a lexical variable, which won't work. (well, you could so something extremely cheesy like: print key=, eval \$$name\{$key}; but yecch, don't to that) You can do this: use strict; my %hash = ( foo = 'bar' ); my $name = \%hash; my $key = 'foo'; print $name-{$key}; Or you could do this (but don't!): use strict; our %hash = ( foo = 'bar' ); my $name = 'hash'; my $key = 'foo'; no strict 'refs'; print $name-{$key}; Usually, if you're trying to use a string (perhaps coming from the outside world) as a symbol name, you're better off using a hash instead: my %data = ( 'hash1' = { foo = 'bar' }, 'hash2' = { foo = 'qux' }, ); for my $name (qw(hash1 hash2)) { print $data{$name}{foo}; } If the string isn't coming from the outside world and you just need a reference, use a proper reference (\%hash) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What is shift ?
Dylan Stamat wrote: No, not the routine that deals with Arrays ! I see code like the following, everywhere: my $coolvariable = shift; Why is a new scalar being assigned to shift ? New to Perl... sorry for the lame question, but couldn't find an answer anywhere. shift is a built-in function. It's documented under perldoc -f shift It removes and returns the first element from an array. When called (as in this case) without an explicit array, it defaults to either @ARGV (if called outside of any sub), or @_ (if called within a sub). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Is it possible with RegEx
Gilles wrote: Hi, I try do to a simple thing : Knowing If a string like 13 exist in a string like 123 Or if 37 exist in 12356789 I tried many solutions, but never found one good so I try to do it with loops which more difficult but not impossible I'd like to know if with RegExp it's more simply If you just want to see if the string 13 is found within the string 123, you can use the index() function: $found = index('123', '13') = 0; == false or a simple regex: $found = '123' =~ /13/; == false If you want to know whether '123' contains both a '1' and a '3', you can do something like this: $found = !grep $_ 0, map index('123', $_), split '', '13'; == true -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Connecting to a database using perl
Manish Uskaikar wrote: Hi, I am a real newbie to databases and perl can anyone of you help me with the packages i need to install and the sequences of functions i need to make to connect to a database and fire queries. DBI is the recommended approach for accessing SQL databases. You need the DBI module itself, plus a driver module (starts with DBD::) for the specific database you want to access. See http://dbi.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Error in module?
Octavian Rasnita wrote: Hi, I have tried the following test program: use Finance::QuoteHist; $q = Finance::QuoteHist-new ( symbols= [qw(IBM)], start_date = '01/01/1999', end_date = 'today', ); __END__ The program prints the following error: ERROR: Date::Manip unable to determine TimeZone. Read the docs for Date::Manip. It explains how Date::Manip determines the time zone. You can fix this in a variety of ways (e.g. set a TZ environment variable). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Storing a long value in an int [correction]
radhika wrote: Hi, I need to set this flag = 0x001 My code is as follows: $flag = OBJ::HALT(0x001); print(setting flag $flag\n); produces: 65536 But when I say $quote-SetFlag($flag); The flag is being set to 0; Is that a method call? $quote-SetFlag($flag) I don't know what SetFlag() is or what it's doing (or what OBJ::HALT is for that matter), so you need to provide some more information. SetFlag() could be doing anything with $flag. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Getopt::Long
Chris Knipe wrote: Hi all, Just a quick question and a couple of lines of really simple code use Getopt::Long; ... GetOptions ('h' = \$h, 'b=s' = \$s ); Sub ShowHelp() { That should be sub ShowHelp { Perl isn't VB :) print this is help } Sub DoSomethingWithString() { ... } If ($s) { DoSomethingWithString(); } else { ShowHelp(); } Right. Now, whilst the above is not perhaps 100% correct, it goes about a generality of Getopt::Long. If I now run the application, ./blah.pl -h - I get the help screen ./blah.pl -s - I get a error, complaining that -s requires a value, and THEN the help screen. ./blah.pl -s s - Everything is fine. So, this is more of a block question I think, but how I can get the above example to show the help screen FIRST, and THEN complain about the missing value for -s Well, this is a little tricky, because the complaint is issued by the GetOptions() call. I would usually do something like: # just show the complaint GetOptions(...blah...) or exit 1; or # show the complaint, then the help GetOptions(...blah...) or ShowHelp(), exit 1; In order to show the help before the complaint, you need to capture the complaint with $SIG{__WARN__} something like this: my $msg = ''; do { local $SIG{__WARN__} = sub { $msg .= shift }; GetOptions('h' = \$h, 'b=s' = \$s ); } or ShowHelp(), die $msg; I would suggest sending the help text to STDERR, or unbuffering STDOUT so that you are sure to get the help text shown before the complaint. Also, you might look at Pod::Usage for an approach to handling the help text. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: processing at preset times
Frank Bax wrote: I have script that takes a very long time to run - hours, sometimes even days (even on a P2-2.8Ghz machine. After loading some data from a database at the beginning (less than a second), the script does no i/o until results are output at the end of script. I'd like to know how the script is progressing through its data, so I added some code to update the database at regular data intervals, but this has some problems: - database is remote, so script goes much slower with these status updates. - updates are based on data instead of clock. I read something about threads in perl and was wondering if these status updates should be coded inside a thread so they have less impact on overall script performance. The number crunching could still go on while database update happens in separate thread. Well, threads don't magically turn one CPU into two. However, this particular case sounds like a good application for threads. Your main crunching thread can be running along while the database updating thread is blocked waiting for the database to respond. To get updates based on clock instead of data... Are there tools within perl for using clock/timer information? Do I have to parse clock/timer info myself to make something happen every hour inside an existing loop? You can just use the simple built-in time() function, which returns seconds since the epoch. If you want to update the database once per hour, you could do something like this: my $t = time; while (1) { do_database_update(); $secs = time - ($t + 3600); # start of next update sleep $secs if $secs 0; } The tricky part is sharing data between the threads, which is extremely sucky in Perl's ithreads implementation, IMO. Read perlthrtut for an overview of the issues. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: PS what is the correct/efficient function to create a file
ZHAO, BING wrote: Hi, unlink $file works fine, but link $file doesn't even exist, link() does exist, but it corresponds to link(2) syscall. perldoc -f link The sysopen function seems to be tedious, does anyone know how to effectively create a file in some directory in perl? This should work, and is not terribly tedious: open(undef, '/tmp/foo') or die $!; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Regex
[EMAIL PROTECTED] wrote: I have a field that looks like this: 'modprobe: modprobe: Can't locate module char-major-10-134' I need to add a single quote so that it looks like this: 'modprobe: modprobe: Can''t locate module char-major-10-134' But I have no idea how to go about doing that, can I get an example? If you don't want to include the quotes at the start and end of the string, you can use: s/(?=.)'(?=.)/''/gs -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XML Help
Scott Taylor wrote: Hi All, I'm using XML::Simple to parse a very simple XML file and dump the data into hashes of hashes. The problem I'm getting, is sometimes information is blank in the XMl file; it looks like this: STREETNUM/ instead of STREETNUM1234/STREETNUM and when I print the hash: print $x-{VEHICLE}-{STREETNUM} ; it returns: HASH(blahblah); How do I test for this so it prints blank? I've tried many things, the most logical I could think of was: if ($x-{VEHICLE}-{STREETNUM}){ print ... } else { print ; } Two ways to do this: 1) use SuppressEmpty option. This will simply exclude the STREETNUM element if it is empty (no attributes and no content) 2) use ForceContent option. This will treat the STREETNUM element as a hash even if it is empty or contains only text. In this case you would use $x-{VEHICLE}{STREETNUM}{content} in your code. #2 would probably be safer, because it would handle attributes to STREETNUM elements properly. You can read more about these options in the XML::Simple documentation. HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XML Help
Scott Taylor wrote: Dermot Paikkos said: I would also say that the source file is wrong, it should read STREETNUM/STREETNUM I read somewhere that blah / is correct syntax (same as blah/blah) You are correct. The two forms are exactly equivalent. see: http://www.w3.org/TR/REC-xml/#sec-starttags -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: quickly snag all numbers
Bryan R Harris wrote: I'd like to snag all the whitespace padded numbers in $_ into an array, e.g. in the following: 1 M_fx,-3,+2.p2 -31.4e-1 4. I'd like to pick up only the 1, -31.4e-1, and 4. I've tried: $ss = qr/(^|\s)[+-]?[0-9]+\.?[0-9]*([eE][+-]?[0-9]+\.?[0-9]*)?($|\s)/; @list = m/$ss/g; ... but it slurps up the leading whitespace if it's there, and misses every other number, amid other problems. I'd love to use \b, but it doesn't work if there are - or + at the leading edge. Any good ideas on how to do this? This should work: /(?:^|\s)((?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?)/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: quickly snag all numbers
Bryan R Harris wrote: Bryan R Harris wrote: I'd like to snag all the whitespace padded numbers in $_ into an array, e.g. in the following: 1 M_fx,-3,+2.p2 -31.4e-1 4. I'd like to pick up only the 1, -31.4e-1, and 4. I've tried: $ss = qr/(^|\s)[+-]?[0-9]+\.?[0-9]*([eE][+-]?[0-9]+\.?[0-9]*)?($|\s)/; @list = m/$ss/g; ... but it slurps up the leading whitespace if it's there, and misses every other number, amid other problems. I'd love to use \b, but it doesn't work if there are - or + at the leading edge. Any good ideas on how to do this? This should work: /(?:^|\s)((?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?)/ This is the right direction, but it grabs numbers that look like this: Well, it grabs the . Is it possible to keep from grabbing those? Add a look-ahead assertion like this at the very end of the regex: (?=\s|$) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to detect if the other end of the TCP connection has gone offline
Karjala wrote: I'm writing a simple client-server application, and I'm trying to find a way to tell if the other end of an open TCP connection has gone offline. If the other side has closed its end of the connection, you detect this by reading from the socket and receiving EOF (0 bytes read), or writing to the socket and getting SIGPIPE. If the other side has crashed (not just process terminated, but server itself has crashed), or the network has gone down between the two, you either need to use some kind of timeout (based on what a reasonable response time would be), or use the SO_KEEPALIVE socket option. With the latter, the kernel will probe the remote side after some period of inactivity and shutdown the connection if the other side doesn't respond. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: send email with Perl
Charles Li wrote: Hi, I am using use Net::SMTP; to send email to multiple people. But the recipients can not send the other receiver emails. It just says undisclosed recipients. How do I send email to multiple people and let them see who is on the To list? Include a To: header in the mail 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: running interactively
Adriano Allora wrote: ha to all, Ha back! I need to use a a shell-program but I cannot pass all the arguments to this program via system() function. In other words: the program doesn't accept all the arguments via command line: I need to open it and write interactively some instructions. If you just need to feed input via stdin, you can to a pipe open: open F, |/path/to/some_program or die $!; print F command\n; ... close F or die $!; If the program expects to work with a terminal (tty), you can use the Expect module to set up a pseudo-tty (pty) and interact with the program that way. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: XML [AntiVir checked]
Naji, Khalid wrote: Hi, Which Module could you recommend for the use of the XML (XML::Simple, XML::Parser and XML::Writer, XML::DOM, XML::PATH...) ? To add to what Wiggins said, I would also take a look at the XML::LibXML family of modules, and look at SAX parsing. These are newer than some of the modules you listed. Also, be sure to go to http://perl-xml.sourceforge.net/ and read the FAQ there. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: keeping track of the 'age' of a file
ZHAO, BING wrote: But, I figured it might be a good idea to save the file for like a week then delete it, if I know some kind of function like clock(as wild as it can get..), date etc, so after a week or so, the perl script would delete the file. The classic way to do this kind of thing is to run find(1) from cron periodically: 0 2 * * * find /some/path -type f -mtime +7 -exec rm -f {} \; If you want to do this from Perl, you either need to use cron, or write a long-running daemon-type process. cron is the best way to do it. The easiest way to check the age of a file is with Perl's -M operator: unlink $somefile if -M $somefile 7; ## file is older than 7 days You can also use the find2perl utility (part of File::Find module) to convert the find command above into Perl code. Or, you can use Randal's nifty File::Finder module (http://search.cpan.org/~merlyn/File-Finder-0.53/) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: compare two files
Jeff Pan wrote: hi, Is there a best way to find some lines which exists in both two files? I usually use the Unix comm(1) utility. Its very efficient, but the input files need to be sorted. Google for ppt comm and you can find a Perl version. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Using the module HTTP::Request
Ranish wrote: But the output of the code is perl aprequest.pl HTTP::Response=HASH(0x81e8a84) How can I make this human readable. print $response-as_string; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: general retry function
Chris Devers wrote: while ( $tries 10 ) { my $result = do_something_risky(); break if ( $result != 0 ); last, not break -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Forcing a save as' dialogue box to come up on left click
Tony Frasketi wrote: Hello Listers I'm trying to find a way to force a download dialogue box to come up when the user clicks on a link on a web page (the link will primarily be for htm, .txt files on the server). Short answer is that you cannot *force* the client to do anything. The HTTP standard addresses this in sec. 19.5.1 of RFC 2616, so you should read that over. Unfortunately, not all clients follow the standard here. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: cookies as hidden files
Denzil Kruse wrote: Well, this is what I witnessed. I'm using a windows computer at home. It is configured to display hidden files. I have a red hat linux server off who knows where that hosts my site. I set up a perl script to set and fetch cookies, and it does so correctly on my computer. But, I went over to a friend's windows computer, and when it tried to bring up the site, the browser(IE) hung. Part of the web site is a flash presentation with music, but the flash was hanging as well, and there was no music. Whatever problem this is, it isn't a Perl problem. Your CGI script neither reads nor writes files on the client PC; the browser handles all that. Sounds like your friend's browser is broken? Or perhaps he has cookies disabled, in which case any cookies sent by your script are simply discarded and you won't see them come back. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another package problem
Luinrandir wrote: ### Inn.pl # ## package Inn; Buy {} Sell {} Talk {} Sleep {} Delivery {} Work { # GameTime(.1); # SendOff(); print qq|Well afraid I do all my own work Try another business|; } ... Did you forget sub keywords on each of these? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problem with package
Luinrandir wrote: package Inn; BEGIN {} END {} return 1; An error comes up when I include the END{} but not the BEGIN{} any clues? Er, WTF are you trying to do? What is the error? You can't use return outside of a sub. The normal idiom is a bare 1 to provide a true result for require(). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why is my package executing everything!
Luinrandir wrote: My package is executing ALL subroutines when required? why? Since you don't show us your code, how on earth are we supposed to guess? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Question about data storage
Peter Rabbitson wrote: * I store dirty orders as XML in a SQL table with 2 columns - one for the order id and another for the arbitrary XML structure. Problem once again is that my XML can be thousands of characters long. I vote for this option. You can use a TEXT or MEDIUMTEXT column to store this data (Unicode, UTF-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: Problem with package
Bob Showalter wrote: You can't use return outside of a sub. The normal idiom is a bare 1 to provide a true result for require(). I'm wrong. You _can_ return from a do FILE construct. So there shouldn't be an error. (suggest you remove the return anyway; it isn't normally used in that situation.) -- 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 DBI / SQL Question
Vance M. Allen wrote: I need to know how to retrieve through Perl DBI a listing of possible ENUM elements from a field for processing under a CGI script. Need to know what database you're talking about. This will probably involve querying data dictionary views or tables. Some DBI drivers also have specific methods for this kind of thing. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Why wont this work? Package require question
Jeff 'japhy' Pinyan wrote: Now you want to call the Inn::HTML() function, right? You can't easily do it if strict is turned on. Here's one way, though: my $glob = $main::{$Player{Location} . ::}{HTML}; $glob-(); Or just turn off strict for a sec: { no strict 'refs'; {$Player{Location}::HTML}() } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: @ARGV
Christopher Spears wrote: From what I understand, @ARGV contains invocation arguments. Then how come I cannot access the first element with $ARGV[0]? What would be the proper way to do this? Well, you can access the first element as $ARGV[0], so something else is going on. Show us your code. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Algorithm Help Needed
Guys, I need help with an algorithm. I'm writing a program that sends a repeated pattern of requests to a service. Each request has a weight that controls the relative frequency with which I need to send that particular request. So given: foo = 1 bar = 3 I would send four requests, one of which is a 'foo', and the other three are 'bar'. So my requests would look like: foo, bar, bar, bar, foo, bar, bar, bar, ... If I have a case like: foo = 1 bar = 1 qux = 6 I can easily send one foo, followed by a bar, followed by 6 qux: foo bar qux qux qux qux qux qux However, what I need to do is to distribute the requests so that the intervals between instances of a given request are distributed as equally as possible. For example: foo qux qux qux bar qux qux qux Now I have only intervals of 0 or 1 between successive qux, instead of an interval of 2 as in the previous case. As an extreme example, if I had a dozen requests with a weight of 1 and a final request with a weight of 12, I would starve the highly-weighted request until the first 12 had been sent. How can I generalize this for any given set of requests and weights? Is anyone aware of any general literature on this kind of problem? (Sounds like a scheduling algorithm maybe?) Thanks, Bob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Algorithm Help Needed
Jeff 'japhy' Pinyan wrote: The extreme cases are the easy ones, though. What I'd like to see are cases like: foo = 1 bar = 2 qux = 3 baz = 4 zip = 5 Once I know what the algorithm's outcome should be for something like that, I think I can develop it. Here's what I've come up with so far, which is extremely simple and seems to work reasonably well: 1. Compute total weight as sum of individual weights 2. For each item in the list compute an interval as (total weight) / (individual weight) 3. Write an entry for weight times, adding interval each time So, for the example above, total weight is 15. Start with foo: interval = 15 / 1 = 15. We need 1 foo, so: foo 15 bar: interval = 15 / 2 = 7.5. We need 2 bar's, so: bar 7.5 bar 15 qux: interval = 15 / 3 = 5. Need 3 qux, so: qux 5 qux 10 qux 15 Final list is: foo 15 bar 7.5 bar 15 qux 5 qux 10 qux 15 baz 3.75 baz 7.5 baz 11.25 baz 15 zip 3 zip 6 zip 9 zip 12 zip 15 Now sort the list by column 2, then by column 1: zip 3 baz 3.75 qux 5 zip 6 bar 7.5 baz 7.5 zip 9 qux 10 baz 11.25 zip 12 bar 15 baz 15 foo 15 qux 15 zip 15 Column 1 becomes the round-robin sequence, with the right number of each request, and farily evenly distributed. The sequence starts and ends with a zip, so I have between 0 and 4 non-zip entries between pairs of zip's. 6 of every 15 requests should be a zip, so there should be an average of 1.5 non-zip's between zip's. Maybe I should could tweak my algorithm to better smooth the distribution of zip's. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sendmail, etc.
Matthew Sacks wrote: Greetings, I want to send mail from my perl code. (Boy, that's really unusual) I am thinking using mail::mailer. I need a bit more info than what I have so far found in the online documentation (perldoc -q mail). Where I can I find some advice? E.G., there is always an example of code that defines a $to argument. but can $to be a list of addresses? (a group, that is). Can $to be a list of 100 email addresses? I usually use Mail::Send, which is a friendlier wrapper around Mail::Mailer (both are part of MailTools distribution). For Mail::Mailer, $to can be either a single address in a scalar, or a reference to an array of addresses: To = '[EMAIL PROTECTED]'; To = [ '[EMAIL PROTECTED]', '[EMAIL PROTECTED]' ]; To = [EMAIL PROTECTED]; For Mail::Send, you can pass a list to the 'to' method: $msg-to(@addrlist); Do I have to think about tuning my sendmail daemon? Not for Perl's sake. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CHILD_ERROR and forking within a child
steve abrams wrote: * code 'paraphrased' for simplicity * Hi all, I have a script which goes to a subroutine. Within the subroutine, there exists: $pid = fork; push(@pids, $pid); unless ($pid) { my $var = new Object; if (not $var-method_that_evokes_a_child()) {Exit;} exit 2; } where the Exit subroutine exits with a number other than 2. The parent process (before this subroutine is called), does a $foo = waitpid $pids[$count], WNOHANG; and handles each child's return value. The problem I am having: CHILD_ERROR (or $?) on the outside of the subroutine is using the value from the child-evoking-method, ignoring the exit code I am giving. For example, if method_that_evokes_a_child exits with '1', the main parent gets '1' from its child, rather than '2' (the argument passed to 'exit()') if method was successful. So, perhaps I'm confused with how the final exit of a child behaves with regard to $?. If I don't call the child-evoking method, the original parent gets the exit code of the child. I want this to be the case even when I call the child-evoking method. Why does it not do this, and how can I 'fix' it? If anyone understands what I'm trying to explain, any help would be appreciated. Thanks! I for one can't understand what you're trying to explain. Can you code up a simple self-contained example that illustrates the problem (i.e. something we can run)? I'm not clear on what you mean by main parent and child-evoking method, etc. I will say that wait(2) only applies to immediate descendants, not grandchildren, if that's what you're doing... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: :Oracle installation script assumes oracle is installed local ly?
[EMAIL PROTECTED] wrote: Hi all. I am attempting to install DBD::Oracle from the perl CPAN shell. The installation script seems to assume that oracle is installed locally. It asks me to set ORACLE_HOME to the path the oracle is installed and to try again. Well I don't have oracle installed locally. I want to install DBD::Oracle so I can connect to a remote oracle server. Any ideas? Oracle server doesn't need to be installed, but the client libraries do. You need to install those. If you're on a platform that you cannot or do not want to install the Oracle client software on, you can install DBD::Oracle on the server and use DBD::Proxy on the client. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: can any body tell me how to remove quotes from a name.
[EMAIL PROTECTED] wrote: Could any body tell me how to get mayank from 'mayank' $var =~ tr/'//d; sp. by map or grep command Those functions are not appropriate to the problem as you've described it -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Force a file download for link
Denzil Kruse wrote: Hi, I want my users to download a csv file. When they left click on the link, it brings the file up within the browswer. They can of course do a right click and Save Target As depending on the browser. But I don't want to fuss with instructions and confused users. I would just like the same thing to happen as a Save Target As on a left click. Very difficult to force the browser to do anything. The best you can do is suggest. The most foolproof way is to use Content-Type: application/octet-stream (cf RFC 2616, sec. 7.2.1). But that seems distasteful to me. Why lie about the content type just because users are morons? Anyway... Content-disposition is not part of the HTTP standard, so you'll get inconsistent results. Also, IE can think it's smarter than you are and inspect the URL for file extensions instead of respecting your Content-Type header. Ain't life fun? So I made something up, but it isn't working. I get an internal server error from the browser. When I run it at a command prompt, it seems to work fine. Here is the code: print content-type: multipart/mixed\n; print content-disposition: attachment; filename=SampleListingUpload.csv\n; open (FILE, $ABS_PATH/httpdocs/SampleListingUpload.csv) or die Unable to load the sample listing template. Reason: $!; my $text = join , FILE; close FILE; print $text; And here is the output from a prompt: -bash-2.05b$ ./sample_listing.cgi content-type: multipart/mixed content-disposition: attachment; filename=SampleListingUpload.csv Keywords,Bid Amount,Title,Url,Description home mortgage,0.10,ABC Home Mortage,http://www.ABCHomeMortgage.com,Instant Quotes tax attorney,0.75,ACME Tax Attorneys,http://www.acmetaxattorneys.com,Let us represent you -bash-2.05b$ multipart/mixed is incorrect. text/csv is the proper MIME type for your response. Also, your MIME header lines techincally need to end with \r\n, and you must have emit blank line after the header. This is why we always recommend using the CGI module. It gets this stuff right. use CGI qw(:standard); open FILE, ...blah blah... print header('application/octet-stream'); print while FILE; -- 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 (cd ..)
Eliyah Kilada wrote: Hi, It seems that the following code gives unexpected results: system (cd $dir_name); system (pwd); --- this prints the old directory name not the new one. In other words, the previous (cd) command hasn't taken its effect! Do anyone know why? Each call to system() creates a separate process in which the command is executed. The cd command only affects that separate process. You need to use Perl's chdir() function to change the working directory for the current process. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: How check DBI version on the server?
Maxipoint Rep Office wrote: How check DBI version on the server? perl -MDBI -le 'print $DBI::VERSION' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: open and edit file to prevent race conditions
Brent Clark wrote: Hi List I have a scenario / debate if you wish with my colleague. The problem is I have to update a CSV file and the way I do it open the file while reading / editting it I then send it to a temp file, unlink the original and the rename the temp to the original file name (Baring in mind I do flock the file) My colleague, disagrees with my approach to this, he is adamant that I must open the file get the file in memory and use seek etc to update the file (also using flock etc.) So basically from the millisecond it takes to unlock , close, unlink, and then rename the file, I am open to race condition. So my question is, whats the best what to update / amend a file. He's right; there is a race condition. But worse than that, if an other process is continuously writing to the file, your unlink and rename operation will cause the data from the other process to be lost. Instead of unlinking and renaming, you could just copy the data from the temp file back into the original file. Or, use Tie::File and update the file in place. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: encrypt the password stored in a file
Ken Perl wrote: The password used to access a ftp server is stored in a text file, the perl program gets the password from the file, the pass it to the ftp server for logon, this is the background. The requirement is encrypt the password store in a more secure way, and the perl program could still use the encrypted password to logon the server. what algorithm should be used in this task? Why are you storing the password? Prompt for it when the program runs. Encrypting it will be pointless. You'll either have to a) store the encryption key somewhere, thus leaving you with the same problem, or b) prompt for it when the program runs, in which case you could just prompt for the FTP password. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Daniel Kurtz wrote: Ooh ooh ooh! One I know! open(COMMAND, dir |); @files = COMMAND; Please tell me you're kidding. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need a list of files in a dir.
Daniel Kurtz wrote: Bob Showalter wrote: Please tell me you're kidding. Why? It works. The question asked how you can do it, not the BEST way to do it. And after a week of Perling, this was the one way I knew. Now I know two ways. g OK, you weren't kidding. Since you're new to Perl, you get a free pass :~) Seriously, though, not all of us run Perl on Windows. Your approach is Windows-specific. In addition, the dir command outputs a bunch of other stuff besides the file name, so you'd have to do some parsing to get the file names. Either a glob approach or an opendir/readdir approach is simpler and more portable if one just needs a list of file names. If more details are needed, the stat() function (or related operators) can be applied to the resulting list. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: use Module VERSION; ignoring version???
JupiterHost.Net wrote: How come use MODULE VERSION; works sometimes and not others? In this case: $ perl -mstrict -we 'use CGI 3.12;print $CGI::VERSION\n;' CGI version 3.12 required--this is only version 3.11 at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl -mstrict -we 'use File::Copy::Recursive 0.15;print $File::Copy::Recursive::VERSION\n;' 0.14 $ Very odd... If you look here: http://search.cpan.org/src/DMUEY/File-Copy-Recursive-0.13/Recursive.pm You'll see that the author of this module has incorrectly implemented the VERSION method as: sub VERSION { $VERSION } From perldoc UNIVERSAL: VERSION ( [ REQUIRE ] ) VERSION will return the value of the variable $VERSION in the package the object is blessed into. If REQUIRE is given then it will do a comparison and die if the package version is not greater than or equal to REQUIRE. VERSION can be called as either a class (static) method, an object method or a function. You should notify the module author to fix this (by removing his method) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: IO::Socket squirreliness
Mason Loring Bliss wrote: On Tue, Aug 23, 2005 at 11:10:58AM -0400, Mason Loring Bliss wrote: Hi, all! I'm learning about dealing with sockets in Perl, and I've got a question about some unexpected behaviour exhibited by the following test script. In the case where I open a connection and then close it before $socket-accept() is called, I'd expect $socket-accept() to return undef, but it never does. Will someone kindly tell me why this is? Thanks in advance! Is there a forum other than this one where I might ask this question? I was hoping that maybe someone here knew the answer and would share it... Should $socket-accept() return undef if the client in question has died off before the server has gotten around to accepting() the connection? Maybe my assumption is faulty, and there's no implicit close happening when the initiating process dies. I'll explore this possibility. Hm. No. When the client calls shutdown(2) or close() before the server calls accept(), the server's $socket-accept still returns with a socket, and not undef. Am I missing something fundamental here? Is this a bug in IO::Socket? Is there some other issue of which I'm unaware? I don't think there's any problem with IO::Socket. Even if accept returns a socket, you should receive an EOF on that socket when you try to read from it, which tells you that the peer has closed the connection. I think you just need to check for both situations: an error from accept(), and EOF from read(). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: IO::Socket squirreliness
Bob Showalter wrote: I don't think there's any problem with IO::Socket. Even if accept returns a socket, you should receive an EOF on that socket when you try to read from it, which tells you that the peer has closed the connection. I think you just need to check for both situations: an error from accept(), and EOF from read(). Another way of looking at it is to suppose that the client connected, sent a small message, and then disconnected before you called accept(). The kernel could still maintain this data in its buffers, and you would obviously need accept to return the socket so you could read the data. A connect() followed by a close() is just another form of this scenario. You need to have a client socket in order to detect the peer's closing the connection. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Seeding variables from command line
[EMAIL PROTECTED] wrote: Sorry to bother everyone, but i was working on this yesterday and i couldn't get it to work. I guess i have the wrong syntax for passing variables in from the command line. Here's my script: = crypt.pl = #!/usr/bin/perl my $pwd = $1; my $seed = $2; my $key = substr(crypt($pwd,$seed),2); print $key; = For example, I want to type: crypt.pl string1 string2 and it should spit out the value of $key. Right now both variables are returning null. Any suggestions? You must be a shell programmer :~) The command-line arguments in Perl are in the global @ARGV array. You can access them directly, as in: my $pwd = $ARGV[0]; # first argument my $seed = $ARGV[1];# second argument Or, you can shift them off the array: my $pwd = shift @ARGV; my $seed = shift @ARGV; Since @ARGV is the default target for the shift() function when used outside a function, you can use the idiom: my $pwd = shift; my $seed = shift; Finally, you can assign them as a list: my ($pwd, $seed) = @ARGV; HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Is there any Makefile.pl example?
Yu Wang wrote: Hi, I have written a program using Gtk2 in Perl. It's the first time I write program in Perl, so I need some help in writting the Makefile.pl I have 1 file for main program, and 5 files for modules. Besides that, I also have document files and some data files to be accessed by the code. I have read a tutorial about Makefile.pl, but it only teaches me how to install modules in to perl module directories. It seems that I couldn't find a tutorial on how to write Makefile.pl to perl applications. I'm not sure about tutorials, but the documentation for ExtUtils::MakeMaker should be studied carefully. You can install scripts as well as modules; for scripts, set the EXE_FILES entry in your Makefile.PL. Here's an example of a program that uses this: http://svn.perl.org/viewcvs/qpsmtpd/trunk/Makefile.PL?rev=470 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: IF statements and modules - do they mix?
Charles K. Clarkson wrote: Dave Adams mailto:[EMAIL PROTECTED] wrote: Does perl allow you to conditionally include a module? In general, you can load a module at runtime by using 'require' and manually running its import() sub routine. require Module; Module::import( 'Import list' ); That should be Module-import(@list); Many (most?) modules do not implement an import() method, but simply rely on the default behavior from Exporter. Another option that can be used at runtime is: eval use Module(@list); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to use % in MySQL SQL statement from Perl?
Siegfried Heintze wrote: The following code works with perl/MySQL. If I comment the second line, however, it does not work. No error messages and no results. If I use the MySQL Enterprise console and type in my first SELECT statement that includes the LIKE clause, it works. I'm stumped. There must be something strange with that %, but I cannot figure it out. Anyone got any suggestions? Siegfried my $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName WHERE sName LIKE '%']; That should raise an error. WHERE clause needs to come befor ORDER BY clause. Unless you have RaiseError turned on, you aren't checking for errors below. $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName]; my $sth = DBH-prepare($sJobTitle); $sth-execute(); my $row; while ($row = $sth-fetch){ push @sResult,li.join( , @$row)./li\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: setting a user passwd
Victor Pezo wrote: Hi, I am developing a program that sets passwd for any user but i dont want the operator sets the passwd. I want to give it as a result of a function [EMAIL PROTECTED] victor]$ perl passwd.pl victor1 #!/usr/bin/perl $usuario=$ARGV[0]; $passwd=PASSWDGENERATEBYOTHERFUNCTION `sudo /usr/sbin/useradd -c $usuario -s /sbin/nologin $usuario`; `sudo /usr/bin/passwd $usuario`; I could add the user, but in the set passwd line. When I use this script always I have a prompt of password assigment that I dont want. Could you give me some light of what can I do? The classic answer to this is to use the Expect module, because passwd(1) historically has read only from /dev/tty. However, if you're on Linux, passwd(1) has a --stdin option that lets you supply the password via standard input. So you could write something like (untested): system echo \Q$passwd\E | sudo /usr/bin/passwd --stdin \Q$usario\E; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: to () or not to (), that is the question.
Brent Clark wrote: Hi list Would someone be so kind as to share some light on this for me. I have the following code: ($fileName) = ($_ =~ /regexcode/o); Which gives me the correct data. But if I make it like so (note the () missing around the variable): $fileName = ($_ =~ /regexcode/o); Whats the difference. The parens on the left side place the assignment operation in list context. This means the right-hand side (the regex match) will be evaulated in list context, which gives different results then when it's evaluated in scalar context (as in the second example). You can read the section on Context in perldoc perldata for more details. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Hash reference structure
Jan Eden wrote: Hi, I need to store a list of month names into a hash structure such that: $self-{monate}-{1}-{bezeichnung} = 'Januar' $self-{monate}-{2}-{bezeichnung} = 'Februar' etc. Until now, I have used the rather clumsy: @month_hash{1..12} = (Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember); for (sort keys %month_hash) { $self-{monate}-{$_}-{bezeichnung} = $month_hash{$_}; } You don't need to sort the keys, you don't need the arrows between adjacent braces, and you can use the 'for' modifier to make the statement a bit more readable: $self-{monate}{$_}{bezeichnung} = $month_hash{$_} for 1..12; The following did not work: @{$self-{monate}-{1 ..12}-{bezeichnung}} = (Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember); Is there a better way to do it? These references are making my brain swirl. If you want to avoid using %month_hash and want to use a list initializer, you could do something like: my $n = 0; $self-{monate}{++$n}{bezeichnung} = $_ for qw/ Januar Februar März April Mai Juni Juli August September Oktober November Dezember /; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Hash reference structure
Bob Showalter wrote: $self-{monate}{$_}{bezeichnung} = $month_hash{$_} for 1..12; That could also be 'for keys %month_hash' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: cool tricks for inserting element into array?
Bryan R Harris wrote: I'd like to turn array @tmp from: (1,2,3) to (1,|,2,|,3) I'm using: @tmp = split(' ', join( | , @tmp)); ... but it seems like a waste to create a string and then split it back up again. I'll bet that's pretty efficient. The problem would come if any of the original elements contained an embedded space. Here's a way, but I doubt it's very efficient: splice @tmp, $_, 0, '|' for reverse 1 .. @tmp-1; Another way: @tmp = map +($_, '|'), @tmp; pop @tmp; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Easy question
Neville Hodder wrote: The following code creates two Input types - a file select and a text input. The text input data is returned as expected whilst the file select data is ignored. I have not found any references for a CGI file select form tag in my documentation so I guess it is not a recognised tag. It is a recognised tag. See http://www.w3.org/TR/html4/interact/forms.html#file-select How can I achieve a returned selected filename within a simple CGI script? Your form encoding type must be multipart/form-data I recommend you use the CGI module. Look in the document under the section 'CREATING A FILE UPLOAD FIELD'. There are several things you need to do to get file uploading working. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response