Re: Redirecting to another url with parameters using post method
On 08/25/2007 07:39 PM, Gunnar Hjalmarsson wrote: Mumia W. wrote: On 08/25/2007 04:32 PM, Gunnar Hjalmarsson wrote: Jeff Pang wrote: 2007/8/25, Praveena Vittal [EMAIL PROTECTED]: I want to redirect to a different url with the parameters in the post method. Well,see 'perldoc CGI' and specially check for, param, redirect. How do you combine a POST request and a 'Location:' header (which is what CGI::redirect prints AFAIK)? I think this is called a Status 307 Temporary Redirect. See RFC 2616 § 10.3.8. This is the last para of that section: If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued. So I don't think that 307 is the proper status code for a redirect via a POST request. In any case it doesn't answer the question how you do it, does it? I do wish the Praveena had been more specific about what he or she is trying to do, but, if status 307 is appropriate, this is how it can be done with CGI.pm: use strict; use warnings; use CGI; # You set the $location. print CGI::header( -status = '307 Temporary Redirect', -location = $location, ); __END__ An HTTP body should also be provided with a link to the new resource, but it is not required. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Convert int for string
On Aug 26, 2007, at 3:22 AM, Randal L. Schwartz wrote: Perl is a very strongly typed language. The problem is that people keep thinking number or string is a type in Perl. It isn't. The type is called scalar. Other types are array and hash and filehandle and dirhandle and built-in object and user-defined object. In that line, I think Perl is not as dynamically typed as other scripting languages, in the sense that sigils do put types in the source code somehow. Since Perl tries to give meaning almost to anything and context allows to add a scalar to an array, the compiler does not complain that much in practice. But from a formal point of view there are types in the code. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trying to dynamically create arrays, getting can't use string as ARRAY ref
On Aug 24, 9:11 am, [EMAIL PROTECTED] (Randal L. Schwartz) wrote: Justin == Justin The Cynical [EMAIL PROTECTED] writes: Justin The Llama presents hashes as single value to a key, so I never thought Justin to make a hash of arrays. That's because (a) an arrayref is still a single value, so we haven't really lied, so much as just simplified to what can be handled in the first 30 hours with Perl, and (b) you *still* can't make a hash of arrays, just a hash of arrayrefs, and that distinction is *important*. Ok, so it's not an array that is in the hash, but a symlink (which is a single value) to an actual array that lives in memory alone and has no real reference outside of the hash, correct? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Convert int for string
On Sat, 25 Aug 2007 18:22:13 -0700, (Randal L. Schwartz) wrote: Jeff == Jeff Pang [EMAIL PROTECTED] writes: Jeff Perl isn't a strong type language like C,so you don't have the need to Jeff convert the variable type distinctly. Perl is a very strongly typed language. The problem is that people keep thinking number or string is a type in Perl. It isn't. The type is called scalar. Other types are array and hash and filehandle and dirhandle and built-in object and user-defined object. Please stop with the perl is loosely typed nonsense. The term strong typing is so ill-defined as to make this an angels-dancing-on-a-pinhead discussion and unlikely to lead to any enlightenment. Even the Wikipedia definition says that there *is* no accepted definition and some of the common usages contradict each other. Under the interpretations I subscribe to I couldn't think of a language that would qualify as weakly typed if Perl were strongly typed, so I believe that you're apply some other interpretation. In keeping with the multiple interpretations, there doesn't appear to be any consensus about Perl's strength of typing. http://use.perl.org/~Ovid/journal/22311 sums it up well for me. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trying to dynamically create arrays, getting can't use string as ARRAY ref
On Sun, 26 Aug 2007 01:00:31 +, Justin The Cynical wrote: On Aug 24, 9:11 am, [EMAIL PROTECTED] (Randal L. Schwartz) wrote: That's because (a) an arrayref is still a single value, so we haven't really lied, so much as just simplified to what can be handled in the first 30 hours with Perl, and (b) you *still* can't make a hash of arrays, just a hash of arrayrefs, and that distinction is *important*. Ok, so it's not an array that is in the hash, but a symlink (which is a single value) to an actual array that lives in memory alone and has no real reference outside of the hash, correct? Don't use the term symlink, however tempting, or you'll confuse yourself and others about real symlinks. Yes, it's not an array in the hash; it's a scalar containing a *reference* to an array, and there may or may not be other references to that array elsewhere in the program depending on how the reference was constructed (with the anonymous arrayref constructor or with the reference to a named array). -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Convert int for string
On Aug 26, 2007, at 3:52 PM, Peter Scott wrote: The term strong typing is so ill-defined as to make this an angels-dancing-on-a-pinhead discussion and unlikely to lead to any enlightenment. Even the Wikipedia definition says that there *is* no accepted definition and some of the common usages contradict each other. I remember MJD has a nice slice about it. I don't know whether it's online though. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trying to dynamically create arrays, getting can't use string as ARRAY ref
Peter Scott wrote: Don't use the term symlink, however tempting, or you'll confuse yourself and others about real symlinks. Yes, it's not an array in the hash; it's a scalar containing a *reference* to an array, and there may or may not be other references to that array elsewhere in the program depending on how the reference was constructed (with the anonymous arrayref constructor or with the reference to a named array). Even anonymous arrays can be accessed from more than one place. #!/usr/bin/perl use strict; use warnings; use Data::Dumper; # create an hash my %a = (); # populate it $a{name} = 'a'; $a{array_ref}[0] = 'a'; # copy the hash my %b = %a; # display them print '%a = ', Dumper \%a; print '%b = ', Dumper \%b; # change the copy $b{name} = 'b'; $b{array_ref}[0] = 'b'; # display them print '%a = ', Dumper \%a; print '%b = ', Dumper \%b; __END__ -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle If you think Terrans are comprehensible, you don't understand them. Great Fang Talphon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trying to dynamically create arrays, getting can't use string as ARRAY ref
On Sun, 26 Aug 2007 12:17:49 -0400, Mr. Shawn H. Corey wrote: Peter Scott wrote: Don't use the term symlink, however tempting, or you'll confuse yourself and others about real symlinks. Yes, it's not an array in the hash; it's a scalar containing a *reference* to an array, and there may or may not be other references to that array elsewhere in the program depending on how the reference was constructed (with the anonymous arrayref constructor or with the reference to a named array). Even anonymous arrays can be accessed from more than one place. Right. I phrased that badly. The poster appeared to be wondering whether there could be another reference to the array already in existence at the time the arrayref was created in the hash and that was what I had in mind. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Dr.Ruud wrote: Why do people who write these books have exercises of little practical value? An exercise needs to be educational. I have worked in programming for 25 years and during that time I have never use a closure and have never seen one used. I may be harsh in my definitions but to me something that is never used is useless. Teaching people to do useless things is not educational. closure introduce another layer of compile/run to the program. They should be avoided. Why would a closure introduce another layer of compile/run? A closure carries an environment, so just call it an object. Dealing with a closure has two phases. A phases when its created (compiled phase) and one when it's executed (run phase). When you write a closure you have to keep the two phases in mind (and separate). For example, in the OP's problem there are three parameters: the start time, the stop time, and the staring directories. Since it doesn't make much sense to separate the start ans stop times, I shall treat them as a data set called times. There are four ways to distribute them: 1. All are parameters to the closure generator. In this case, the closure is not very flexible. What it can tell are if a file has been modified between its runs. 2. The times are closure-generator parameters and the starting directories are closure parameters. This gives a closure that can look at different directories but in the same time interval. 3. The starting directories are closure-generator parameters and the times are closure ones. This gives a closure that looks at the same directories but with different time intervals. 4. All are parameters are closure ones. This gives a closure that is very flexible but is little different from a common sub. The problem with closures is that you have to write them and their generators at the same time. So you have to keep two different phases in mind, the compile phase and the run phase, while remembering what parameters belong to which phase. Objects can do the same things as closures, which is store and hide data, but don't have this problem of having to keep in mind two phases of the same code. -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle If you think Terrans are comprehensible, you don't understand them. Great Fang Talphon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Mr == Mr Shawn H Corey [EMAIL PROTECTED] writes: Mr Objects can do the same things as closures, which is store and hide data, Mr but don't have this problem of having to keep in mind two phases of the Mr same code. But objects have fixed code with variable data. Closures can have variable code with variable data, including user-specified behavior passed in to a constructor or a mutator. So, yes, objects can do *some* of the things that closures do, but not all. Think of closures as variables that hold behavior. Sure, maybe you've never needed that in your legendary 25 years in the industry, but I've used it *frequently* in my 30 years. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Randal L. Schwartz wrote: Think of closures as variables that hold behavior. Sure, maybe you've never needed that in your legendary 25 years in the industry, but I've used it *frequently* in my 30 years. :) Why do you include an insult with every thing you post? BTW, what legends do you have on me? (web links preferred) (and nothing from stonehenge.com, independent sources only). Do they make me out as mean as you? -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle If you think Terrans are comprehensible, you don't understand them. Great Fang Talphon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Shawn == Shawn H Corey [EMAIL PROTECTED] writes: Shawn Why do you include an insult with every thing you post? I don't think I do. I was only making fun of your claim, since you made the claim. Why did you include 25 years? It just sets you up for a fall. :) Shawn BTW, what legends do you have on me? (web links preferred) (and nothing Shawn from stonehenge.com, independent sources only). Do they make me out as Shawn mean as you? Again, I don't think I've been mean. But I will knock the wind out of any air-filled claim, and you made one here. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Randal L. Schwartz wrote: Shawn == Shawn H Corey [EMAIL PROTECTED] writes: Shawn Why do you include an insult with every thing you post? I don't think I do. I was only making fun of your claim, since you made the claim. Why did you include 25 years? It just sets you up for a fall. :) Oh, I get it. When I said 25 years, you thought that I meant 25 years with Perl. Sorry, about the confusion. I have programmed in many different languages and have never seen a closure. All programming languages are Turing complete, so it is possible to create a closure in any language; meaning that if they were useful, they would appear more often. And I have never seen one (except in academia). And OK, you're not mean; you just have a mean sense of humour. -- Just my 0.0002 million dollars worth, the legendary Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle If you think Terrans are comprehensible, you don't understand them. Great Fang Talphon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Shawn == Mr Shawn H Corey [EMAIL PROTECTED] writes: Shawn Oh, I get it. When I said 25 years, you thought that I meant 25 years Shawn with Perl. No. Shawn Sorry, about the confusion. No confusion. Shawn I have programmed in many different languages and have never seen a Shawn closure. Then you've used a different set of languages from what I have. Shawn All programming languages are Turing complete, so it is possible to Shawn create a closure in any language; The second part doesn't follow from the first. Perhaps you don't understand closure well enough to be commenting on it. Shawn meaning that if they were useful, they would appear more Shawn often. Also an unsubstantiated conclusion. You're just leaping from one thing to the next here, and getting deeper in pure speculation instead of justified facts. Shawn And I have never seen one (except in academia). Then you've had a pretty narrow bit of experience for being around for 25 years. Shawn And OK, you're not mean; you just have a mean sense of humour. No, I don't think it's humor. It's just calling BS where I see it, like the message I'm reply to here. People may laugh, but the intent is communication. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File::Find
The code didnt work. Error: Can't stat /my/dir: No such file or directory at test.pl line 12 On 8/20/07, Martin Barth [EMAIL PROTECTED] wrote: On Fri, 17 Aug 2007 07:48:33 -0700 [EMAIL PROTECTED] (Randal L. Schwartz) wrote: Why not just: my @list; find sub { push @list, $$File::Find::name }, /var/SAMPLES; HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
Mr. Shawn H. Corey wrote: Dr.Ruud wrote: Why do people who write these books have exercises of little practical value? An exercise needs to be educational. I have worked in programming for 25 years and during that time I have never use a closure and have never seen one used. I may be harsh in my definitions but to me something that is never used is useless. Teaching people to do useless things is not educational. Sorry Shawn, but if you're going to claim that anything you haven't seen in your illustrious 25-year career is useless than the rest of your post isn't worth reading. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File::Find
Somu == Somu [EMAIL PROTECTED] writes: Somu The code didnt work. Error: Somu Can't stat /my/dir: No such file or directory Somu at test.pl line 12 Then you don't have /my/dir. :) I'd actually be surprised if you did. I haven't seen any systems that have /my as a top-level directory. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Redirecting to another url with parameters using post method
Mumia W. wrote: Mumia W. wrote: On 08/25/2007 04:32 PM, Gunnar Hjalmarsson wrote: Jeff Pang wrote: 2007/8/25, Praveena Vittal [EMAIL PROTECTED]: I want to redirect to a different url with the parameters in the post method. Well,see 'perldoc CGI' and specially check for, param, redirect. How do you combine a POST request and a 'Location:' header (which is what CGI::redirect prints AFAIK)? I think this is called a Status 307 Temporary Redirect. See RFC 2616 § 10.3.8. I do wish the Praveena had been more specific about what he or she is trying to do, but, if status 307 is appropriate, this is how it can be done with CGI.pm: use strict; use warnings; use CGI; # You set the $location. print CGI::header( -status = '307 Temporary Redirect', -location = $location, ); No, that prints a content-type header as well, and doesn't redirect. Suppose you meant: print CGI::redirect($location, -status=307); or, more straightforward print Status: 307\nLocation: $location\n\n; Anyway, thanks for mentioning this 'magic' status code, Mumia. I learned something new today. :) This is my understanding of how it works: When you POST a form, and the server responds with status code 307 plus a location header, the browser displays a confirm box giving you the option to resend the request to the target location, or cancel the request. If the client isn't a web browser, but e.g. a Perl script that POSTs some data, you can bypass the confirmation step: use LWP::UserAgent; my $ua = LWP::UserAgent-new; push @{ $ua-requests_redirectable }, 'POST'; $ua-post( $url, [ var1 = 'foo', var2 = 'bar' ] ); In that case, also the status code 301 Moved Permanently lets the parameters be passed on to the target location. Btw, is this technique properly documented anywhere, or would it be a suitable addition to perlfaq9? -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
In article [EMAIL PROTECTED], Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chris wrote: I'm working on yet another exercise from Intermediate Perl. I've been given a script that searches for files that fall between a two timestamps. Why do people who write these books have exercises of little practical value? Exercises are a tough thing. The trick is to: * find something that demonstrates the feature being discussed * doesn't need features you haven't shown yet * isn't saddled with a unfamiliar problem domain * can be completed with what the student likely has already installed * is limited enough that it can be completed in a reasonable time * works for the entire audience Anything with practical value is likely to not actually be very practical to someone else. In this case, sysadmins may think the exercise is very practical, but bio-informaticists may not. However, practicality is the wrong way to learn. We don't intend to teach anyone how to do a specific task. We're teaching the tools people can use to solve all sorts of different tasks. Learn to use the tool and you can do a lot. Learn a task, and that's all you can do. Please feel free to send me suggestions for different exercises for the second edition, or point me toward the book that you wrote so I can look at your exercises to see how I might make things more practical. :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: building Perl 5.8.8
In article [EMAIL PROTECTED], Robert Hicks [EMAIL PROTECTED] wrote: When it asks about threads should I enable them or no? In Perl's Configure, if you don't understand the question, accept the default answer. :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Redirecting to another url with parameters using post method
On 8/26/07, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Mumia W. wrote: snip Btw, is this technique properly documented anywhere, or would it be a suitable addition to perlfaq9? Its not a Perl technique. Its part of the HTTP specs. PS Why do my emails show up on the www.codecomments.com forum? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: subroutine references
On 8/26/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Dr.Ruud wrote: Why do people who write these books have exercises of little practical value? An exercise needs to be educational. I have worked in programming for 25 years and during that time I have never use a closure and have never seen one used. I may be harsh in my definitions but to me something that is never used is useless. Teaching people to do useless things is not educational. snip So, you have never used sort, map, grep, File::Find::find, or any of the other Higher Order functions? They all take a code block or anonymous function that makes use of closures. Oh, and in my ten years of coding experience I have only been consciously using them for the last six (when I moved from mostly ESQL/C and 4GL to mostly Perl). snip Objects can do the same things as closures, which is store and hide data, but don't have this problem of having to keep in mind two phases of the same code. snip Objects in Perl do not do a very good job of data hiding. In fact, one of the few ways to actually hide data in is to use closures (see perldoc perltoot). You seem to not understand closures or what they are useful for. I would suggest running out and getting Higher Order Perl. It will make you a better programmer (even if you are a good programmer now). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
a division warning
I run a perl command below, perl -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3;$x/$y};print hello' Useless use of division (/) in void context at -e line 1. hello I'm confused about the first warning.What's it?thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: a division warning
On 8/26/07, lists user [EMAIL PROTECTED] wrote: I run a perl command below, perl -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3;$x/$y};print hello' Useless use of division (/) in void context at -e line 1. hello I'm confused about the first warning.What's it?thanks. Let's break this down and see what is going on: perl -MO=Deparse -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3;$x/$y};print hello' Useless use of division (/) in void context at -e line 1. use warnings; use strict 'refs'; eval { do { my $x = 3; my $y = $x - 3; $x / $y } }; print 'hello'; -e syntax OK From this we can see that the result of $x/$y is not used. Perl is warning you that this is useless. However, it is not exactly useless as it is triggering a divide by zero error in the eval. The way to get rid of this warning is to make sure the result is used by a function or assigned to a variable: perl -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3; my $z = $x/$y};print hello' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Redirecting to another url with parameters using post method
yitzle wrote: On 8/26/07, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Btw, is this technique properly documented anywhere, or would it be a suitable addition to perlfaq9? Its not a Perl technique. Its part of the HTTP specs. quote NAME perlfaq9 - Networking ($Revision: 1.15 $, $Date: 2003/01/31 17:36:57 $) DESCRIPTION This section deals with questions related to networking, the internet, and a few on the web. /quote I'd say that this topic deals with using Perl in an HTTP context. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Longest prefix match
Hi, I want to implement longest prefix match in my code in perl, but am not able to get started with it. I am sure, it can be easily achieved with the help of regex in perl, but I haven't worked on it. Following is what I want to do:- If the phone number is +852 --- The country is Hong Kong +853 --- The country is Macau. I have a list of 65 such countries and their codes. I have to read a particular field in the CSV file, and on the basis of longest prefix match, assign a country to it. Thanks in anticipation, Mihir
Re: Longest prefix match
On 8/27/07, Mihir Kamdar [EMAIL PROTECTED] wrote: Hi, I want to implement longest prefix match in my code in perl, but am not able to get started with it. I am sure, it can be easily achieved with the help of regex in perl, but I haven't worked on it. Following is what I want to do:- If the phone number is +852 --- The country is Hong Kong +853 --- The country is Macau. I have a list of 65 such countries and their codes. I have to read a particular field in the CSV file, and on the basis of longest prefix match, assign a country to it. Thanks in anticipation, Mihir Don't reinvent the wheel (unless it is for fun or educational purposes): http://search.cpan.org/~dcantrell/Number-Phone-1.58/lib/Number/Phone/Country.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Longest prefix match
first build a hash which record all countries and their codes. my %countries = (852 = 'Hong Kong', 853 = 'Macau' ...); then use regex or other ways (I prefer substr) to get the prefix. my $prefix = substr($string,1,3); last get the country name via the prefix code. my $country = $countries{$prefix}; 2007/8/27, Mihir Kamdar [EMAIL PROTECTED]: Hi, I want to implement longest prefix match in my code in perl, but am not able to get started with it. I am sure, it can be easily achieved with the help of regex in perl, but I haven't worked on it. Following is what I want to do:- If the phone number is +852 --- The country is Hong Kong +853 --- The country is Macau. I have a list of 65 such countries and their codes. I have to read a particular field in the CSV file, and on the basis of longest prefix match, assign a country to it. Thanks in anticipation, Mihir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Longest prefix match
Mihir Kamdar wrote: I want to implement longest prefix match in my code in perl, but am not able to get started with it. I am sure, it can be easily achieved with the help of regex in perl, but I haven't worked on it. perldoc perlrequick perldoc perlretut perldoc perlre Good luck! -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/