RE: my, my...
Jorge Almeida mailto:[EMAIL PROTECTED] wrote: : #!/usr/bin/perl -w : use strict; : use diagnostics; : my $a=27; : doit(); : sub doit{ : print $a\n; : } : : The output of this program is: : 27 : : Just what I would expect if line 4 had our instead of my. : What am I missing? $a, in this case, is a file-scoped lexical. It is available anywhere in the file. Sometimes a file scoped lexical is called a global variable, though that can be confusing because global has other meanings as well. It is usually best to avoid using variables which are not local to a sub routine inside a sub routine, though there are cases where this it is desirable and good programming practice. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: reg exp continued need pulled from reference
Derek B. Smith mailto:[EMAIL PROTECTED] wrote: : I then tried Try something simpler, not more complex. Test this case. my @hosts = ( 'sun' ); $worksheet-write_col( 'A2', [EMAIL PROTECTED], $sheet_format ); If it fails testing then there may be a problem with write_col() or with the setup for the object $worksheet. If it does test okay then the problem may be in the data manipulation just before the call to write_col(). HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Conditional sorting across two arrays
Rinku Mahesh mailto:[EMAIL PROTECTED] wrote: : If the above explaination is confusing I'm looking for a way : where every element of an array can be mapped to corresponding : element of another array and as a whole both the arrays require : a sorting w.r.t. 2nd array. M.J. Dominus wrote three slides about an Indirect Sort which you may find helpful. He's using two arrays of names. One for first names, one for last names. Basically, the idea is to sort the array indexes and then apply the sorted indexes to each array using an array slice. (I don't know if he's right about those APL folks.) http://perl.plover.com/yak/hw2/samples/slide003.html In your case, you need a numerical comparison (=) on both arrays as opposed to a string comparison (cmp). You also require that ties be sorted on the other array. That can be performed within the sort. One thing I like about sorting indexes is that you can save the sorts. use strict; use warnings; # Test data my @unique= ( 66, 23, 44, 11, 900, 1009 ); my @occ_count = ( 2, 77, 22, 2, 77, 29 ); # Sort in ascending order, ascending order # Use reverse for descending order, descending order my @ascending_indexes = sort { $occ_count[$a] = $occ_count[$b] || $unique[$a] = $unique[$b] } 0 .. $#occ_count; # Sort in descending order, ascending order # Use reverse for ascending order, descending order my @descending_indexes = sort { $occ_count[$b] = $occ_count[$a] || $unique[$a] = $unique[$b] } 0 .. $#occ_count; # Reports print Ascending sort then ascending sort:\n\t; printf '%5d', $_ foreach @occ_count[ @ascending_indexes ]; print \n\t; printf '%5d', $_ foreach @unique[ @ascending_indexes ]; print \n\n; print Ascending sort then descending sort\n\t; printf '%5d', $_ foreach @occ_count[ reverse @descending_indexes ]; print \n\t; printf '%5d', $_ foreach @unique[ reverse @descending_indexes ]; print \n; print Descending sort then descending sort:\n\t; printf '%5d', $_ foreach @occ_count[ reverse @ascending_indexes ]; print \n\t; printf '%5d', $_ foreach @unique[ reverse @ascending_indexes ]; print \n\n; print Descending sort then ascending sort\n\t; printf '%5d', $_ foreach @occ_count[ @descending_indexes ]; print \n\t; printf '%5d', $_ foreach @unique[ @descending_indexes ]; print \n; __END__ For larger arrays, you might want to transform one array first. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CYGWIN Uninstall
Charith Hettige mailto:[EMAIL PROTECTED] wrote: : And I am sorry if I caused any inconvenience by posting : this as I thought people will be help full rather than : point out what this mailing list is and what it is not. Wow! That's a terrible apology. Rewrite it and try being just a little contrite. Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Turning text array into variables?
Shawn Hinchy mailto:[EMAIL PROTECTED] wrote: : Is there any way to turn text from an array into variables? Yes. Use a hash. use List::Util 'sum'; my @array = qw(one two three); my %variables; @variables{ @array } = 1 .. 3; my $answer = sum( @variables{ @array } ); print Answer is : $answer.; __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- 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, how to extract five texts on each side of an URI? I post my own perl script and its use.
Hui Wang mailto:[EMAIL PROTECTED] wrote: : Can anybody tell me how to improve the running speed of this : program? Thanks. I don't know if this is faster, but it is a more accurate solution. Your submitted code failed under some untested circumstances. I created another page similar to the CPAN page you used and fed it more complicated tests. Chakrabarti placed relevance on distance from the link. I changed your report to reflect this relevance. Instead of squashing all text together, it now shows a report of text token relevance. This change allowed me to test more thoroughly as well. Here is the sample report for one link with multiple texts inside the anchor. http://www.clarksonenergyhomes.com/scripts/index.html -5: 3401 MB 280 mirrors -4: 5501 authors 10789 modules -3: Welcome to CPAN! Here you will find All Things Perl. -2: Browsing -1: Perl modules 0: Perl 0: scripts +1: Perl binary distributions (ports) +2: Perl source code +3: Perl recent arrivals +4: recent +5: Perl modules You can find the modified code here (for a short time): Script: http://www.clarksonenergyhomes.com/chakrabarti.txt Module: http://www.clarksonenergyhomes.com/chakrabarti.pm HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Conversion of Hex bytes to binary and vice versa
Dharshana Eswaran mailto:[EMAIL PROTECTED] wrote: : The desired output should look like the following: : : 0x0a = 1010 : 0x23 = 00100011 : : Can anyone suggest me for the same? Read perlfaq4: How do I convert between numeric representations/bases/radixes? HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- 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 everyone, how to extract five texts on each side of an URI? I post my own perl script this time.
Hui Wang mailto:[EMAIL PROTECTED] wrote: : I can make my program do its job at last, but it runs : slowly. Can anybody tell me how to improve the running : speed of this program? You only provided the module. Can you supply a working example? Something we can actually run? HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Jumping to inner loops
Luba Pardo mailto:[EMAIL PROTECTED] wrote: : Example: once that the element h=0 from arra1 is found in : array2, then move to the inner loop for h to become h+2 : and not h+4. Then when the 4 consecutive elements in the : array 1are found in the array 2, then make h= h+4 in the : array1. Elements in the other array should move also : every 4 elements. Can you explain that better? It really makes very little sense. Ignore the script and just explain each step you wish to take. Forget about h and k and the inner and outer loop, just explain what you are trying to accomplish. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Worse than just a beginner
Brian mailto:[EMAIL PROTECTED] wrote: : I'm wondering if someone can do me an enormous favour and : write a cgi for me please, I just can't get my head around : the books I have, they might just as well be written in : Klingon. You want us to feed you for a day? Think about what needs to be done. What are the steps needed to perform the actions to get the results you want? Here's an example. 1. Get numerical user input. 2. Divide input from step 1 by 25 and keep the remainder. 3. Use the result from step 2 as an index into a string. 4. ... Notice that my algorithm does not contain elements of a specific solution. These steps could equally apply to VB, C#, Java or Perl. Once you have listed all the steps needed to describe the problem then you can apply a specific solution. Look at each step and solve only that step. Solutions are a lot easier if you break them down into more manageable pieces first. BTW, You don't have to solve them in the order they will be used. Solve the easiest one first, then the next and so on. Look at step 2 above. Repeated subtractions gets you a remainder. Now you have a solution for the remaining value. Try to solve the rest yourself. Come back here when you get stuck solving a step. print 1 % 25, \n; print 30 % 25, \n; print 300 % 25, \n; print 1234 % 25, \n; print 60001 % 25, \n; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 http://www.clarksonenergyhomes.com/ Don't tread on my bandwidth. Trim your posts. -- 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 parsing program -help
I BioKid mailto:[EMAIL PROTECTED] wrote: : I need a help to write a tricky perl script This is not all that tricky to accomplish. Break the problem into parts and solve each part. You have two main sections. Searching cluster.txt for 100% and deleting corresponding records from data.txt. You can write the script in a number of ways, but try writing the deletion section first. Given a gi number, delete a record in data.txt. You'll probably do something like this. - Open the file, - Split the file by records, - Search record for gi number field, - Delete that record on the disk, and - Close the file. There's nothing tricky about that. Each of those steps is a fairly trivial task. Some steps can be done in one line of perl code. Here are some steps for the first sections. - Open the file, - Split the file by records, - Search record for 100% field, - Locate gi number, - Delete that record in data.txt, and - Close the file. There's nothing tricky about that either. In fact, many of those steps are the same as the one's above. Perl is an excellent language choice for coding this type of application. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: nice regular expression
I.B. wrote: : unfortunately I have to use regex to solve this problem. Why do you have to use a regex? Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 to parse and verify certain content..
Vishwanath Chitnis wrote: : is there any other way other than above mentioned to do this? How can we possibly tell with only those lines? Show more code. Something we can run that will illustrate your problem. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Modules for printing the content of an array
Rob Coops wrote: : Simply do this in your perl script: : *use Data::Dumper;* : *print Dumper @huge_array;* For the archives: Those asterisks (*) are for emphasis. They are not actually in the code. Arrays and hashes can also be dumped using a reference. I find a reference more aesthetically pleasing. use Data::Dumper 'Dumper'; print Dumper [EMAIL PROTECTED]; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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::Dumper
chen li wrote: Let's look at the calls: : my $call=Bar::print_result(1,2); : my $call2=Bar-print_result(2); $call gets whatever is returned by Bar::print_result(). As we see below, Bar::print_result() always returns 1. Now. we'll look at what the sub returns: : sub print_result{ : my $data1=shift; : my $data2=shift; : print This is the data1 $data1 and data2 $data2, \n; : } Unless the return() statement is used, a sub routine returns the value of the last operation or assignment. This subroutine returns the success of the print. If the print is successful, this subroutine, whether called as a method or as a subroutine, will always return 1. Since $call will always be set to 1, we have confirmation that the call to both the subroutine and the method were successful. : My question: What does it mean? Does it mean : successfully calling either a subroutine or method? : This is the data1 1 and data2 2 @_ = (1, 2) : $VAR1 = 1; Sub routine call was successful. : This is the data1 Bar and data2 2 @_ = ('Bar', 2) : $VAR1 = 1; Sub routine call was successful. This may be a more useful test. use strict; use warnings; use Bar; print Sub routine call:\n\tBar::print_result(1,2);\n; my $call = Bar::print_result(1,2); print \n\nMethod call:\n\tBar-print_result(1,2);\n; $call = Bar-print_result(1,2); __END__ package Bar; use strict; use warnings; use Data::Dumper 'Dumper'; sub print_result{ print Dumper [EMAIL PROTECTED]; } 1; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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
John Ackley wrote: : while( ($service) = $SERVICE-fetchrow_array ) { According to the DBI docs: If there are no more rows or if an error occurs, then fetchrow_array returns an empty list. When a value is returned, $service is set to that value. When we get to the end of the list, () is returned and $service is set to the undefined value. Since it tests false, the while loop stops with $service set to an undefined value. You can see this in the following script. use strict; use warnings; use Data::Dumper 'Dumper'; my $service; ($service) = (); print Dumper $service; __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 dynamically sign array a name
Shiping Wang wrote: : Hi, I have a big array, I need re-arrange it then put into sub : array, after that do something on each sub array. How do you want to split it into sub arrays? Like items, number of items, random items, ...? : Here is my code: [snip] It is really hard to tell what you are attempting. We don't know what is in @P_array, for example, because it is never defined and @q_$i isn't a valid perl variable name. Working code would be better. Tell us what you want to do to the big array. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 local when appropriate
Derek B. Smith wrote: : ## Below is better pratice ## : : sub getfile { : my $filename = shift; : open F, $filename or die open failed $! : my $contents; : { local $/ = undef; # Read entire file at once :$contents = F; # Return file as one line : } : close F; : return $contents; : } : : : I read an excerpt from : http://perl.plover.com/local.html#2_Localized_Filehandles Curiously, you do not actually localize the file handle in getfile(). : and was wondering if this holds true regarding : localizing $/ and setting it to undef in Perl 5.8.x? If you do not localize the $/ operator then you will change it for the rest of the script. That might be a problem for other I/O operations which fail to set it. In 5.8.x this function might better be written like this, but I lack the experience to call it a best practice. sub slurp_file { # open file for read or die my $file = shift; open my $fh, '', $file or die qq(Cannot open $file: $!); # slurp file local $/ = undef; # return file as scalar return $fh; } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 dynamically sign array a name
Shiping Wang wrote: According to the code you provided, you are breaking up the large array into smaller arrays like this: print Large array values become these subarrays:\n\n; my @P = 1 .. 90; foreach my $i ( 0 .. 9 ) { print \t[; foreach my $value ( $P[$i], @P[8*$i+10 .. 8*$i+17] ) { printf '%3d,', $value; } print ],\n; } __END__ Large array values become these subarrays: [ 1, 11, 12, 13, 14, 15, 16, 17, 18, ], [ 2, 19, 20, 21, 22, 23, 24, 25, 26, ], [ 3, 27, 28, 29, 30, 31, 32, 33, 34, ], [ 4, 35, 36, 37, 38, 39, 40, 41, 42, ], [ 5, 43, 44, 45, 46, 47, 48, 49, 50, ], [ 6, 51, 52, 53, 54, 55, 56, 57, 58, ], [ 7, 59, 60, 61, 62, 63, 64, 65, 66, ], [ 8, 67, 68, 69, 70, 71, 72, 73, 74, ], [ 9, 75, 76, 77, 78, 79, 80, 81, 82, ], [ 10, 83, 84, 85, 86, 87, 88, 89, 90, ], Is that what you really want for each sub array? HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 dynamically sign array a name
Shiping Wang wrote: : Yes, but it start @P = 0 .. 89; I might use the any() function available in List::MoreUtils. I try to avoid flag like the plague. use List::MoreUtils 'any'; my @P = ( 0.06, 0.04, 0.98, 0.12, 0.02, 0.98, 0.11, 0.25, 0.36, 0.01, 0.01, 0.01, 0.02, 0.01, 0.05, 0.056, 0.046, 0.98, 0.12, 0.002, 0.06, 0.04, 0.98, 0.12, 0.02, 0.98, 0.11, 0.25, 0.36, 0.01, 0.01, 0.01, 0.02, 0.01, 0.05, 0.056, 0.046, 0.98, 0.12, 0.002, 0.06, 0.04, 0.98, 0.12, 0.02, 0.98, 0.11, 0.25, 0.36, 0.01, 0.01, 0.01, 0.02, 0.01, 0.05, 0.056, 0.046, 0.90 ); my $cutoff = 0.01; my @result; foreach my $i ( 0 .. 5 ) { if ( any { $_ = $cutoff } $P[$i], @P[8*$i+10 .. 8*$i+17] ) { push @result, 1; } else { push @result, 0; } } print join( \t, @result ), \n; __END__ I might also try a subroutine to process each array. my @result; foreach my $i ( 0 .. 5 ) { push @result, cutoff( [ $P[$i], @P[8*$i+10 .. 8*$i+17] ] ); } print join( \t, @result ), \n; sub cutoff { my $array_ref = shift; return any { $_ = 0.01 } @$array_ref ? 0 : 1; } __END__ Or even this (if you can understand it in six months): my @result = map cutoff( [ $P[$_], @P[8*$_+10 .. 8*$_+17] ] ), 0 .. 5; print join( \t, @result ), \n; sub cutoff { my $array_ref = shift; return any { $_ = 0.01 } @$array_ref ? 0 : 1; } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: incorrect output
Geetha Weerasooriya wrote: : When I turn on the use warnings it gives the warning ' : Use of uninitialized value in numeric ne(!=) at . : line 37, FILE line.. : : Here line 37 is if (@line != ()) { In this case, perl will use the scalar value of @line, which is a count of its elements. # Try this: if ( @line != 0 ) { # Or this: if ( @line ) { HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 do I populate a form field based on the value entered in a different field
RICHARD FERNANDEZ wrote: : For example, if the user types Wilma into the textbox, : the script should populate the target textbox with my : edited value, say, Betty. That sounds like a client side script, like JavaScript or ECMAscript, not perl. With server side perl, you'll need to submit the form to the server before the second textbox is filled. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Parse Help
Jeff Westman wrote: : I would like it cleaned up to look like : : p_var1='SD' : p_var2='QR44' : p_var3='543210987' : p_var4='001' : p_var5='12345' : p_var6='20060907' : p_var7='000WR44' : p_var8='X' : p_var9='' #!/usr/bin/perl use strict; use warnings; my $input = q{ [20060911 14:47:11]p_var1=SD KQt=1 HZZ=2: 83,68//p_var2=QR44 KQt=1 HZZ=4: 77,57,52,52//p_var3=543210987 KQt=1 HZZ=9:52,54,48,52,50,57,49,56,50//p_var4=001 KQt=1 HZZ=3:48,48,49//p_var5=12345 KQt=1 HZZ=5: 49,50,51,52,53//p_var6=20060907 KQt=1 HZZ=8: 50,48,48,54,48,57,48,55//p_var7=000WR44 KQt=1 HZZ=11:48,48,48,48,48,48,48,77,57,52,52//p_var8X KQt=1 HZZ=2: 83,68//p_var9=NULL }; my @report; foreach ( $input =~ /(p_var[^]+)/g ) { # change to single quote tr//'/; # add = if missing s/'/='/ unless /\d=/; # add to report push @report, $_; } # print report print $_\n foreach @report; __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Summary for mean/average calculation in perl
Bryan Harris wrote: :: ... and cute tricks should only be used in cute programs. : : I'll take that as a compliment -- thanks, John! He said cute programs, not cute programmers. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: looping through complicated hashes..
Michael Alipio wrote: : ignore this one.. I've already figured out how. Why not post your solution for the archives? Someone else may run across your question during a search and will not know the answer you found. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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-Line in Regular Expression
Romeo Theriault wrote: : Hello, I'm trying to match this line (or more than one) starting from : the words user picard... : : 8/28/2006 1:04:41 PM: Retrieving mail from host mail.maine.edu : [130.111.32.22], user picard... : 8/28/2006 1:04:45 PM: Mail retrieval failed, reason: POP3 Host did : not acknowlege password and returned following error: -ERR [AUTH] : Invalid login How many lines is that? One or two? It looks like two. Can you attach or provide a link to about 10 lines (5 that match and 5 that don't) as they might appear in the log? BTW, acknowlege is misspelled. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Create HTML code with perl
[EMAIL PROTECTED] wrote: : : I tried with this way, but not work: One reason for the problem is that perl does not recognize and as operators. The print statement needs some type of delimiter to print plain text. As you probably know already, a pair of double quotes () is one set of delimiter. Perl also has a single quote (') for delimiting printable text. In the 'perlop' file we find several other perl operators which allow us to print quoted text under the section entitled Quote and Quote-like Operators. Namely q{}, qq{} and qw{}. Read the docs for detailed information. print MAPA q{table width=95% border=0 cellspacing=0 cellpadding=0}; print MAPA qq{table width=95% border=0 cellspacing=0 cellpadding=0}; Last are HERE documents which are like HTML pre tags for printing. If you find your HERE documents are not printing, consult perlFAQ 4, Why don't my HERE documents work? : print MAPA table width=95% border=0 cellspacing=0 cellpadding=0; Use single quotes when you need to print double quotes without interpolation. print MAPA 'table width=95% border=0 cellspacing=0 cellpadding=0'; There are many perl modules for handling HTML and xhtml output. Since CGI is often used for tabular data, table processing has a number of programmatic solutions which considerably reduce typing and increase program readability. #!/usr/bin/perl use strict; use warnings; use HTML::Table; my $test = new HTML::Table( -width = '95%', -spacing = 0, -padding = 0, -border = 0, -data= [ [ 'test', 'test'], [ 'test', 'test'], ], ); print $test; __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Trouble with variable scoping
Roman Daszczyszak wrote: : In my perl script, I have a global variable called : @excludedIPAddresses, declared at the top of the script using : my. That sounds like a bad idea, but go on. : When I run this, I get an error Can't localize lexical : variable. I understand that it's because the variable is : declared using my; what I don't understand is why, or what I : should declare the variable as, since if I leave out my I get : an error using use strict. Don't use local() in this circumstance. sub ExcludeIPAddress { my $ipAddress = shift; my $subnet = shift; return scalar grep /$ipAddress/, @excludedIPAddresses, $subnet-broadcast(), $subnet-base(); } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: [Bulk] RE: Totally lost - need a starting point
Helen wrote: : Yes I have a perl script running inside of the expect script, : which works fine. I need to find a way to call the expect : script and output the perl to the html page that is calling it. Perl needs to print to STDOUT to send information to the browser via CGI. Calling an Expect script via CGI is an Expect question, not a perl question. Perhaps you need to ask your question on an Expect mailing list. I did find this on the Expect FAQ. http://expect.nist.gov/FAQ.html#q24 HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 some help filtering thru results
Mike Blezien wrote: : My regrex is not very strong and need to some help figuring : out the best way to do this. I don't use regular expressions to parse HTML. I generally use HTML::TokeParser. The documentation is pretty good and I can step through the markup the same way I read it. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Totally lost - need a starting point
Helen wrote: : I am starting from scratch again reading the manual more : completely. I am just running out of time on my deadline. Break down your task into small pieces and solve for those pieces. The first piece I can see is running an Expect script from a perl program. Do you know how to do that? I have no idea what Expect is, but searching for 'expect' and 'perl' in Google revealed a perl module for expect. The other pieces of your problem might include getting form values from an HTML form. CGI.pm can help with that. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Urgent Help!
Neetee Pawa wrote: : I wanna use the name of hash ref as the value of string. That sounds like a really bad idea. A more common approach would probably use the name of the key and set each @row item to that. What do you want the data structure to look like when the loop is done? Don't explain it with words, show us an example. my $i = 0; foreach my $header ( sort keys %$headers) { push @input_data, { $header = $rows[$i++], }; } ~ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: calculate the value in an array of array
chen li wrote: : $total[ $column ] += $row-[ $column ]; : : Can you or anyone else explain it a bit more? It is short for this. $total[ $column ] = $total[ $column ] + $row-[ $column ]; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Vertically aligning textfields when using CGI
Nath, Alok (STSD) wrote: : I am generating a simple form which generates different : textfields and scrolling list in different rows. When I display : the form what I see is, the different textfields and scrolling : list are not aligned vertically. I want the textfields and : scrolling list to start under a particular column. Like Rob, I suggest a table, but I like to fashion my sub routines the same way CGI.pm does by returning text values. print my_form(); sub my_form { my $cgi = CGI-new(); return $cgi-startform( -method = 'GET' ), $cgi-start_table(), form_row( 'Field A', $cgi-scrolling_list( -name= 'field', -default = ['field_1'], -values = [ 'field_1', 'field_2', 'field_3', 'field_4', ], ), ), form_row( 'Field B', $cgi-textfield( -name = 'field_b' ), ), form_row( 'Field C', $cgi-textfield( -name = 'field_c' ), ), form_row( 'Field D', $cgi-textfield( -name = 'field_d' ), ), $cgi-end_table, $cgi-endform(); } sub form_row { my( $field, $control ) = @_; my $cgi = CGI-new(); # adjust column widths to taste. return $cgi-Tr( $cgi-td( { -width = '30%', -valign = 'top' }, $field, ), $cgi-td( { -width = '70%', -valign = 'top' }, $control, ), ); } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 populate an 12x8 array from a data file
chen li wrote: : I need to read a data file containing 96 records/lines : and each record/line contains several columns : separated by tab. I would like to extract the first : column from each record only and put them into a 12x8 : array. Here is the script I use to do the job but it : seems I have some problems with the loop to build a : 12x8 array(I just get a one-dimenstion array only). I would do it in two steps. Import the first columns of each line then use Array::Dissect to reform() or dissect() the array into an AoA. use strict; use warnings; use Data::Dumper 'Dumper'; use Array::Dissect 'reform'; my $file = 'in.txt'; open my $fh, '', $file or die qq(Cannot open $file: $!); my @array; while ( my $line = $fh ) { next if $line =~ /CPM/; push @array, ( split ' ', $line )[0]; } close $fh; @array = reform( 12, @array ); print Dumper [EMAIL PROTECTED]; __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Unable to run prog's
Mohd Abdul Rasheed wrote: :The thing I see in Perl is ppm prompt which looks like : ppm : unfortunately on this prompt I am unable to run any : of my Perl programme . :Please help me out sir give tips for begining it. ppm is not perl. Perl is run from the command line. The perl docs should be in HTML format on your hard drive. Look in the html directory where perl is installed and find the readme.html file. Mine is located here. file:///C:/Perl/html/readme.html HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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-clause again
Dr. Claus-Peter Becke wrote: : first of all a question without respect to my problem. what does : HTH mean? Hope that helps or, sometimes here in Texas it means hotter than Hell. : i would like of having returned a string value as printed by : print @row. That is in a loop. There may be many of those strings, not just one. From the query I assume that each pass produces one return value ($row[0]). They could be printed and then pushed onto another array which will survive the loop. [code in this message is not tested] . . . $sth-execute() or die $sth-errstr; my @result; while ( my @row = $sth-fetchrow_array ) { print @row, $q-br; push @result, @row; } $sth-finish; $dbh-disconnect; return @result; } In scalar context this will return the number of matching rows, if any. In list context it will return the array matches. if ( databaserequest_noun( 'blah', 'blah', 'blah' ) ) { # matches } else { # no matches } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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-clause again
Dr. Claus-Peter Becke wrote: : maybe anybody detects the reason why the return value becomes 1 Perl returns values from subroutines implicitly and explicitly. A 'return' statement is used to send an explicit return. Otherwise, the return value of the last statement is returned implicitly. Explicit returns are preferred, but not required. You have chosen an implicit return. sub databaserequest_noun { . . . $dbh-disconnect; } If successful, $dbh-disconnect;, will return 1. What did you want databaserequest_noun() to return? HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: DBI
Bjørge Solli wrote: : I get an error message I don't understand. I've been following : what I thought was good practice when talking to a DB. Did you import those constants? use DBI qw(:sql_types); HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 get the information on the dynamic website?
sewe_perl wrote: : Is there any method to get the information on the dynamic : website, such as php, jsp and so on. Yes, FTP. php is executed on the server and the result is sent over http. LWP fetches the result, not the source. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 clause
Dr. Claus-Peter Becke wrote: : although for example the values of databaserequest_noun : and $Q::lexicalentry both are 'Italy' i get the resulting : message the entry isn't part of the database. what's : going wrong? databaserequest_noun($col, $table, $case) and $Q::lexicalentry are not both equal to 'Italy'. use CGI; my $q = CGI-new(); if ( 'Italy' eq 'Italy' ) { print $q-p(the entry is part of the database); } else { print $q-p(the entry isn't part of the database); } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Syntax help with variable quotes
Grant wrote: : open(LABEL,/path/to/the/$file.gif); This should be working. Perhaps $file does not have in it what you think it does. Since I/O operations should be checked for success anyway, try this. open LABEL, /path/to/the/$file.gif or die qq(Cannot open /path/to/the/$file.gif: $!); HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Multidimensional array / Passing an array to a sub
Martin Tournoij wrote: : I'm currently massivly confused by multidimensional arrays and : passing arrays to subs. : : Why is it that @_[1] isn't properly copied to @a? It is properly copied. Because @_[1] one is a scalar and @a is an array the reference to the passed array in stored in $a[0]. : Music($var1, [EMAIL PROTECTED]); : : sub Music : { :print $_[1][1]; # works :my @a = @_[1] # Gives warning, should be written as $_[1] So stop writing it as @_[1], silly. :) my $var = shift; my $array_ref = shift; :print $a[1]; # Outputs ARRAY(#memaddr) print @{ $array_ref }; :print $a[1][1]; # Works : :for (@a) for ( @{ $array_ref } ) { HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Dynamically choosing CGI file based on form output
Mike Martin wrote: : I am trying not to go this route because I want to keep the : subsidiary files as self-contained as possible : : There are four files at present which are around 600 lines, : which I think is a sensible size. These all do a specific job : which can be linked together. : : It would be nice to be able to distribute together or separate I see. You could use a system call to the dispatch the scripts from the first form. User and password could be sent on the command line. #!/usr/bin/perl -T use strict; use warnings; use CGI::Carp 'fatalsToBrowser'; use CGI qw( header param :html :form ); if ( param('tasks') ) { dispatch(); } else { print task_form(); } sub dispatch { my %tasks = ( calendar= '', contacts= '/cgi-bin/contacts.pl', correspond = '', filing = '', file_manage = '/cgi-bin/finance.pl', finance = '', telephone = '', timesheets = '/cgi-bin/timesheet.pl', ); # Dispatch to script. *Not Tested* foreach my $task ( param('tasks') ) { next unless $tasks{$task}; system( $tasks{$task}, param('user'), param('pass'), ); } } sub task_form { my %tasks = ( calendar= 'Calendars', contacts= 'Contacts', correspond = 'Correspondence', filing = 'Filing', file_manage = 'File Management', finance = 'Finance', telephone = 'Telephone Logging', timesheets = 'Timesheets', ); return header(), start_html( -style = '/proj.css' ), start_multipart_form(), 'user', br(), textfield( -name = 'user', -size = 15, ), br(), 'password', br(), password_field( -name = 'pass' ), br(), br(), 'Choose a task', br(), scrolling_list( -name = 'tasks', -values = [ sort keys %tasks ], -labels = \%tasks, -multiple = 'true', ), span( { -class = 'place_cmd' }, submit( -name = 'act', -value = 'Chooser', ) ), br(), end_form(), end_html(); } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Returning Values fr nested FOR w/o RETURNing fr sub
Alex Gill wrote: : My question is: : How can the 'for' loop within bases() output a list for 'print' : as invoked in the last line of code? It can't. You'll have to wait until the loop finishes unless you print directly from the loop which is less robust. my @powers; push @powers, 2 ** $_ for 0 .. 7; print bases( @powers ); sub bases { my @bases; foreach my $base (@_) { push @bases, sprintf( '%08b', $base ) . sprintf( '%4d', $base ) . sprintf( '%4o', $base ) . sprintf( '%4X', $base ) . \n; } return @bases; } To save some time you could pass a reference to @powers. print bases( [EMAIL PROTECTED] ); sub bases { my $powers_ref = shift; my @bases; foreach my $base ( @$powers_ref ) { push @bases, sprintf( '%08b', $base ) . sprintf( '%4d', $base ) . sprintf( '%4o', $base ) . sprintf( '%4X', $base ) . \n; } return @bases; } If you understand what it does, map() can compact things. sub bases { my $powers_ref = shift; return map { sprintf( '%08b', $_ ) . sprintf( '%4d', $_ ) . sprintf( '%4o', $_ ) . sprintf( '%4X', $_ ) . \n; } @$powers_ref; } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Dynamically choosing CGI file based on form output
Mike Martin wrote: : I have the following code which should : : 1. Give user a choice of actions : 2. Based on these go to the specified script : : I have the following issues : : 1. The Submit button needs clicking twice after selection The first time the script through the 'select' field is empty and '' is passed into the form 'action' attribute. CGI.pm changes this to the name of this script. If '5' were chosen, the second time through the script the 'select' field is '5' and '/cgi-bin/finance.pl' is passed into the form 'action' attribute. You can remedy this by calling '/cgi-bin/finance.pl' from the script rather then printing the form and then going to the chosen script. A better solution might include modules instead of scripts. : 2. Only one value can be chosen, to choose another the form : must be reloaded from scratch (ie: reload button does not : work, only go etc) That sounds like a browser caching problem. Search the CGI.pm docs for 'cache' for details. You can also add a reset button for the form. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Dynamically choosing CGI file based on form output
Charles K. Clarkson wrote: : The first time the script through the 'select' field is empty Whoopsie! The first time through the script the 'select' field is empty -- 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 handling using CGI
I BioKid wrote: : I am able to do the second part, but am not able to get : the users file to a variable or array ? Read the Files and I/O section of the perlintro file in the perl documentation. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Dynamically choosing CGI file based on form output
Mike Martin wrote: : I have the following code which should : : 1. Give user a choice of actions : 2. Based on these go to the specified script : : I have the following issues : : 1. The Submit button needs clicking twice after selection : 2. Only one value can be chosen, to choose another the form must be : reloaded from scratch (ie: reload button does not work, only go etc) : : Any assistance appreciated : : Script follows [snip] The code does not compile. There is probably a syntax error on the following line. : popup_menu(-name='select',-values=[EMAIL PROTECTED],-default=$commands1{1}[0,-lab els=\%select); BTW, is your space bar broken? White space (tabs, spaces, blank lines, etc) used consistently can make programs easier to read and maintain. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 script from vbscript
Shourya Sengupta wrote: : How do I call a perl script from a vb script? The same way you run *any* external program from a VB script. This is really a VB question, not a perl question. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 add a list of numbers
tom arnall wrote: : Whatever happened to good old: : : my (@data,$result); Why declare these ... : @number = (1,2,3); : $sum = 0; And then use these? Go ahead. Hit yourself upside the head. :) Yet another reason to declare variables only as they are first used. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: math formula substitution and evaluation
Daniel D Jones wrote: : Ah! Simple change: Subroutines should not normally operate on external data. Pass data into and out of each subroutine. As a matter of style, I avoidsqashingwordsinvariableandsuborutinenamesalltogether. I like to use an underscore for most names. run_tests( [EMAIL PROTECTED], [EMAIL PROTECTED] ); : sub runtests() { sub run_tests { my( $tests , $values ) = @_; : my $test; : foreach (@tests) { : $test = $_; foreach my $test ( @$tests ) { : $test =~ s/([a-z])/$values[ord($1) - ord('a')]/g; $test =~ s/([a-z])/$values-[ord($1) - ord('a')]/g; : return 0 unless eval $test; This doesn't look right. If eval fails half way through @tests you will have half of @tests converted and half unconverted. Are you sure you want to change @tests and not work on a copy? : } : return 1; : } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Looking for a faster way of getting a directory listing from a disk
Ed Panni wrote: : I was wondering if there is a quicker way of getting a directory : listing from a disk. I am currently doing the following but it : takes a bit of time if I happen to have to search multiple 250Gb : drives. You are searching through a lot of files. Perhaps the best way to speed things up is to change your algorithm. Instead of collecting all the files first, why not process each wanted file as it is found? You might also be able to break the task down into more manageable chunks of files. Perhaps 10 or 20 GB sections of the disks at a time. The File::Find module will help make this easier. : $i = c d e; No quoting? That doesn't look good. : @array = ; Why set the first element to ? Why name an array array? We already know it's an array. Why not use something like @files? : foreach $i (split/ /,$disk) { $disk has not been defined yet. Perhaps you meant $i? : print \nChecking $i: for the tests.; : @array1= `dir $i:\\ /B /S`; Perl has built-in directory functions. You might also find the File::Find module useful. It will recurse directories and allows you to filter for certain files. File::Find::Rule is very convenient, though still slow on an entire drive. : # Establish a count of how big the array is for stepping : through the array later to find the .exe file : : $lineC = @array1; $lineC will reset for each drive. That's not what you probably want. Everything in @array will be one big array when the loop is finished, not separate arrays for each drive. It sounds like you need a hash of arrays keyed to drive letters, not a simple array. : # append the array if more than one disk is selected : : push(@array, @array1); : : } Read the perlfunc file, especially directory functions. Start with opendir and follow the links to related functions. There's an example of reading a directory under the readdir function. The File::Find module is the most popular way to safely recurse directories. Read up on the use of strictures and warnings. You have a sloppy programming style which will hurt you down the road. Start every script with these modules. Think of them as training wheels. They are needed until you find your balance. use strict; use warnings; use diagnostics; Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 getting errors
Ryan Dillinger wrote: : Hello again, : I have rewrote this script I hoped the way you told me. : And now I have just one error that states: Use of uninitialized : value in hash element at names.pl line 24, line 1 When I run the script I get this. Are you sure this is the script you are running? Global symbol $search requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 13. Global symbol %name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 14. Global symbol $raw requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 17. Global symbol $in requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 27. Global symbol $in requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 29. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 30. Global symbol $keys requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 30. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 31. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 31. Global symbol $in requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 33. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 36. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 37. Global symbol $in requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 39. Global symbol $search requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 41. Global symbol $search requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 44. Global symbol $keys requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 45. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 53. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 54. Global symbol $name requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 54. Global symbol $in requires explicit package name at C:\1\dfwrein\cgi-bin\a.pl line 60. Execution of C:\1\dfwrein\cgi-bin\a.pl aborted due to compilation errors. Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Multiple filenames in form
Peter Oram wrote: : How can I get the IE behaviour to occur when a user has Firefox? That's a JavaScript problem, not a perl problem. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Removing print statements from cgi script
Mike Martin wrote: : Does anyone know if its possible to remove data printed from a : web-page created from cgi.pm depnding on the effect of a : sub-routine. Not from the server. It may be possible to do this with javascript or with AJAX. Search Google for details on AJAX. : : ie: : : I print the header and a selection form which then runs a sub : - is it posible to replace the contents without loading a new : web-page After you print the page, your script stops running. Each time you submit a form you may start the script again. It is not one continuous script, even though it sometimes appears that way to the user. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 Help.
Lou Hernsen wrote: : and if I want to include certain german umlutted vowels like : ö and ä i would add them like this? : $string =~ tr/-_a-zA-Z0-9öä//cd; : What happened when you tested it? : then what does this do? (from parsing SDTIN) : : $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg; Well, the left hand side of the s operator is a regular expression. This expression is looking for a percent sign (%) followed by an hex number, followed by another hex number. If a match is found, then the hex numbers are placed in $1. The right hand side of the s operator is a replacement string. It is normally interpolated (or treated as a double quoted string), except when the e modifier is included. In this case the e modifier executes the replacement or right hand side of the s operator. The result of the execution of the right hand side will replace the percent sign followed by a hex number followed by another hex number in $name. The g modifier will do this repeatedly. This is all explained in more detail in the file 'perlop' under the Quote and Quote-like Operators section. You can read about the pack() function in 'perlfunc'. : $name =~ tr/\0//d; ### replaces zero values to empty In this case \0 is equivalent to ASCII 0 or chr(0). The d modifier deletes matched, but unreplaced characters in $name. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 Help.
Sara wrote: : Need help to remove EVERY thing (non-alphabets, symbols, : ASCII codes etc) from a string except for a-zAZ, 0-9, : dash and underscore. : : $string =~ s/?? Read perlop: Quote and Quote-like Operators $string =~ tr/-_a-zA-Z0-9//cd; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Win32 - determining if a file is a directory
Mark Harris wrote: # Always use strict and warnings. use strict; use warnings; : use Win32::File; : $dirspec = c:\\xfer; # / is the preferred perl directory separator # (even on windows). my $dirspec = 'c:/xfer'; Following Tom's advice we might do this. : opendir(DS, $dirspec); # Always check I/O operations for success. opendir DS, $dirspec or die qq(Cannot open $dirspec: $!); : while($fn = readdir(DS)) # $fn is not a descriptive variable name. while ( my $filename = readdir DS ) : { : if ( -d $fn) # Prepend path info on file tests. if ( -d c:/xfer/$filename ) HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Another (hopefully more clear) plea for help with CSV data
Ralph H. Stoos Jr. wrote: Perl is a name, not an acronym. Write Perl or perl, but never PERL (unless you are yelling). : OK, so here is the task. The first row I want to turn into : variable names. Machine, PurgeSuccess, etc. You probably don't want to do that. You may end up needing symbolic references to access those variables. Using symbolic references is frowned on. Another approach might use a hash which has keys that match the column names. The values associated with those keys would reference arrays of values from all the records. : Then with that removed the real work happens. The script would : then request which variables I would like to sort on or find : records (rows) that contain the matches specified. Are you going to rewrite the script for each different record search? How often will different searches be needed? Who decides the need for new searches (you, the boss, other programmers, users, etc.)? HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Trying to add hyperlink
Prabu wrote: : use CGI qw/:standard/; [snip] : th(['','A HREF=#Network Switch/A','A HREF=#Bay 1/A','A : HREF=#Bay 2/A','A HREF=#Bay 3/A' ,'A HREF=#Network : Switch/A' ]), Sorry, that will produce invalid xhtml 1.0 Transitional, the default DOCTYPE for CGI.pm. Better to use the a() function already loaded into the main namespace by the 'use' statement. It will automatically change the output should the -noxhtml CGI.pm pragma is added later. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Trying to add hyperlink
', 'Bay 2', 'Bay 3', 'Network Switch' ] ), row( 'Enclosure 1', '/' = 'Bl20p G2', '/' = 'yes', '/' = 'yes', ), row( 'Enclosure 2', '/' = 'no', '/' = 'no', '/' = 'yes', ), ], ), ), $q-end_html(); sub row { my $q = CGI-new(); my $name = shift; return $q-th( 'Enclosure 2' ) . $q-td( anchors( @_ ) ); } sub anchors { my $q = CGI-new(); my @anchors = @_; my @return; while ( @anchors ) { push @return, $q-a( { -href = shift @anchors }, shift @anchors ), } return [EMAIL PROTECTED]; } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Another (hopefully more clear) plea for help with CSV data
Chad Perrin wrote: : On Thu, Jun 22, 2006 at 03:07:32AM -0500, Charles K. Clarkson wrote: :: ::: OK, so here is the task. The first row I want to turn into ::: variable names. Machine, PurgeSuccess, etc. :: :: You probably don't want to do that. You may end up needing :: symbolic references to access those variables. Using symbolic :: references is frowned on. Another approach might use a hash which :: has keys that match the column names. The values associated with :: those keys would reference arrays of values from all the records. : : I must be missing something. Please explain the sentence You : may end up needing symbolic references to access those variables. Ralph wants to create variables named as columns. Since each variable will hold an array, he will probably go with these. @Machine, @PurgeSuccess, @PurgePrepared, @PurgeStarted, @PurgeCauseFaultID, @PurgeModId, @PurgeStopModId, @ModIdJobCfg, @NameJobCfg, @Full_cfg, @FinisherCfg, @plex, @PPM, @PropID, @AtreeNodeID, @JobID, @MediaID, @Width, @Height, @Color, and @Weight Assume Ralph writes a generic program which allows the user to define searches using column names. Problem: How do we use the variable with only the column name? Assuming the column name is in variable named $column_name, this comes to mind. Note that @ModIdJobCfg cannot be lexically scoped. Neither can the other 20 variables above. # For testing. Normally comes from user. my $column_name = 'ModIdJobCfg'; # For testing. This data would normally come from a file. our @ModIdJobCfg = 1 .. 3; { no strict 'refs'; print $_\n foreach @{ $column_name }; } If we used a hash of arrays, we would be able to avoid symbolic references. Note that we can also test for column name availability easier with the hash as well. # For testing. Normally comes from user. my $column_name = 'ModIdJobCfg'; # For testing. This data would normally come from a file and # contain more keys. my %jobs = ( ModIdJobCfg = [ 1 .. 3 ], ); print $_\n foreach @{ $jobs{ $column_name } }; : : Are you going to rewrite the script for each different : : record search? How often will different searches be needed? : : Who decides the need for new searches (you, the boss, other : : programmers, users, etc.)? : : Why would he need to rewrite the script? To do a significantly different search. If he's not rewriting the script than he is creating his own query lanqage. : Why couldn't it just loop through input data to (for instance) : create an array containing each row, starting with the column : headings row, then shift from each array to name new arrays from : the column headings row and populate it in order from the other : rows? I was asking questions, not making statements. If the searches are going to change regularly and if non perl programmers are going to do the searches, then Ralph is basically creating his own SQL language and a database may be a better solution. If only perl programmers are going to do the searches then they can just rewrite the script each time they do new search. I don't know what Ralph needs, hence the reason for my questions. : I'm not saying that's necessarily the best way to do it, but it : seems like a reasonable example of how the script could just : dynamically handle different data from each run if need be : without having to rewrite it each time. Some search functions : could be created that simply take input that allows for search : terms to be specified when the script is run. Voila, it works. : Did I misunderstand your point? I wasn't making a point. I was asking for more information. That's why all the sentences had question marks at the end. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 creating variables from a CSV file
Ralph H. Stoos Jr. wrote: : The part I can't seem to get going has to do with making : variables out of the header row in the CSV file. The way it : needs to work is that the first row may be of differing lengths : (extra fields). So, the first row defines the names of columns on each subsequent row (or line) of the CSV file. : I want to have the standalone PERL script to make the variables : and then allow the user to sort the data based on the contents : of the columns (i.e. pull out the records that match one or more : criteria). When you say records are you referring to columns or rows? How are you defining the term variables? If you mean you want a data structure which will hold selected columns from a CSV file, then it's a fairly trivial exercise. Use a hash to hold array references of column values (a HOA in perldsc in the docs). Key the hash on the column names you have selected. : The final product would allow me to select the file, specify : some thing like the value of the PPM or Grain (and : combinations thereof), and write the output to a new CSV file. You can access the fields of each row by using Text::CSV_XS or Text::CSV_PP. These modules will also allow you to write properly formatted CSV files. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: uninitialized value error
Smith, Derek wrote: : I am getting the following error yet the script is doing what : I need it to do restart a process: : : Use of uninitialized value at /usr/local/admin/named_monit.pl : line 71 (#1) It seems that when the test on line 64 is true, $arry[0] is not defined (and not initialized) and throws this error. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: uninitialized value error
Smith, Derek wrote: : Charles K. Clarkson wrote: : : : It seems that when the test on line 64 is true, $arry[0] : : is not defined (and not initialized) and throws this error. : : I thought that was the problem initially but tested it and I do : see this element populated on lines 64 and 65 : : 61 for (;PS;) { : 62 push @arry, (split)[1]; : 63 } : 64 print $arry[0],\n; : 65 print scalar @arry,\n; : 66 : 67 if (scalar defined @arry 1) { : 68 print LOG named was not running, now restartng\n, dateme(); : 69 system (echo named dubdns02|mailx -s named $oncall); : 70 system (/sbin/init.d/named start); : 71 } : 72 print $arry[0],\n; : 73 : 74 open (PSO, ps -p$arry[0] -o vsz |) or die unable to spawn ps -p $!; : : __OUTPUT__ : : 7431 is the PID. : : csdns03# perl named_monit.pl : 7431 : 1 : 7431 Did line 74 throw the uninitialized warning in this case? The original line 64 (now line 67) simply tested @arry 1. Such an array would have no elements in it. $arry[0] would have no value in it. If line 64 tested false, as in this case, then the warning should not have appeared. Something like this might avoid the error. if ( @arry 1 ) { print LOG named was not running, now restartng\n, dateme(); system (echo named dubdns02|mailx -s named $oncall); system (/sbin/init.d/named start); } else { local *PSO; open PSO, ps -p$arry[0] -o vsz | or die unable to spawn ps -p $!; while (PSO) { next if /\D/; exit 1 if $_ VSZ; print LOG named vsz reached over 60mb, now stopping starting\n; print LOG dateme(), \n; namedchk(); } close PSO; } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: unscrambler speedup rewrite
Jeremy Kister wrote: I'm wondering how others could write to code so that it'd find words faster. You don't say where the speed problem is. There are two distinct parts to your script. Loading the dictionary and finding the scrambled word. The scrambling algorithm depends on splitting every same length word in the dictionary into a character array and then comparing each character against the characters in the selected word or words. A better choice might compare entire words. You could massage the dictionary entries in another script into a hash with two words for each entry. The second entry would contain all the words of each alphabetized letter arrangement. Assuming these are the only 3 letter words in the dictionary, each entry might look like this. aet = [ 'ate', 'tea', 'eta', ], art = [ 'rat', 'tar', 'art', ] foo = [ 'foo' ], Store the dictionary hash with Storable or with DBM::Deep and access it as a hash in the guessing part of the script. In the data massaging script we might use this to stuff words into the hash (warning: untested code). Note that this code only needs to be run when the dictionary changes, not each time the scramble script runs. use strict; use warnings; use Storable 'store'; my $dir = $ENV{'HOME'}/data/dictionary/; opendir my $dh, $dir or die qq(Cannot open $dir: $!); my( %dictionary, $word_count ); foreach my $file ( grep {/^english-word/} readdir $dh ){ open my $fh, $dir$file or next; while ( my $word = $fh ) { next if $word =~ /[^a-z]/; chomp $word; my $alpha = join '', sort split //, $word; push @{ $dictionary{ $alpha } }, $word; $word_count++; } } close $dh; store( \%dictionary, 'scramble.db' ); # Feedback. printf Stored %s words in %s keys\n, $word_count, scalar keys %dictionary; __END__ Assuming the dictionary hash is in scramble.db, we might do something like this (warning: untested code). use strict; use warnings; use Storable 'retrieve'; # This loads the special dictionary. my $dictionary = retrieve( 'scramble.db' ); while (1) { print 'word: '; chomp( my $scramble = STDIN ); last if $scramble eq 'q'; ( my $alpha = $scramble ) =~ s/\s+//g; # test this to see what it does. $alpha = join '', sort split //, lc $alpha; if ( defined $dictionary-{$alpha} ) { if ( @{ $dictionary-{$alpha} } ) { print \n; foreach my $word ( @{ $dictionary-{$alpha} } ) { next if $word eq $scramble; print $word\n; } print \n; } else { print qq(Sorry, I cannot scramble $scramble.\n\n); } } else { print qq(Sorry, I cannot scramble $scramble.\n\n); } } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: scoping problem with hash
Mr. Shawn H. Corey wrote: : for ( keys %kv_pairs ){ : $hash_ref-{$_} = $kv_pairs{$_}; : } You could use a hash slice there. @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: defaults
Bryan R Harris wrote: : Is there an = also? How about or=? All perl operators are listed in the 'perlop' file. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 are the problems with my CGI script
chen li wrote: : I just try a small CGI script. Although it displays no : problem on the webpage there are two small errors in : the script. I wonder if anyone here can help me figure : out. [snip helpful code] : my $name=$query_obj-param('text_field'); : print $query_obj-p,This is your name $name, : \n\n; #line31 : : : print $query_obj-p; : my $major=$query_obj-param('menu_name'); : print This is your major $major ; #line35 On your first pass through the script the form has not been filled out, so text_field and menu_name have no associated values. CGI.pm will return there values as undef. Thus $name and $major are not initialized. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. PS You are using the paragraph tag p incorrectly. You should either use br tags or give your paragraph tags some content. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: substitute/regex etc
Dan wrote: : how can i substitute, or remove anything that's not an : alphanumerical character in a string? my $string = AbCdEF1246Hfn \n; $string =~ tr/A-Za-z0-9//cd; print qq{$string}; You can read more about tr/// in the perlop file in the docs. : i.e: : $string = AbCdEF1246Hfn \n; : $string =~ s/[^a-z][^A-Z][^0-9]//g; : : though to me, that would say: : (replace anything that's not a lower case letter as the first : char) then (replace anything that's not an upper case letter : as the second char) then (rpelace anything that's not a number : as the third char). : : or is this right? It says replace any three character sequences where the first character is not lower case, the second character is not upper case and the final character is not a digit. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- 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 are the differences between Perl and PHP when handling with Web pages
sfantar wrote: : What are the differences between Perl and PHP? You can Google for that. I found the following article. I think perl can be used for more applications than PHP. http://www.zend.com/zend/art/langdiff.php : Which one is the best to build up a website? You don't really need scripting to build a web site. I have used products written in various languages to provide complete sites. For example, I just set up a web site using Wordpress, a PHP based blog. In the past, I have used Movable Type, a perl based blog. In the latest one I knew I would be doing very little modification and the documentation is rich enough to allow the end user to manage the site without a big learning curve. In the first instance I knew I would need to modify some stuff and perl is easier for me to grasp. You can intermix languages on a web site and choose the best application for whatever job you are doing. There is little reason to restrict your site to only perl or only PHP. : There are more and more PHP-based websites. Except the : fact that ISP provide most of the time PHP/MySQL web : hosting, why do people prefer using PHP instead of Perl? Why do people like to go to the movies? Why are people vegetarians? There are as many answers to your question as there are people programming in PHP and perl. And I'm a person who prefers perl over PHP, so your question reveals at least one fallacy (complex question). I prefer perl to PHP because I can write better code in perl than I can in PHP. Some prefer PHP because they can write better code in it than in perl. Many many people write code without proficiency in either. To many of us, getting the job done, is not good enough. We want to churn quality code that is as elegant as it is functional. I can do that in perl, but not in PHP. Your question is like asking an artist why he prefers the fat brush to the thin brush. He may not have a preference. Or his preference might change with each painting, or the phase of the moon, or something indescribable. Perhaps he respects others who favor the fat brush or perhaps he has more training or history invested in the fat brush. Even after you find out why he does what he does, you can't apply that answer to all artists. His answers are personal. You'll have to interview every artist. I prefer perl over PHP because I can write more competent code in perl and because I don't see a need (today) to become a more competent PHP programmer. : I would like to create one only using Perl. Consequently, : what are the most used modules for this purpose? If I were building a house, I would not go to the hardware store and say, I'd like to build a house with this hammer. What do I do? Instead I'd go to an architect and say, I'd like to build a house. Can you help me design it? I look at user experience long before I look at which language to program scripts. Create a story board or comic book illustrating your typical, or ideal, user's experience on your web site and worry about which programming language you might prefer down the road. Build your web site for your web site visitors, not for your programming language preference. In sports there is an apt saying, Keep your eye on the ball. Your web site visitors are the ball. You are focusing on the wrong object. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Howto check a parameter size in CGI.pm
Wijaya Edward wrote: : Is there a way to determine the size of a parameter of a : textarea or filefield in CGI.pm? You can determine the length (using the length() function) of a field, but not the size of the control on the form. That information is not sent via the Common Gateway Interface. The CGI specification is available here. http://hoohoo.ncsa.uiuc.edu/cgi/ #!/usr/bin/perl use strict; use warnings; use CGI qw/param/; # Simulate form input. param( foo = Text from\na textarea control\n ); print length param( 'foo' ); __END__ You could hide information about form field sizes in hidden fields in the form. Here's is a meta field hidden in a form which also has a textarea by the name textarea_1 with 5 rows and 40 columns. input type=hidden name=textarea_1_meta value=5,40 #!/usr/bin/perl use strict; use warnings; use CGI qw/param/; # Simulate form input. param( textarea_1 = Text from\na textarea control.\n ); param( textarea_1_meta = '5,40' ); print form_field_stats( textarea_1 = 'textarea' ); sub form_field_stats { my( $field, $type ) = @_; return unless $type eq 'textarea'; my( $rows, $columns ) = split ',', param( $field . '_meta' ); return sprintf qq|The textarea $field is %s characters long.\n| . qq|\tIt is %s rows by %s columns wide.\n|, length param( $field ), $rows, $columns; } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Converting a string to a filehandle
Wijaya Edward wrote: : I would like to convert that string as if it is stored : inside a file, and bypassing the file creation step. I think you want the IO::Scalar module. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 Don't tread on my bandwidth. Trim your posts. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: login
Nenad wrote: : I use something like this Humor me and do this exactly. Show the list what the result is. Change passwords where appropriate. I am curious about whether this part works. Let's make sure it does before we move on to checking for a valid user. use strict; use warnings; use DBI; use Data::Dumper 'Dumper'; my %provera = provera_korisnika(); print Dumper \%provera; sub provera_korisnika { my $dbh = DBI-connect( DBI:mysql:evidencija, 'root', '', { RaiseError = 1, AutoCommit = 0, } ) || die Database connection not made: $DBI::errstr; my $sql = qq{ SELECT user, pass FROM login }; my $sth = $dbh-prepare( $sql ); $sth-execute(); my( $user, $pass ); $sth-bind_columns( undef, \$user, \$pass ); my %provera; while( $sth-fetch() ) { $provera{ $user } = $pass; } return %provera; } __END__ : sub provera_korisnika #Proveravam korisnicko ime i lozinku : { : $ime = $user-get_text; #this method get text from entry : $lozinka = $pass-get_text; #this to This is a really really bad practice. $user and $pass have not been passed into this subroutine. If you want help from this list, you'll need to stop writing this kind of code. Everything must pass in and pass out of the subroutine explicitly. No shortcuts. I you do not understand this, we need to start a new thread on writing subroutines. Once you can write good subroutines you will never write like this again. : $dbh = DBI-connect( : DBI:mysql:evidencija, : 'root', '', { : RaiseError =1, : AutoCommit =0 } : ) || die Database connection ^^^ What's with all this space? Edit your email better than this. Four spaces would be sufficient. Have your editor convert tabs to spaces before pasting the code to your message. Don't rely on the email program to wrap long lines. Wrap long lines yourself. : my $sql = qq{ SELECT user, pass FROM login }; : my $sth = $dbh-prepare( $sql ); : $sth-execute(); : : my( $user, $pass ); : $sth-bind_columns( undef, \$user, \$pass ); : : while( $sth-fetch() ) : { : foreach($user) : { Most looping is done over a list or array, not a single scalar. This is okay if you realize that $user is now aliased inside $_. You obviously don't know that. So you can skip the loop completely. : if( $user eq $ime) : { : print $user, $ime\n; #what if OK : } : else { Gtk2-main_quit; } #what if wrong : } : } : } : : I want if user corect do something, if not do something Build the %provera hash first. Once we know that hash is being built properly, we can then check for the correct user. Stop jumping ahead and concentrate on the hash for now. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 If it looks wrong convert it to plain 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: login
the rest of your code. Don't let it mess with exterior stuff and don't mess with its interior. Search Randal's old articles for good subroutine writing rules. I'll bet he has a lot of good advice. Here's a solution which does not use the dobijanje_iz_entrya() subroutine and builds off the sub we wrote up top. We'll probably want to use 'eq' over '==' for password checking. my %provera = provera_korisnika(); if ( $provera{ $user-get_text } eq $pass-get_text ) { print Pera\n; } HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 If it looks wrong convert it to plain 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: hash assign not working
Smith, Derek wrote: : My hash creations are not working as I expected: %hash = ( @mir, : @mir2 ); : : Why? Because nothing magical happens on the right hand side of the assignment. If I have a series of arrays over there perl flattens them into one list. It does not handle them special just because there's a hash on the right hand side. If @mir = (1, 2 ,3) and @mir2 = (4, 5, 6), then ( @mir, @mir2 ) = (1, 2, 3, 4, 5, 6) So using a little algebra, my %hash = ( @mir, @mir2 ); Is the same as this: my %hash = (1, 2, 3, 4, 5, 6); Or similar to this: my %hash = ( 1 = 2, 3 = 4, 5 = 6, ); HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 If it looks wrong convert it to plain 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: hash assign not working
Wagner, David --- Senior Programmer Analyst --- WGO wrote: : while ( @mir ) { : $hash{shift(@mir)} = shift(@mir2); :} We can also use a hash slice. my %hash; @[EMAIL PROTECTED] = @mir2; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 If it looks wrong convert it to plain 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: hash assign not working
Charles K. Clarkson wrote: : It does not handle them special just because : there's a hash on the right hand side. Whoopsie! Should be left hand side not right. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: format output from Data::Dumper
Jeff Pang wrote: : my @original=(...); : my @sort=sort {$a cmp $b} @original; : print Dumper @sort; You might like the results better using an array reference. print Dumper [EMAIL PROTECTED]; Or you could avoid the extra array with the anonymous array constructor (or is it an operator? [shrug]) print Dumper [ sort {$a cmp $b} @original ]; HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 If it looks wrong convert it to plain 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: files creating filters
badrinath chitrala wrote: : Can sombody hepl me in the below prog Can you tell us what it is suppose to do? It looks like you are trying to add line numbers to a file and print the result. : I could not get any output What is on your command line? What is in the file which is processed? Did you check to be certain that the file you are trying to open was actually opened? In other words, have you verified that the file you want perl to open is really where you think it is. HTH, Charles K. Clarkson -- Mobile Homes Specialist Free Market Advocate Web Programmer 254 968-8328 If it looks wrong convert it to plain 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: pointer to subroutine?
Bryan R Harris wrote: : Okay, I'll rename it to something else -- but I still want : it to be called _uc in my code and maybe just u : available to the user. Is this possible? Yes. You can have another sub call _uc(). sub u { return _uc(@_); } Subroutines are in the Symbol Table. You could associate (I'm not certain that is the correct term) another name with this sub using a glob. You can read more about this in Symbol Tables section of perlmod file of the documentation, but it may rob you of some sanity. :) local *convert = \_uc; Calling convert() will now do the same as calling _uc(). HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- 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 and bad words
Sky Blueshoes wrote: : I've been trying to develop some regex's to match bad words. : Just comparing against a list of bad words doesn't work that : well, because I would have to include every possible use of : a curseword, ie: bullshit, shit, shithead, etc. Oh crap! Those are bad words? I thought bad words were FEMA, FDA, EPA, IRS, Homeland Security, stuff like that. : Plus looping through every word in the list would invariably : be slow. Here is an example of one such regex: : : /(?:bull)shit/i : : My problem here is getting the ending on there. I want this : regex to also match the words, shithead, shitter, etc, etc. Have you looked at the Regexp::Common::profanity module. If it doesn't fit your need, perhaps the source can give a few pointers. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: scalar on a populated hash.
Smith, Derek wrote: : I do not understand why scalar is returning me 2/8? Also isn't : scalar %hashname the recommended way to get a count of the key : or values in any hash? No. Try this. scalar keys %sc Or: if ( keys %sc ) { : My goal is to get a count of the values in each hash. It should be the same as the number of keys. [snip] : my ($key,$value) = 0; Why scope these variables way out here? Outside the loop and outside the block they are actually used in. : foreach (SC) { : next if (/\A#/g); : if ( /(?i)savecrash=\d+/ || /(?i)savecrash_dir=\W+\w+/ ) { : chomp; : ($key,$value) = split/=/; These need only be in this scope. my($key, $value) = split/=/; : $sc{$key} = $value; : : } : : } : print SCALAR VALUE\t:, scalar %sc,\n; : if (exists $sc{$key} ) { : while (($key,$value) = each %sc) { These need only be in this scope. while ( my($key, $value) = each %sc) { : print $key\t:$value\n; : : } : : } [snip] : my ($key1,$value1) = 0; : foreach (CC) { :next if (/\A#/g); :if ( /(?i)crashconf_\w*/ || /(?i)crash_\w+\W+/) { :chomp; :($key1,$value1) = split/=/; :$cc{$key1} = $value1; Why use new key/value variable names? Perl doesn't force you to do this. my($key, $value) = split/=/; $cc{$key} = $value; :scrash_excluded_\w+\W+//gi; :} :} [snip] : #if (scalar $cc{$key1} = 1 ) { : print SCALAR:\t,scalar $cc{$key1},\n; :while (($key1,$value1) = each %cc) { :print $key1\t:$value1\n; These need only be in this scope. while ( my($key, $value) = each %cc) { print $key\t:$value\n; : :} : :#} : HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: has key/value pairs
Smith, Derek wrote: : I need to create a hash with a key/value pair as text:nontext : like so: : savecrash as the key and 1 as the value : : savecrash_dir as the key and /var/adm/crash as the value. : : for (;SC;) { : : if ( /(?i)savecrash=/ || /(?i)savecrash_dir=\W+\w+/ ) { : : chomp; my( $key, $value ) = split /=/; $vg{$key} = $value; : $vg{$_}++; Delete that line. You can read more about the split() function in the perl documentation. : : } : : } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: has key/value pairs
Smith, Derek wrote: : Excellent... thank you. Before sending the email question, I : was trying to use split to get rid of that and could not get : it to work as I was using : code : : For (FH) : If (/pattern/) { :split /\=/ ,$_ /; :$vg{$_}++ : } : } : /code : : Why didn't this work? Because it is wrong on so many levels. Seriously, assuming the capitalization of for and if are typos, you can't just add a slash / wherever you want to and expect perl to know why. Assuming that trailing slash is also a typo, And you really meant this ... for (FH) if (/pattern/) { split /\=/, $_; $vg{$_}++ } } ... then there are still problems. First split() returns a list of values, but you are not capturing that list. I think that split() defaults to placing its values in @_, but you are not accessing that here and it is deprecated. All the work is being done in $vg{$_}++ which ignores the split() and increments the value associated with the key in $_. That one of those key/value pairs happens to be correct is just coincidence. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: generate list in increments of 10's
Mike Blezien wrote: : is there a simple way to generate a list of numbers from : 0 - 1000 in increments of 10 IE: 0, 10, 20, 30, 40. ...etc No offense intended, but is this a homework problem? HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CGI - Tables and Stylesheet
Mark Martin wrote: : I'm new to stylesheets - currently my html report picks the : style for a table from the stylesheet but I have a number : of table printing on my html report and I'd like to format : each differently. : : here's the table code : : [snip code] Okay, so what is your question? Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: CGI/Includes question
Steve Gross wrote: : The problem is that the .shtml file contains includes. When my : template-out method calls the .shtml file, the includes are simply : passed along and not parsed. Use a redirect. Create the .shtml file with your program and then redirect to that .shtml file. Apache will then process the SSI includes of the .shtml file. BTW, there is a H::T mailing list made exclusively for H::T questions. https://lists.sourceforge.net/lists/listinfo/html-template-users HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- 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 our across blocks
Anthony Ettinger wrote: : #!/usr/bin/perl -w : : use vars qw($foo); #globals; : use strict; : : sub foo { : $foo = 'foo'; : my $baz = 'baz'; : } : : my $baz = 'pre-baz'; : foo(); : : print $foo, \n; : print $baz, \n; I think the problem we are having is why use a solution which resorts to global variables when lexical variables get the job done fine? use strict; use warnings; my $baz = 'pre-baz'; my $foo = foo(); print $foo, \n; print $baz, \n; sub foo { my $foo = 'foo'; my $baz = 'baz'; return $foo; } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- 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 our across blocks
Anthony Ettinger wrote: : #!/usr/bin/perl -w : : use vars qw($start_time $end_time); : use strict; : : BEGIN { : $start_time = time(); : } : : sub log_time { : my $exit_code = shift; : my $elapsed_time = $end_time - $start_time; : : print $elapsed_time, \n; : } : : END { : $end_time = time(); : log_time($?); : } : : __END__ BEGIN { my $start_time = time(); sub log_time { # my $exit_code = shift; print time() - $start_time, \n; } } END { log_time($?); } Or, if this is not a persistant perl enviroment, like modperl, just this. END { # $^T is the time at which the program began # running, in seconds since the epoch. print $^T - time(), \n; } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- 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 the function of BEGIN in perl
chen li wrote: : Recently I read some source codes of perl modules. I : find some codes look like this: : : BEGIN {..} : : What is the function of BEGIN here? Read BEGIN, CHECK, INIT and END in the perlmod file. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Replying to the perl list (was Re: problem with whitespace not splitting on split.)
Randal L. Schwartz wrote: : Oh geez. Here we go again. : : Please read http://www.unicom.com/pw/reply-to-harmful.html. : And understand that *no* list managed at lists.perl.org will : *ever* have reply-to set. Thank goodness. :) : : Your other lists coddle to the beginners who can't operate their : mail client, at the expense of experts who *can*. Let's not : hobble the experts, or the experts will go away. In practice, I use two types of replies. One to all the list recipients and one to only the author of this particular message. It's silly to send the message to the entire list and send a duplicate to the author. (He already has a copy because he is a member of the list.) PBML on Yahoo Groups uses munged Reply-To addresses. I have contributed to that list for about 6 years. I understand that it will never change this option. Thank goodness. I like not having to use reply to all and then delete addresses like I do on the list.perl.org lists. I am willing to give up my freedom in exchange for a sane reply choice. What we probably need is unmunged Reply-To addresses and mail clients which allow custom reply choices. Then the experts and we young whipper snappers can both be happy. :) HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Replying to the perl list
Russ Foster wrote: : I thought this was a beginners list? It's a Perl beginner's list not an email beginner's list. If I choose to find answers to my problem in an encyclopedia I would first learn the correct method to use the encyclopedia then I would be able to use that resource correctly. The same is true of a technical email list. If I choose to use a technical email list for answers I would first read up on the etiquette for using that list then I would be able to use that resource correctly. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- 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 whitespace not splitting on split.
Mr. Shawn H. Corey wrote: : On Wed, 2006-26-04 at 15:22 -0500, Rance Hall wrote: : : @domain = split /\s+/, $domainlist; : : It's not splitting on whitespace since you are telling it to : split on a single space character (ASCII 0x20). I thought a single space character was whitespace. Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: clarification abt system function
[EMAIL PROTECTED] wrote: : Hi All, : :I was unable to resolve the following lines.Could any one : please help me resolve the same? What do you mean by resolve? That word may not mean what you think it means. Try rephrasing your question. : I could not find any user defined module named system. : : System-get_renv(); : System-get_receiver_dir(); Show us more code and tell us what you are trying to do. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- 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
Johannes Ernst wrote: : I also realize that Cpan exists ;-) but that this piece of code : isn't quite ready to go into Cpan, which is why I didn't put it : there. I'm only posting this in the hope that somebody, one day, : may think it could be marginally useful. That's all. I'm making : no claims that it will address world hunger ... ;-) CPAN is not just for modules. You can post code there as well. Some of the code on CPAN is pretty old. It would be nice to get more recent code. Even the instructions are old. http://www.cpan.org/scripts/submitting.html BTW, I think indent() could be rewritten. I think these do the same thing as your indent(). sub indent { my $indent = shift; return '' unless defined $indent; return '' x $indent; } # Or: sub indent { return '' unless defined $_[0]; return '' x $_[0]; } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: sorting an array of arrays by arr_el[$idx][2] (or something like that)
Ed wrote: : my @lineArray; : while(F) : { : # if the line is a net localgroup line add it to the array : if( $_ =~ $s_criteria ) You probably should be testing against a regular expression. if ( $_ =~ /$s_criteria/ ) Or just: if ( /$s_criteria/ ) : { : print FOUND localgroup line:- $_\n; : split /\s/; This form of split() is deprecated. You should be receiving an error for this. : push( @lineArray, @_ ); ---no it's an array of arrays. An array of arrays is a short name for an array of array references. Array elements can only hold scalar values and arrays are not scalars. References to arrays are scalars. push @lineArray, [EMAIL PROTECTED]; Or: push @lineArray, [EMAIL PROTECTED]; Or bypassing the deprecated form of split(): push @lineArray, [ split ' ' ]; : # print @lineArray; : } : : Can someone set me straight or provide an alternate method? use strict; use warnings; . . . my @unsorted; while ( F ) { push @unsorted, [ split ' ' ] if /$s_criteria/; } Once you actually get an array of arrays you can try the Sort::ArrayOfArrays module to sort it. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Cannot access file because it is being used by another process
Ed wrote: : What's odd is that this code runs fine if I run it as a : command line script, but if it's run as a CGI script if : fails. So, what you're saying is that this error may be coming from your host and not from perl. Running your error through Google reveals it to be an IIS 6.0 error. Are you using IIS 6.0? http://support.microsoft.com/kb/890015/en-us Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: verify if e-mail is returned
Cristi Ocolisan wrote: : Hi all, : : I'm trying to develop a system to send mass mailing. : In order to do that I already developed the script, but I faced : some problems when I ran it. (I'm using MySQL to store the e-mail : addresses) : : 1. It seems that I have to LIMIT the number of addresses (to max. : 100) when I send a message. Why do you have to do that? What happens when you use 101 email addresses? Is this a limit of your mail server, MySQL, or of the module you are using to send bulk mail? : 2. I cannot verify if the message is received or it came back to me, : unless I read the maillog on the server. You need a module which reads the maillog on the server. Did you search for a mail module like that at CPAN? Perhaps one that looks for bounced email might do. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response