How to browse and select a remote file and then return the filename
I am in the process of learning how to use the CGI.pm module but can not find a method that will allow me to simply choose a 'remote' file. I need to be able to return the value path+filename of a file that the user has browsed to using something like the standard HTML form type: PINPUT type=file value=filename/P I do NOT want to upload a file using $query-filefield, instead I want the user to be able to select a file using the standard browse dialogue and then the CGI script return that selected filename for further use. Thanks Nev
Re: How to browse and select a remote file and then return the filename
On Thu, Jul 07, 2005 at 03:00:02PM +0100, Neville Hodder wrote: I am in the process of learning how to use the CGI.pm module but can not find a method that will allow me to simply choose a 'remote' file. I need to be able to return the value path+filename of a file that the user has browsed to using something like the standard HTML form type: It isn't possible. For that sort of thing you'll need something like an ActiveX control with permission to read the user's file system. (Or to get the user to type the path to the file). Since the server doesn't have permission to access the user's file system over the Internet, and since that file system might be UNIX type, DOC type, or some other unknown type - it isn't a particularly useful feature to build into HTML. -- David Dorward http://dorward.me.uk -- 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 browse and select a remote file and then return the filename
On Thu, 7 Jul 2005, David Dorward wrote: On Thu, Jul 07, 2005 at 03:00:02PM +0100, Neville Hodder wrote: I am in the process of learning how to use the CGI.pm module but can not find a method that will allow me to simply choose a 'remote' file. I need to be able to return the value path+filename of a file that the user has browsed to using something like the standard HTML form type: It isn't possible. For that sort of thing you'll need something like an ActiveX control with permission to read the user's file system. (Or to get the user to type the path to the file). And that, in turn, can only be reliable with IE on Windows. It does nothing for the growing minority that uses alternative browsers (Firefox, Opera, Safari, etc) or operating systems (OSX, Linux, etc); I'm not aware of anyone getting ActiveX to work on anything other than the IE/Windows combination. Admittedly, that's something like 90% of web users, but Firefox, in particular, seems to be growing fast now. Out of curiosity, why do you need to do this? What problem are you trying to solve ? Could you get the result you need by some way other than figuring out remote file paths ? -- Chris Devers -- 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 browse and select a remote file and then return the filename
On Thu, Jul 07, 2005 at 11:42:29AM -0400, Chris Devers wrote: It isn't possible. For that sort of thing you'll need something like an ActiveX control with permission to read the user's file system. (Or to get the user to type the path to the file). And that, in turn, can only be reliable with IE on Windows. Well, that specific example anyway :) I suspect a signed Java applet could work on other systems. Its not reliable on IE anyway - its unlikely that all users would have their security low enough (and accept the alerts) for it to run. However, I have trouble conceiving of a circumstance where it would be useful to do this over the WWW, so its probably in an environment where user agents can be mandated. I'm not aware of anyone getting ActiveX to work on anything other than the IE/Windows combination. Admittedly, that's something like 90% of web users, but Firefox, in particular, seems to be growing fast now. I seem to recall somebody managing to run ActiveX and IE under WINE :) -- David Dorward http://dorward.me.uk -- 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 browse and select a remote file and then return the filename
Do you mean you just don't want the actual file uploaded...just the name of it? You can probably accomplish this by having the file form field in a separate form (that is not submitted). Then use javascript to populate the field in the form that actually does get submitted. -Original Message- From: Neville Hodder [mailto:[EMAIL PROTECTED] Sent: Thursday, July 07, 2005 9:00 AM To: beginners-cgi@perl.org Subject: How to browse and select a remote file and then return the filename I am in the process of learning how to use the CGI.pm module but can not find a method that will allow me to simply choose a 'remote' file. I need to be able to return the value path+filename of a file that the user has browsed to using something like the standard HTML form type: PINPUT type=file value=filename/P I do NOT want to upload a file using $query-filefield, instead I want the user to be able to select a file using the standard browse dialogue and then the CGI script return that selected filename for further use. Thanks Nev -Message Disclaimer- This e-mail message is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not the intended recipient, any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by reply email to [EMAIL PROTECTED] and delete or destroy all copies of the original message and attachments thereto. Email sent to or from the Principal Financial Group or any of its member companies may be retained as required by law or regulation. Nothing in this message is intended to constitute an Electronic signature for purposes of the Uniform Electronic Transactions Act (UETA) or the Electronic Signatures in Global and National Commerce Act (E-Sign) unless a specific statement to the contrary is included in this 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: How to browse and select a remote file and then return the filename
On Thu, 7 Jul 2005, David Dorward wrote: On Thu, Jul 07, 2005 at 11:42:29AM -0400, Chris Devers wrote: It isn't possible. For that sort of thing you'll need something like an ActiveX control with permission to read the user's file system. (Or to get the user to type the path to the file). And that, in turn, can only be reliable with IE on Windows. Well, that specific example anyway :) I suspect a signed Java applet could work on other systems. I thought Java applets were sandboxed, and that access to the filesystem was explicitly not allowed. Have things changed in the past few years? I thought the whole point of Java applets was that they were safe, in part, because they couldn't interact with the underlying filesystem. I seem to recall somebody managing to run ActiveX and IE under WINE :) That barely counts :-) -- Chris Devers -- 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 browse and select a remote file and then return the filename
On Jul 7, 2005, at 9:00 AM, Neville Hodder wrote: I am in the process of learning how to use the CGI.pm module but can not find a method that will allow me to simply choose a 'remote' file. I need to be able to return the value path+filename of a file that the user has browsed to using something like the standard HTML form type: PINPUT type=file value=filename/P I do NOT want to upload a file using $query-filefield, instead I want the user to be able to select a file using the standard browse dialogue and then the CGI script return that selected filename for further use. Thanks Nev You can use Firefox for the client... It will send the name and path of the file, but won't upload it ;) And, while not positive, I think you can do this with CGI.pm. Try setting the max upload to 1 or 2 k and see what happens. Use File::Basename to get the name and path of the remote file. Kindest Regards, -- Bill Stephenson 417-546-8390 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Yet another question on perl modules
Hello everyone, Most modules I run across have a BEGIN block containing some variable declarations, module loaders etc. Although I understand what BEGIN is (code being evaluated immediately after it is parsed), I miss the point of the excercise. For example: package csv_generator; use Text::CSV_XS; our $ERROR; sub new { my $class = shift; return (bless {}, $class); } sub add_line { my $self = shift; push @{$self-{pending}}, [EMAIL PROTECTED]; return 1; } sub wrap_csv { my $self = shift; my $csv = Text::CSV_XS-new; my @result; foreach my $line @{$self-{pending}} { $csv-combine (@{$line}); push @result, $csv-string(); } return (join (\n, @result)); } Where would BEGIN come to play? P.S. I know the above code is messy, without any error checking, and I might even have a typo somewhere. It is just for illustration purposes. -- 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 question on perl modules
On Thu, Jul 07, 2005 at 02:22:34AM -0400, Casey West wrote: This is a confusing question, but I think the answer is that a BEGIN block would come into play before any of these things are executed. -- Casey West Sorry :) Question is: why would I want to use a BEGIN block in the above script skeleton. What advantages would BEGIN give me that I can not have otherwise, and why most modules bear one (some more than one). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: FAQ
Thanks for the reply sir. But i am still stuck with the same old problem since the system() function isn't working the manpages aren't of much help either. Giving below an account of what my programs are their output: PERL PROGRAM #assign.pl# #!/usr/bin/perl use strict; use warnings; print enter the first number\n; my $x = STDIN; chomp $x; print enter the second number\n; my $y = STDIN; chomp $y; my $z = system(assign.f,'$x','$y'); print Output of the two numbers is:\n; print $z,\n; exit; #output# $perl assign.pl enter the first number 2 enter the second number 4 Can't exec assign.f: Permission denied at assign line 10, STDIN line 2. Output of the two numbers is: -1 #FORTRAN PROGRAM# c assign.f WRITE(*,*) ENTER FIRST NUMBER READ(*,*) x WRITE(*,*) ENTER SECOND NUMBER READ(*,*) y z = x+y WRITE(*,*)z END #output# $g77 assign.f $ ./a.out ENTER FIRST NUMBER 2 ENTER SECOND NUMBER 4 OUTPUT OF THE TWO NUMBERS IS: 6. Can you suggest sir what should be my approach to this problem. Waiting for an early response from you. Thanking you.. __ How much free photo storage do you get? Store your friends 'n family snaps for FREE with Yahoo! Photos http://in.photos.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: FAQ
Thanks for the reply sir. But i am still stuck with the same old problem since the system() function isn't working the manpages aren't of much help either. Giving below an account of what my programs are their output: PERL PROGRAM #assign.pl# #!/usr/bin/perl use strict; use warnings; print enter the first number\n; my $x = STDIN; chomp $x; print enter the second number\n; my $y = STDIN; chomp $y; my $z = system(assign.f,'$x','$y'); print Output of the two numbers is:\n; print $z,\n; exit; #output# $perl assign.pl enter the first number 2 enter the second number 4 Can't exec assign.f: Permission denied at assign line 10, STDIN line 2. Output of the two numbers is: -1 #FORTRAN PROGRAM# c assign.f WRITE(*,*) ENTER FIRST NUMBER READ(*,*) x WRITE(*,*) ENTER SECOND NUMBER READ(*,*) y z = x+y WRITE(*,*)z END #output# $g77 assign.f $ ./a.out ENTER FIRST NUMBER 2 ENTER SECOND NUMBER 4 OUTPUT OF THE TWO NUMBERS IS: 6. Can you suggest sir what should be my approach to this problem. Waiting for an early response from you. Thanking you.. ___ Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://in.mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: FAQ
Thanks for the reply sir. But i am still stuck with the same old problem since the system() function isn't working the manpages aren't of much help either. Giving below an account of what my programs are their output: PERL PROGRAM #assign.pl# #!/usr/bin/perl use strict; use warnings; print enter the first number\n; my $x = STDIN; chomp $x; print enter the second number\n; my $y = STDIN; chomp $y; my $z = system(assign.f,'$x','$y'); print Output of the two numbers is:\n; print $z,\n; exit; #output# $perl assign.pl enter the first number 2 enter the second number 4 Can't exec assign.f: Permission denied at assign line 10, STDIN line 2. Output of the two numbers is: -1 #FORTRAN PROGRAM# c assign.f WRITE(*,*) ENTER FIRST NUMBER READ(*,*) x WRITE(*,*) ENTER SECOND NUMBER READ(*,*) y z = x+y WRITE(*,*)z END #output# $g77 assign.f $ ./a.out ENTER FIRST NUMBER 2 ENTER SECOND NUMBER 4 OUTPUT OF THE TWO NUMBERS IS: 6. Can you suggest sir what should be my approach to this problem. Waiting for an early response from you. Thanking you.. __ How much free photo storage do you get? Store your friends 'n family snaps for FREE with Yahoo! Photos http://in.photos.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: FAQ
madhurima das [EMAIL PROTECTED] asked: Thanks for the reply sir. But i am still stuck with the same old problem since the system() function isn't working the manpages aren't of much help either. system() won't work the way you want to use it. From the manpage: The return value is the exit status of the program as returned by the wait call. Passing the arguments the way you do also doesn't work because your Fortran code expects to read them from standard input. This looks like a job for open2 or the expect module. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: FAQ
Can you try with backtick or qx[ ] ? my $z = `assign.f $x $y`; hth. Can't exec assign.f: Permission denied at assign line 10, STDIN line 2. Output of the two numbers is: -1 --Muthu -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Query on File::Find
Shobha Deepthi am Donnerstag, 7. Juli 2005 06.19: Hi, Hi probably not the best answer, but nobody else answered: Am using find method in File::Find module. Right now this method is being used as follows: find({wanted = \find_and_instantiate_commav_file, no_chdir = 0}, $spec_entry); But I want to pass another parameter to find_and_instantiate_commav_file subroutine. I tried, find({wanted = \find_and_instantiate_commav_file(some_value), You can't pass an argument while defining a subroutine reference in general. BTW, from the File::Find man page: The wanted function takes no arguments but rather does its work through a collection of variables. no_chdir = 0}, $spec_entry); And the sub routine is as follows: sub find_and_instantiate_commav_file() { my $slave_path = shift; No argument passed to the sub, so @_ is empty, and that's the reason for the error message below. *LINENO:* if ( /,v$/ ) { // do something } } This fails with, Use of uninitialized value in pattern match (m//) at ...*LINENO* Not a CODE reference at /usr/local/oracle/perl/5.8.1/lib/File/Find.pm line 792. Can anyone let me know how to pass parameters to subroutine refernced in find method and how to access these within the subroutine. You can use a lexical my-variable, which you set before invoking find, and accessing from within the wanted sub. hth, joe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Query on File::Find
On Jul 7, Shobha Deepthi said: But I want to pass another parameter to find_and_instantiate_commav_file subroutine. I tried, find({wanted = \find_and_instantiate_commav_file(some_value), no_chdir = 0}, $spec_entry); The syntax \function returns a reference to a function. But the syntax \function(...) returns a reference to the RETURN value of function() called with whatever args you've given it. What you want to do is: find({ wanted = sub { find_and_instantiate_commav_file(some_value) }, no_chdir = 0, }, $spec_entry); Here, we create an anonymous function (sub { ... }) and use it. This anonymous function, when called, just calls the find_...(...) function. -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: FAQ
On Jul 7, madhurima das said: #assign.pl# #!/usr/bin/perl use strict; use warnings; print enter the first number\n; my $x = STDIN; chomp $x; print enter the second number\n; my $y = STDIN; chomp $y; my $z = system(assign.f,'$x','$y'); Many things wrong here: 1. system() does NOT return the OUTPUT of the program it runs (see the docs: perldoc -f system) 2. you have single quoted $x and $y, which means they are simply the strings $x and $y -- you wanted Perl's values for those variables 3. you're calling assign.f, instead of a.out 4. assign.f reads its values from STDIN, not from the commandline Assuming you have compiled assign.f to a.out, I would do the following: use IPC::Open2; open2 my($read), my($write), ./a.out or die can't open2 ./a.out: $!; $read; # read (and discard) a line of output print $write $x\n; $read; # read (and discard) the next line of output print $write $y\n; chomp(my $z = $read); # read (and save) the next line of output close $read; close $write; -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- 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 question on perl modules
On Jul 7, 2005, at 8:16, Peter Rabbitson wrote: Hello everyone, Most modules I run across have a BEGIN block containing some variable declarations, module loaders etc. Although I understand what BEGIN is (code being evaluated immediately after it is parsed), I miss the point of the excercise. It is very simple: BEGIN is appropriate when you need something to be executed at compilation time. That's it. If your code does not need anything to be executed there, then you don't need a BEGIN block. You seem to assume that the lack of BEGIN blocks in your programs is suspicious, as if you were missing something. Well, probably you don't, BEGIN blocks are not that common in everyday programming, I need them just occasionally. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Query on File::Find
Hi Jeff, Thanks for your help. That really worked! Shobha Deepthi V The statement below is true. The statement above is false. Jeff 'japhy' Pinyan wrote: On Jul 7, Shobha Deepthi said: But I want to pass another parameter to find_and_instantiate_commav_file subroutine. I tried, find({wanted = \find_and_instantiate_commav_file(some_value), no_chdir = 0}, $spec_entry); The syntax \function returns a reference to a function. But the syntax \function(...) returns a reference to the RETURN value of function() called with whatever args you've given it. What you want to do is: find({ wanted = sub { find_and_instantiate_commav_file(some_value) }, no_chdir = 0, }, $spec_entry); Here, we create an anonymous function (sub { ... }) and use it. This anonymous function, when called, just calls the find_...(...) function.
query
Sir, I have the following problem: I need a perl program which asks the user to input two numbers x y. The program next calls a fortran program to do some calculations with the two numbers x y sends the output z back to the perl program. The perl program next conveys this output z to the user. My programming approach to this problem is as follows: PERL PROGRAM #assign.pl# #!/usr/bin/perl use strict; use warnings; print enter the first number\n; my $x = STDIN; chomp $x; print enter the second number\n; my $y = STDIN; chomp $y; my @z = system(assign.f,'$x','$y'); print Output of the two numbers is:\n; print @z,\n; exit; #output of assign.pl# $ perl assign enter the first number 2 enter the second number 4 Can't exec assign.f: Permission denied at assign line 14, STDIN line 2. Output of the two numbers is: -1 FORTRAN PROGRAM #assign.f# WRITE(*,*) ENTER FIRST NUMBER READ(*,*) x WRITE(*,*) ENTER SECOND NUMBER READ(*,*) y z = x+y WRITE(*,*)OUTPUT OF THE TWO NUMBERS IS: WRITE(*,*)z END #output of assign.f# $ g77 assign.f $ ./a.out ENTER FIRST NUMBER 2 ENTER SECOND NUMBER 4 OUTPUT OF THE TWO NUMBERS IS: 6. So,i'm unable to connect both the programs. Kindly help with some books or pseudocode or the functions needed to solve this problem. Waiting for an early response. Thanking you.. __ How much free photo storage do you get? Store your friends 'n family snaps for FREE with Yahoo! Photos http://in.photos.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: query
On Thu, 7 Jul 2005, madhurima das wrote: I have the following problem: Yes. We saw it each of the previous times you posted it. While you were posting this message twice and another one three times -- please don't ever do that again, by the way, thanks -- you got back several useful responses. Did you read any of the responses? Clearly it seems that you didn't, because they had specific recommendations for ways to fix your program that you still aren't correcting. Send your messages *once*. Read the responses you get. Act on those responses. If you still need help, demonstrate how the fix didn't do what you need to have done, and explain what you're confused about. If you have to have an early response, a free, volunteer list may not be the best alternative available to you :-) If you're just going to keep posting your work requirements, maybe the right thing would be to pay someone to do the work for you. There are several people on the list that would be happy to do your work for you for a reasonable fee. Alternatively, read the responses people have already sent back to you. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: query
madhurima das [EMAIL PROTECTED] wrote: I have the following problem: Looks like the previous time you posted this. [...] my @z = system(assign.f,'$x','$y'); [...] Read the perlfunc manpage on system. 1. system does return a scalar. 2. that scalar is not the output of the program you called. 3. the Fortran code you are calling does not expect parameters on the command line. It tries to read them from standard input. 4. you're trying to run Fortran source code. That will not work. HTH, Thomas PS: No, I will not do your homework for you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Atmoic operations in Multi-threaded Perl?
On 7/6/05, Siegfried Heintze [EMAIL PROTECTED] wrote: Can I assume that an auto-increment operation on an integer value is atomic (that is, cannot be interrupted by another thread)? This is a common assumption in C/C++. The perl debugger I use leads me to believe that perl stores all integers as strings however, in spite of my efforts to force them to integer by adding zero. This would mean that an auto-increment is probably not atomic. What about a string copy: is that atomic? these should get you started: http://www.perlmonks.org/index.pl?node_id=288022 http://search.cpan.org/~nwclark/perl-5.8.7/ext/threads/shared/shared.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Intelligent Sorting
Here is one way to approach: !perl use strict; use warnings; my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12); foreach my $MySortedFile (sort { $a-[1] = $b-[1] or $AlphaToNbr{lc($a-[2])} = $AlphaToNbr{lc($b- [2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} DATA ) { chomp($MySortedFile-[0]); print $MySortedFile-[0] . \n; } I have a rudimentary understanding of the above now (from reading Ch 15 of 'Learning Perl' and the perlreftut manpage). This is what I grok (assuming a mmmDD format): 1. Create a hash with numeric equivalents for the months. 2. Perform a sort by first comparing numbers (I'm assuming the , but I don't quite know how that reference works). 3. Then comparing mmm (having been converted to lower case, the value of the respective AlphaToNbr key is compared). 4. Compare another pair of numbers (DD?) After that I'm lost. I'm not familiar with the 'map' function or what happens after that. Also, you use an imaginary scalar that would contain the data. I have the data in an array and tried to use your sortsub as follows (taking some cues from the LP book); I think I'm off base... begin snip (omitted creation of array @user_links) my %AlphaToNumber = ( jan = 1, feb = 2, mar = 3, apr = 4, may = 5, jun = 6, jul = 7, aug = 8, sep = 9, oct = 10, nov = 11, dec = 12, ); # sort chronologically using a code snippet from 'Wags' @user_links = ( sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } @user_links; map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} DATA ); end snip __DATA__ /2005Jul01-2005Jul02/foo/bar.html /2005Jul05-2005Jul06/foo/bar.html /2005Jun09-2005Jun10/foo/bar.html /2005Jun10-2005Jun11/foo/bar.html /2005Jun13-2005Jun14/foo/bar.html /2005Jun14-2005Jun15/foo/bar.html Output: /2005Jun09-2005Jun10/foo/bar.html /2005Jun10-2005Jun11/foo/bar.html /2005Jun13-2005Jun14/foo/bar.html /2005Jun14-2005Jun15/foo/bar.html /2005Jul01-2005Jul02/foo/bar.html /2005Jul05-2005Jul06/foo/bar.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: Intelligent Sorting
On Jul 7, Ryan Frantz said: foreach my $MySortedFile (sort { $a-[1] = $b-[1] or $AlphaToNbr{lc($a-[2])} = $AlphaToNbr{lc($b- [2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} DATA ) { [snip] } 1. Create a hash with numeric equivalents for the months. 2. Perform a sort by first comparing numbers (I'm assuming the , but I don't quite know how that reference works). 3. Then comparing mmm (having been converted to lower case, the value of the respective AlphaToNbr key is compared). 4. Compare another pair of numbers (DD?) After that I'm lost. I'm not familiar with the 'map' function or what happens after that. You have to read it from the bottom up. FIRST the input filehandle is read (in this case, DATA), and all the lines of input are fed to the map() function. THEN the map() function returns a list of array references, whose elements are: the original line, $1, $2, $3 (from the regex match). This list of array references is then passed to sort(), which sorts them first by their year, then by the hash-value associated with the lowercase version of their month, and then by their day. my %AlphaToNumber = ( jan = 1, feb = 2, mar = 3, apr = 4, may = 5, jun = 6, jul = 7, aug = 8, sep = 9, oct = 10, nov = 11, dec = 12, ); # sort chronologically using a code snippet from 'Wags' @user_links = ( sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } @user_links; map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} DATA ); Ok, you would do: @user_links = sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } map { [ $_, /^.(\d{4})(\w{3})(\d{2})/ ] } @user_links; Here, your @user_links array holds the data that Wags was reading from the DATA filehandle. We still execute the map() on it, though, because we need to get from /2005Jun01-Jun04xxx to the array reference containing [/2005Jun01-Jun04xxx, 2005, 'Jun', '04']. -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Intelligent Sorting
Ryan Frantz wrote: Here is one way to approach: !perl use strict; use warnings; my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8 sep 9 oct 10 nov 11 dec 12); foreach my $MySortedFile (sort { $a-[1] = $b-[1] or $AlphaToNbr{lc($a-[2])} = $AlphaToNbr{lc($b- [2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} DATA ) { chomp($MySortedFile-[0]); print $MySortedFile-[0] . \n; } I have a rudimentary understanding of the above now (from reading Ch 15 of 'Learning Perl' and the perlreftut manpage). This is what I grok (assuming a mmmDD format): 1. Create a hash with numeric equivalents for the months. 2. Perform a sort by first comparing numbers (I'm assuming the , but I don't quite know how that reference works). The (\d{4}) implies numeric and there MUST be four digits(the form can be {lowest char count,highest character count). If you leave blank like {1,} then says 1 to as many as you can find. 3. Then comparing mmm (having been converted to lower case, the value of the respective AlphaToNbr key is compared). 4. Compare another pair of numbers (DD?) Correct if the year is equal and the month is equal then compare the days. After that I'm lost. I'm not familiar with the 'map' function or what happens after that. Also, you use an imaginary scalar that would contain the data. I have the data in an array and tried to use your sortsub as follows (taking some cues from the LP book); I think I'm off base... begin snip (omitted creation of array @user_links) my %AlphaToNumber = ( jan = 1, feb = 2, mar = 3, apr = 4, may = 5, jun = 6, jul = 7, aug = 8, sep = 9, oct = 10, nov = 11, dec = 12, ); # sort chronologically using a code snippet from 'Wags' @user_links = ( sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } @user_links; map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} DATA ); Just take DATA and replace that with @user_links. The code should look like: @user_links = ( sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} @user_links; The map is creating an array reference where item 0 is Capturing the whole input line item 1 is the (\d{4}) Capturing the year item 2 is the (\w{3}) Capturing the month item 3 is the (\d{2}) Capturing the day Now as you view the sort you see the $a-[1] = $b-[1] which is comparing the year then [2] is comparing the numeric month then [3] is comparing the numeric day Wags ;) end snip __DATA__ /2005Jul01-2005Jul02/foo/bar.html /2005Jul05-2005Jul06/foo/bar.html /2005Jun09-2005Jun10/foo/bar.html /2005Jun10-2005Jun11/foo/bar.html /2005Jun13-2005Jun14/foo/bar.html /2005Jun14-2005Jun15/foo/bar.html Output: /2005Jun09-2005Jun10/foo/bar.html /2005Jun10-2005Jun11/foo/bar.html /2005Jun13-2005Jun14/foo/bar.html /2005Jun14-2005Jun15/foo/bar.html /2005Jul01-2005Jul02/foo/bar.html /2005Jul05-2005Jul06/foo/bar.html *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Intelligent Sorting
Just take DATA and replace that with @user_links. The code should look like: @user_links = ( sort { $a-[1] = $b-[1] or $AlphaToNumber{lc($a-[2])} = $AlphaToNumber{lc($b-[2])} or $a-[3] = $b-[3] } map {[$_, /^.(\d{4})(\w{3})(\d{2})/]} @user_links; The map is creating an array reference where item 0 is Capturing the whole input line item 1 is the (\d{4}) Capturing the year item 2 is the (\w{3}) Capturing the month item 3 is the (\d{2}) Capturing the day Now as you view the sort you see the $a-[1] = $b-[1] which is comparing the year then [2] is comparing the numeric month then [3] is comparing the numeric day Wags ;) To finalize the script, I need to output this data. I did the following and it works. begin (omitted opening filehandle and other prints...) foreach (@user_links) { print USER $_-[0]; } end Many thanks to Wags and japhy; I've really learned a lot from the both of you. I'm off the pick up 'Programming Perl' after I finish 'Learning Perl'... ry -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Intelligent Sorting
Ryan Frantz wrote: [snip] Many thanks to Wags and japhy; I've really learned a lot from the both of you. I'm off the pick up 'Programming Perl' after I finish 'Learning Perl'... ry Pick up the Learning Perl Object, References, and Modules book before picking up Programming Perl, it will serve you better as a learning tool. Though they may seem like more advanced topics, learning them will accelerate your Perl usage and save you loads of time. I am certainly not saying that you shouldn't have the Camel on your desk, but the learning series when first starting will be more helpful. Much of what the camel provides is already available from perldoc. If you can only get one, stick with the learning series, though if you can swing both there is no reference source like the Camel. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Module memory usage
what are the various ways of finding out how much memory a particular module is using, from the command line under Linux ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Module memory usage
On Thu, 7 Jul 2005, Scott R. Godin wrote: what are the various ways of finding out how much memory a particular module is using, from the command line under Linux ? A lot the modules in the B:: and Devel:: namespaces can get at this sort of information. The Devel::Size module can get at this, at least partly. http://search.cpan.org/~dsugal/Devel-Size/Size.pm B::TerseSize also looks useful: http://search.cpan.org/dist/B-Size/lib/B/TerseSize.pm So you should be able to do something like this: $ perl -MO=TerseSize -MCGI -e '$q = new CGI; 1;' That suggests 240 bytes on my system, which is smaller than I expected, but then I wasn't doing anything interesting. It may be more interesting for use in profiling real programs. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Intelligent Sorting
Jeff 'japhy' Pinyan wrote: On Jul 6, Ryan Frantz said: I'm working on a script that will generate a listing of files on a regular basis so that I can create hyperlinks to each respective file. As you see from the sorted output below, though it is in ASCIIbetical order, it is not in chronological order: /2005Jul01-2005Jul02/foo/bar.html /2005Jul05-2005Jul06/foo/bar.html /2005Jun09-2005Jun10/foo/bar.html /2005Jun10-2005Jun11/foo/bar.html /2005Jun13-2005Jun14/foo/bar.html /2005Jun14-2005Jun15/foo/bar.html Is there any decent documentation available that I could study so that I can sort this better? I thought about grabbing the ctime of each file and sorting on that but I'm not sure if that would add unnecessary complexity to the script. The primary problem is that the dates in the filenames are formatted as mmmDD rather than MMDD. Before sorting the filenames, you could convert the month NAMES to numerical representations (Jan = 01, Dec = 12), and then after you've sorted them (ASCIIbetically will work here) you can change those numerical representations back to the month names. from Programming Perl's 'Efficiency' chapter: Sorting on a manufactured key array may be faster than using a fancy sort subroutine. A given array value may participate in several sort comparisons, so if the sort subroutine has to do much recalculation, it's better to factor out that calculation to a separate pass before the actual sort. :-) such as, for example, building the hash keys on the fly as you slurp in the dir names/paths into that key's value . . . (hint, hint, did the lightbulb go off yet?) %month2num = ( Jan = 01, Feb = 02, ...Jun = 06, ... Dec = 12);#fixme foreach ( qw[ /2005Jun13-2005Jun14/foo/bar.html ] ) { my $fullpath = $_; my ($y1, $m1, $d1, $y2, $m2, $d2) = m( ^/ # starting slash (\d{4}) # year (\w{3}) # monthname (\d{2}) # day - # a dash (\d{4}) # etc, etc, (\w{3}) (\d{2}) / )x or warn $pathname didn't match! next; my ($MD1, $MD2) = $month2num{ $m1 }, $month2num{ $m2 }; $squid{$y1$MD2$d1-$y2$MD2$d2} = $fullpath; } print $squid{$_}\n foreach sort keys %squid; Of course, there are certain constraints involved with regards to how much memory you'll use if your list is long... :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Form / CGI error
--- Chris Devers [EMAIL PROTECTED] wrote: On Wed, 6 Jul 2005, Ron Smith wrote: I'm getting an error when I submit the following html form to a CGI script. Let's focus on the script, not the HTML. Once you've verified that the script works, at least on a basic level -- i.e. you can go to http://your-site/cgi-bin/your-script.cgi and get back a non-error response -- *then* you can start thinking about the HTML. #!/www/perl/bin/perl -wT use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print header; print CORE::dump(); # = This line was originaly: print dump(); Okay, hold that thought... -snip-3-From the browser--- Internal Server Error This continues to be useless. It's a generic error response from the web server; it indicates nothing about what the actual problem was. That said, with CGI::Carp's fatalsToBrowser, you should be getting useful diagnostics in the web server response. Maybe it's hidden in a comment or something, I don't know. In any case, the response you pasted doesn't have any useful information in it, just as it didn't when you pasted it to the list a few days ago :-) --snip-4-From the error log-- [Wed Jul 06 18:23:56 2005] [error] [client 127.0.0.1] Premature end of script headers: form4-21.cgi, referer: http://localhost/form4-21.html Okay, now we're getting somewhere. Premature end of script headers is generally a tell-tale sign that the CGI script never sent back the mandatory content-type declaration. I'm not clear why this isn't working, as the `print header;` line you have should do this, but in any case you can ignore CGI.pm for a moment and just put the needed line in directly, like so: #!/www/perl/bin/perl -wT use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print Content-type: text/plain\n\n; print Okay, at least this worked.\n; If the code above works, then you can amend it to use your CORE line: #!/www/perl/bin/perl -wT use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print Content-type: text/plain\n\n; print CORE::dump(); Now then, why on earth are you trying to dump core? This was just an exercise out of a book. I gave your suggestion a try and worked through the lines and got it to work. I still get the error with 'dump()' though. I finally moved on to the following, whiched worked fine: #!/www/perl/bin/perl -wT # use strict; use CGI qw(:standard); # use CGI::Carp qw(fatalsToBrowser); print header; my $first_name = param('fname'); my $last_name = param('lname'); my $fav_color = param('color'); print qq(Hello, $first_name $last_name.br /); print qq(Your favorite color is: $fav_colorbr /); Thanks for the suggestion. :-) Ron If you just want to output the environment, this is a clumsy way to do it. Something like this would work just fine: #!/www/perl/bin/perl -wT use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print Content-type: text/plain\n\n; print Environment variable dump:\n; foreach $key ( sort keys %ENV ) { print $key: $ENV{$key}\n; } That should work, and as it isn't dumping core, it might even behave :-) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Query about ssh from perl program
Hello All, I have a query about using ssh programmatically. I tried using both system and exec, but didn't work. I mean, I wanted some processing to happen on the remote machine to which i connect with ssh, which is not happening. I have copied the code below. Kindly help or suggest any other options! Thanks! Dhanashri foreach $machine (@machine_list) { $command = ssh -l commonuser $machine; system($command); $flood_dir=/home/commonuser/flood; # Run flood $command=$flood_dir/flood/flood $flood_dir/round-robin.xml $flood_dir/flood.out; system($command); # Run analyze_relative script on the flood logs to generate redable report $command=$flood_dir/flood/examples/analyze-relative $flood_dir/flood.out $flood_dir/flood.report; system($command); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response