Re: two questions

2009-08-04 Thread John W. Krahn
sys adm wrote: 1. why perl doesn't have a built-in strip() function? Why doesn't BASIC have built-in regular expressions? Why doesn't C have built-in strings? Why doesn't $LANGUAGE have built-in $FEATURE? Because that is the way the language was designed. each time I need to say $var =

Re: two questions

2009-08-04 Thread Uri Guttman
> "sa" == sys adm writes: sa> 1. why perl doesn't have a built-in strip() function? each time I sa> need to say $var =~ s/^\s+|\s+//g to strip the blank space before sa> and after the variable, specially if this is a CGI var. because it is so easy to write a strip thing with regexes. a

two questions

2009-08-04 Thread sys adm
1. why perl doesn't have a built-in strip() function? each time I need to say $var =~ s/^\s+|\s+//g to strip the blank space before and after the variable, specially if this is a CGI var. 2. what's the standard module or method to generate a random string, for example the string will be used as

Re: Purpose of $$ in subroutine

2009-08-04 Thread Chas. Owens
On Tue, Aug 4, 2009 at 23:07, Dave Tang wrote: > On Wed, 05 Aug 2009 12:55:22 +1000, Chas. Owens > wrote: > > snip >> >> In this case it is telling Perl that compare expects two scalars as >> arguments. > > snip > > Now the compare($$) makes much more sense. > > snip >> >> There are many [pitfalls

Re: Purpose of $$ in subroutine

2009-08-04 Thread Dave Tang
On Wed, 05 Aug 2009 12:55:22 +1000, Chas. Owens wrote: snip In this case it is telling Perl that compare expects two scalars as arguments. snip Now the compare($$) makes much more sense. snip There are many [pitfalls][2] to prototypes and they should really not be used unless you have a

Re: Purpose of $$ in subroutine

2009-08-04 Thread Chas. Owens
On Tue, Aug 4, 2009 at 19:30, Dave Tang wrote: snip >                sub compare($$) { snip > running this script, but just wanted to know its purpose in compare($$). snip Those are [prototypes][1]. They change how Perl thinks about the function call. In this case it is telling Perl that compare

Re: Purpose of $$ in subroutine

2009-08-04 Thread John W. Krahn
Dave Tang wrote: Hi everybody, Hello, I was reading perlfaq7.pod, 7.15: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}? In one of the examples it shows how regular expressions can be passed to subroutines: sub compare($$) {

Purpose of $$ in subroutine

2009-08-04 Thread Dave Tang
Hi everybody, I was reading perlfaq7.pod, 7.15: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}? In one of the examples it shows how regular expressions can be passed to subroutines: sub compare($$) { my ($val1, $regex) = @_;

Re: localtime() oddities

2009-08-04 Thread Roman Makurin
Big thanks for replying. Just modified my mktime() call : POSIX::mktime(sec, min, hour, month, year, -1, -1, 1); and now it work as expected :) On Mon, Aug 03, 2009 at 08:42:43AM -0400, Shawn H. Corey wrote: > Roman Makurin wrote: >> Could someone explain me whats goin on :) >> > > Do you have D

Re: Inverting a hash safely

2009-08-04 Thread Shawn H. Corey
Ed Avis wrote: Shawn H. Corey gmail.com> writes: Why on earth would you want to invert an XML file? What I mean is that many modules (such as XML::Twig) return data as hashes. To me, it doesn't make any sense to return both a hash and its inverse from the function. Instead I would return jus

Inverting a hash safely

2009-08-04 Thread Ed Avis
Shawn H. Corey gmail.com> writes: >>>But then again I never have to invert a hash; when I populate it, I >>>would populate its inverse as well. >>But in the particular case I was thinking of, >>there was some (programmer-maintained, not user-maintained) configuration data >>in a hash: >> >>

Re: Inverting a hash safely

2009-08-04 Thread Shawn H. Corey
Ed Avis wrote: Shawn H. Corey gmail.com> writes: But then again I never have to invert a hash; when I populate it, I would populate its inverse as well. I would build both data structures at the same time, inserting only the data I need, where I need it. That's often a good approach. But

Re: Parsing RSS feeds

2009-08-04 Thread Kwame Bahena
When you have some scripts ready, could you share them? Are you doing this for a blog? Best regards, In article <1233387242.4218.32.ca...@ar2.protva-net>, dro...@gmail.com (Roman Makurin) wrote: > В Сбт, 31/01/2009 в 09:05 +0200, Erez Schatz пишет: > > On 1/31/2009 8:45 AM, Roman Mak

Re: Inverting a hash safely

2009-08-04 Thread Ed Avis
Uri Guttman stemsystems.com> writes: > EA> foreach my $k (sort keys %hash) { > >why the sort? No terribly good reason; I just wanted the error messages to be deterministic. You could speed it up a bit by not sorting and it would still work just as well, but the error message given might in

Re: Inverting a hash safely

2009-08-04 Thread Ed Avis
Shawn H. Corey gmail.com> writes: >But then again I never have to invert a hash; when I populate it, I >would populate its inverse as well. I would build both data structures >at the same time, inserting only the data I need, where I need it. That's often a good approach. But in the particul

Re: Inverting a hash safely

2009-08-04 Thread Ed Avis
Jenda Krynicky Krynicky.cz> writes: > [inverting a hash but checking that no data is lost] >>To give a really useful error message is a bit more code: >> >>my %reverse; >>foreach my $k (sort keys %hash) { >>my $v = $hash{$k}; >>if (exists $reverse{$k}) { >>die