[23913] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6115 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 11 14:06:10 2004

Date: Wed, 11 Feb 2004 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Feb 2004     Volume: 10 Number: 6115

Today's topics:
    Re: automatically send http header <glex_nospam@qwest.invalid>
    Re: Forgetting how to use vec (Aaron Sherman)
    Re: Help with https request (Michael Tully)
    Re: how to convert a string to an escaped string (Jon Landenburer)
    Re: How2 prevent perl's searching "std directories"? <bart.lateur@pandora.be>
    Re: Include data in a perl program? <ThomasKratz@REMOVEwebCAPS.de>
        Matching multiple lines with regexp <mix@anon.lcs.mit.edu>
    Re: Matching multiple lines with regexp <tadmc@augustmail.com>
    Re: Performance patch to Parse-Yapp 1.05 <clint@0lsen.net>
    Re: Perl usage these days? <bmb@ginger.libs.uga.edu>
    Re: Perl usage these days? <rdover@ev1.net>
    Re: Perl usage these days? <ThomasKratz@REMOVEwebCAPS.de>
    Re: perl/korn scirpt for appending first variable to en <beardy@beardy.net>
    Re: perl/korn scirpt for appending first variable to en <barmar@alum.mit.edu>
        Regular Expression Help Needed (Deja User)
    Re: Regular Expression Help Needed <lallip@dishwasher.cs.rpi.edu>
    Re: Regular Expression Help Needed <noreply@gunnar.cc>
    Re: Regular Expression Help Needed <bruce-news@hartweg.us>
    Re: RFC: utils.pm <peter@semantico.com>
    Re: RFC: utils.pm <tassilo.parseval@rwth-aachen.de>
    Re: RFC: utils.pm <uri@stemsystems.com>
    Re: RFC: utils.pm thumb_42@yahoo.com
    Re: RFC: utils.pm <tore@aursand.no>
    Re: Search and replace string <ian.cass@mblox.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 11 Feb 2004 10:24:26 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: automatically send http header
Message-Id: <0HsWb.131$C%.26357@news.uswest.net>


> [Tuesday 10 February 2004 00:06]Alex Shi (chpshi@stonix.com) wrote:
> 
> 
>>With php you don't need to explicitly send http header before
>>print or echo. However in perl you need it. Even with mod_perl
>>you have to issue following before any http output
>>
>>print "Content-type: text/plain\n\n";
>>
>>I am just wondering if it possible to add a command in Apache
>>configuration so that we don't need the line of sending header
>>in perl script?


And your perl question is??? (Hint: You're posting this question to the 
wrong group.)

The answer: Yes.  Read the mod_perl documentation: 
http://perl.apache.org/docs/2.0/user/config/config.html


------------------------------

Date: 11 Feb 2004 08:14:50 -0800
From: ajs@ajs.com (Aaron Sherman)
Subject: Re: Forgetting how to use vec
Message-Id: <eaa2c627.0402110814.73e1feff@posting.google.com>

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message news:<c00r3f$3f4$1@canopus.cc.umanitoba.ca>...
> In article <eaa2c627.0402061000.2c9dfe4c@posting.google.com>,
> Aaron Sherman <ajs@ajs.com> wrote:
> :I have a small piece of Perl code that does something like this:
>  
> :  for($i=0;$i<length($x);$i++){
> :    vec($y,$i*7,8)=vec($x,$i*8,8);
> :  }

> $i*7 and $i*8 are offsets. Your code does this if $x is 'PerlOneTwo'

That part I knew. What I always forget is that the BITS argument is
not a length like it is for substr, but a block-size, used to compute
the number of bytes (not bits, even though it's measured in bits) of
the OFFSET.

This is annoying because it means that the above does not work the way
the documentation seems at first glance to suggest, and worse:

  vec($y,$i,7)=vec($x,$i,8);

which is EXACTLY what I want does not work because vec is really only
operating in bytes, even though that third parameter is in bits, so it
throws an error about 7 bits being invalid :-(

I think it's time for me to write a module that implements a generic
version of vec (obviously with a different calling convention).


------------------------------

Date: 11 Feb 2004 08:23:57 -0800
From: michael@dntenterprises.com (Michael Tully)
Subject: Re: Help with https request
Message-Id: <395feb14.0402110823.5b9e34c1@posting.google.com>

"gnari" <gnari@simnet.is> wrote in message news:<c0cq7s$j97$1@news.simnet.is>...
> "Michael Tully" <michael@dntenterprises.com> wrote in message
> news:395feb14.0402102046.59c7ac33@posting.google.com...
> > I am trying to get a page from a secured site that uses digital
> > certificates and https. I am using LWP and CRYPT::SSLEAY for accessing
> > the site. The question that I have has been perplexing me for days...
> >
> > If I go to the site and request the page in question, I can do a 'View
> > Source' and see all the <Option> tags just fine within the only form
> > that is on the page, but when I request the page via LWP, I get the
> > first <Option> tag (Which happens to be the one that is 'selected'),
> > but then the rest do not show up.
> 
> maybe you are just printing the content to a terminal. if the option
> tags are in lines terminated only with \r, it may look like some
> lines are missing
> 
> output it to a file and examine it by using a browser, or a tool like 'od',
> or just do s/\r/\n/g before printing
> 
> gnari

Well, it was a good thought, but still no dice. I have gone to several
other web sites and have been able to get the option tags. I have even
gone to other pages on the same site and have been able to get the
option tags. For some reason, this page will just not display those
tags and it is stumping me. ARRRRGGGGGGGHHHHHHH!


------------------------------

Date: 11 Feb 2004 08:24:27 -0800
From: jon.m.landenburger@verizon.com (Jon Landenburer)
Subject: Re: how to convert a string to an escaped string
Message-Id: <feee7535.0402110824.6bd6c6d@posting.google.com>

Lowell Kirsh <lkirsh@cs.ubc.ca> wrote in message news:<c0ct1k$qgu$1@mughi.cs.ubc.ca>...
> I want to convert:
>    blah blah "foo" blah
> to
>    blah\ blah\ \"foo\"\ blah
> 
> Is there an easy way to do it?
> 
> Lowell

#!/bin/perl
$A = 'dogs "bark" and cats "meow"';
print "$A\n";
$A=~s- -\\ -g;
print "$A\n";

give
!./a.pl
dogs "bark" and cats "meow"
dogs\ "bark"\ and\ cats\ "meow"
[Hit return to continue] 

$A=~ s- -\\ -g

=~  says evaluate this expression
s   says substitute
-   next charater after s is a delimiter
    the three delimiters define a before and after
    the before is  a " "
    the after is a "\"
g   says global. do it for all occurrentces of the before pattern
(instead of the first.


------------------------------

Date: Wed, 11 Feb 2004 16:06:37 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How2 prevent perl's searching "std directories"?
Message-Id: <ujkk20lmkv4i0o7p1cf6vrgnagg1lit57h@4ax.com>

kj wrote:

>Is there a way to prevent perl from searching "standard" directories
>when looking for library files?  Is there a way to set (as opposed
>to append to) @INC on the command line when invoking perl?

Look into the lib pragma. Usually you use  it as

	use lib '/path/to/lib';

in a program, or as 

	-Mlib=/path/to/lib

on the command line, but you can do 

	no lib '/path/to/remove';

as well. For the command line, insert a "-" right after the "M":

	-M-lib=/path/to/remove,/another/path/to/remove

-- 
	Bart.


------------------------------

Date: Wed, 11 Feb 2004 17:20:18 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Include data in a perl program?
Message-Id: <402a5739.0@juno.wiesbaden.netsurf.de>

David O in Seattle wrote:
> Hi,
> 
> I'm not sure out to do this, and Google searches didn't seem to yield
> well for me (perhaps I used the wrong terms) so I thought I'd see if
> someone can point me in the right direction.
> 
> I'm writing a PERL script to use the Win32::TieRegistry module and
> Win32API::Registry module.  I noticed in Registry that there are calls
> to load registry hive data into a module.  What I would LIKE to do is
> include that hive data in a scalar or similar object for use by the
> "RegLoadKey" call so I don't have to include a separate .reg file when
> I distribute my code.
> 
> Suggestions/Guidence would be very appreciated.. TIA.
> 

What about using Data::Dumper to dump a complete Win32::TieRegistry tree
to text and store that below the __DATA__ token? Later you can eval the
text data back to a hash and feed it again to Win32::TieRegistry.
Perhaps you'll have to set a few of the Win32::TieRegistry options like 
'ArrayValues' or 'DualBinVals' to get a true 1:1 save nad restore.
I haven't tested it myself, but it should be possible.

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


------------------------------

Date: 11 Feb 2004 18:00:02 -0000
From: lcs Mixmaster Remailer <mix@anon.lcs.mit.edu>
Subject: Matching multiple lines with regexp
Message-Id: <20040211180002.9304.qmail@nym.alias.net>

If I want to match two words appearing on two lines, how's it done?

  dog
  cat
  
  
if $match =~ /^dog  . . . \n . . . cat/  . . .  ????????????????????





------------------------------

Date: Wed, 11 Feb 2004 12:46:38 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Matching multiple lines with regexp
Message-Id: <slrnc2ku4e.9ie.tadmc@magna.augustmail.com>

lcs Mixmaster Remailer <mix@anon.lcs.mit.edu> wrote:

> If I want to match two words appearing on two lines, how's it done?


   perldoc -q line

       I'm having trouble matching over more than one line.  What's wrong?

       How can I pull out lines between two patterns that are themselves on
       different lines?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 11 Feb 2004 16:49:11 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Performance patch to Parse-Yapp 1.05
Message-Id: <slrnc2kn87.6nq.clint@poly.0lsen.net>

On 2004-02-11, John M. Gamble <jgamble@ripco.com> wrote:
>
> Maybe to ensure that the patch actually gets implemented, you could post
> this to a modules group, and cc the author of the module?

Thanks for the suggestion.

I've sent questions to the author over the past couple months and didn't
hear squat, so I can only assume that he's either not maintaining or not
interested in answering questions about it.

-Clint


------------------------------

Date: Wed, 11 Feb 2004 12:19:20 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Perl usage these days?
Message-Id: <Pine.A41.4.58.0402111218100.11554@ginger.libs.uga.edu>

On Wed, 11 Feb 2004 thumb_42@yahoo.com wrote:
>
> I wonder, do you folks think maybe perl is declining because people are
> waiting for perl 6? (and adopting different languages in the meantime?)
>

Perl isn't declining.  It's the most-used language in the world, and its
market share increases daily.

Regards,

Brad


------------------------------

Date: Wed, 11 Feb 2004 18:03:43 -0000
From: "Pope Bob" <rdover@ev1.net>
Subject: Re: Perl usage these days?
Message-Id: <102krjv25j59ace@corp.supernews.com>


Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
>
>Perl isn't declining.  It's the most-used language in the world, and its
>market share increases daily.

What do you base your statement upon?

All such generalizations are wrong, including this one....

-Bob


------------------------------

Date: Wed, 11 Feb 2004 19:46:27 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Perl usage these days?
Message-Id: <402a7979.0@juno.wiesbaden.netsurf.de>

Pope Bob wrote:

> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> 
>>Perl isn't declining.  It's the most-used language in the world, and its
>>market share increases daily.
> 
> 
> What do you base your statement upon?
> 
> All such generalizations are wrong, including this one....
   ^^^
      nice one! :-) Was the joke intentional (no smiley) ?

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


------------------------------

Date: Wed, 11 Feb 2004 16:10:40 +0000
From: Beardy <beardy@beardy.net>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <pwsWb.2647$Y%6.388456@wards.force9.net>

Tony Walton wrote:
> 
> I'm on commission from the manufacturers of "<", "(" and ")".

No doubt that in Rich Teer's "Next Keyboard and Mouse" survey, you 
requested an extra line of three keys with *just* these symbols, to 
avoid the use of nasty things like shift keys ;-) Maybe even three extra 
buttons on the mouse :-)

>>
>> I prefer:
>>
>> cat infile | sed -e 's/^\([^ ]*\).\(.*\)$/\2 \1/' > outfile
>>
>> Far more legible ;-)
> 
> 
> But using up most of the world's meagre supply of backslashes.
> 

No, OJ Simpson did that :-D



------------------------------

Date: Wed, 11 Feb 2004 11:40:21 -0500
From: Barry Margolin <barmar@alum.mit.edu>
Subject: Re: perl/korn scirpt for appending first variable to end of line.
Message-Id: <barmar-AF91FC.11402111022004@comcast.ash.giganews.com>

In article <pwsWb.2647$Y%6.388456@wards.force9.net>,
 Beardy <beardy@beardy.net> wrote:

> Tony Walton wrote:
> > 
> > I'm on commission from the manufacturers of "<", "(" and ")".
> 
> No doubt that in Rich Teer's "Next Keyboard and Mouse" survey, you 
> requested an extra line of three keys with *just* these symbols, to 
> avoid the use of nasty things like shift keys ;-) Maybe even three extra 
> buttons on the mouse :-)

Lisp Machine keyboards had additional, unshifted parenthesis keys for 
this reason.  I think they were where to the right of P, where standard 
keyboards have [ and ].

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


------------------------------

Date: 11 Feb 2004 08:13:13 -0800
From: dejauser@safe-mail.net (Deja User)
Subject: Regular Expression Help Needed
Message-Id: <ba74bae9.0402110813.6a3da794@posting.google.com>

I am new to regular expressions and I can't seem to figure out
following.

(1) Regular expression should find a match, if the given string does
NOT start with 90, 91, 31, or 32.

(2) Find a match, if the string contains DNI or 'DO NOT INSTALL'
anywhere in the string.

I need two seperate expressions for (1) and (2). 

Thanks


------------------------------

Date: Wed, 11 Feb 2004 11:16:52 -0500
From: Paul Lalli <lallip@dishwasher.cs.rpi.edu>
Subject: Re: Regular Expression Help Needed
Message-Id: <20040211111440.A20515@dishwasher.cs.rpi.edu>

> Date: 11 Feb 2004 08:13:13 -0800
> From: Deja User <dejauser@safe-mail.net>
> Newsgroups: comp.lang.perl.misc, comp.lang.tcl, comp.unix.questions, alt.php,
>     comp.programming
> Subject: Regular Expression Help Needed
>
> I am new to regular expressions and I can't seem to figure out
> following.
>
> (1) Regular expression should find a match, if the given string does
> NOT start with 90, 91, 31, or 32.
>
> (2) Find a match, if the string contains DNI or 'DO NOT INSTALL'
> anywhere in the string.
>
> I need two seperate expressions for (1) and (2).
>
> Thanks
>

Well, I have no idea what all those other groups will give you, but here
you'll get a perl answer.  And btw, this sounds suspciously  like a
homework question.... naughty naughty.

$string !~ /^(90|91|31|32)/

$string =~ /(DNI|DO NOT INSTALL)/

Paul Lalli


------------------------------

Date: Wed, 11 Feb 2004 17:14:44 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regular Expression Help Needed
Message-Id: <c0dkj3$14t3vm$1@ID-184292.news.uni-berlin.de>

Didn't you find any further newsgroups where you could post your
homework questions?

Deja User wrote:
> I am new to regular expressions and I can't seem to figure out 
> following.
> 
> (1) Regular expression should find a match, if the given string
> does NOT start with 90, 91, 31, or 32.
> 
> (2) Find a match, if the string contains DNI or 'DO NOT INSTALL' 
> anywhere in the string.
> 
> I need two seperate expressions for (1) and (2).

What have you tried so far?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Wed, 11 Feb 2004 11:27:55 -0600
From: Bruce Hartweg <bruce-news@hartweg.us>
Subject: Re: Regular Expression Help Needed
Message-Id: <UBtWb.7$3P3.1@dfw-service2.ext.ray.com>



Deja User wrote:

> I am new to regular expressions and I can't seem to figure out
> following.
> 
this will help learn about REs

http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm
> (1) Regular expression should find a match, if the given string does
> NOT start with 90, 91, 31, or 32.
> 
a negative lookahead constraint is what you want:

http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm#M26

regexp {^(?!(90|91|31|32))} $input

> (2) Find a match, if the string contains DNI or 'DO NOT INSTALL'
> anywhere in the string.
> 
this is simple alternation

regexp {DNI|NO NOT INSTALL} $input


> I need two seperate expressions for (1) and (2). 
> 
> Thanks

Bruce



------------------------------

Date: Wed, 11 Feb 2004 16:20:49 +0000
From: Peter Hickman <peter@semantico.com>
Subject: Re: RFC: utils.pm
Message-Id: <402a5662$0$29814$afc38c87@news.easynet.co.uk>

Nothing in this package does anything that can't be done in Perl already 
or in the exceptional cases isn't available with greater functionality 
in existing, function specific, packages (ie Date::Calc).

In truth is looks like training wheels for basic programmers.

A perl programmer will know what $value =~ s/^\s*//; will do but unless 
they come from a basic background then they will not know what 
ltrim($value) does and having gone to the trouble of learning all your 
wrappers will have learnt nothing new.


------------------------------

Date: 11 Feb 2004 17:17:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: RFC: utils.pm
Message-Id: <c0do47$hjh$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tore Aursand:

> On Wed, 11 Feb 2004 14:02:48 +0000, Tassilo v. Parseval wrote:
>>> [...]
>>>
>>> The main question is:  Although I know that the Perl core should stick
>>> to a minimum, why isn't a module like this included?  It covers most of
>>> the traps that newbies encounters, and it offers experienced
>>> programmers to be even more lazy when programming.

>> Also, I'd find the availability of such micro-functions in the core
>> offending. Maybe it's because I suffer more from hubris than others, but
>> I really like to reinvent these small wheels in my programs each time.
> 
> Really?  It's the complete opposite for me:  I don't want to reinvent the
> wheel each time, and I certainly don't want to include heaps of modules
> for doing small, repetetive things.

Yes, this was a purely subjective point of mine. Think of a bunch of
people (the perl porters) and each one of them has a different set of
objections. 

Actually, the way decisions are made among the perl developers is quite
interesting. There is no ruling authority who eventually says that
things are going to be done this or that way (maybe the pumpking of a
branch, but he seldom uses his authority). There are no polls either.
It's just informal discussion. After a while (when all things have been
said against or in favour something) an unspoken and silent agreement
has been reached. In 90% of the cases I was eventually convinced that
the decision that was made was the right one even when I initially had a
different opinion on the matter. It's almost mystic. ;-)

>> The real reasons though for not including them is indeed the size
>> argument. A recent Perl distribution is really big and the amount of
>> code in it (that has to be maintained) scary.
> 
> I agree on this one.  The core size of Perl should always be a minimum,
> but I don't think that a module like this one would have much impact on
> the size. :)

Haha, you are too optimistic, I am afraid. :-)  If such functions ever
made it into the core, clearly they would be heavily optimized. In the
end, they'd be written in C (note that there is no core function that is
written in pure Perl). And once you are in the realms of C, seemingly
trivial things get annoying. For instance, every string function would
have to be utf8-safe. And so on and so forth.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Wed, 11 Feb 2004 17:30:26 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: RFC: utils.pm
Message-Id: <x71xp18qx9.fsf@mail.sysarch.com>

>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:

  TA>   STRINGS
  TA>     ltrim( $value ) - Removes leading whitespace from a string.
  TA>     rtrim( $value ) - Removes trailing whitespace from a string.
  TA>     trim( $value ) - Combines ltrim() and rtrim().

all too trivial for subs.

  TA>     squish( $value ) - Removes (all the) whitespace from a string.

too trivial for sub. tr/\n\r\t //d;

  TA>     split_csv( $value ) - Easy CSV splitting. (*)
  TA>     random_string( $length ) - Generates a random string $length
  TA>                                characters long.

what char set does this use? 


  TA>   CASTING
  TA>     as_string( $value, [$default] ) - Always returns a defined value,
  TA>                                       optionally $default if $value
  TA>                                       isn't defined.
  TA>     as_int( $value ) - Always returns $value as an integer.

who needs casting in perl?

  TA>     as_decimal( $value, [$decimals] ) - Always returns $value as a
  TA>                                         decimal number with $decimals
  TA>                                         numbers after the decimal point.

sprintf

  TA>     as_boolean( $value ) - Always returns $value as a boolena value (ie.
  TA>                            TRUE/1 or FALSE/0).

bah, perl doesn't need booleans.

  TA>     as_date( $value ) - Always returns $value as a date
  TA>     (YYYY-MM-DD).

and what is the input format? strftime is good enough

  TA>     as_time( $value ) - Always returns $value as a time
  TA>     (HH:MM:SS).

ditto

  TA>     as_datetime( $value ) - Always returns $value as a datetime (which
  TA>                             means combining as_date() and as_time()).

  TA>   VALIDATION
  TA>     Each of the CASTING functions also have a is_* function, which returns
  TA>     TRUE/1 or FALSE/0 depending on wether the input argument conforms to
  TA>     the datatype.


  TA>   NUMBERS
  TA>     round( $value ) - Rounds a number to the nearest integer.
  TA>     random_number( $min, $max ) - Returns a random number in the range
  TA>                                   $min to $max.

number or integer?

  TA>     format_number( $value, $separator ) - Formats a number with a given
  TA>                                           separator; 1234 becomes 1,234.

  TA>   ARRAYS
  TA>     unique( $arrayref ) - Returns only the unique elements in $array.
  TA>     intersection( $arrayref1, $arrayref2 ) - Computes the intersection
  TA>                                              of two array references.
  TA>     union( $arrayref1, $arrayref2 ) - Computes the union of two array
  TA>                                       references.
  TA>     shuffle( $arrayref ) - Returns the elements shuffled randomly.

  TA>   DATES
  TA>     now_year()
  TA>     now_month()
  TA>     now_day() - These three returns current the year, month and day.
  TA>     now_date() - Combines the three above.
  TA>     now_hour()
  TA>     now_minute()
  TA>     now_seconds() - These three returns the current hour, minute and
  TA>                     second.
  TA>     now_time() - Combines the three above.
  TA>     now() - Combines now_date() and now_time(); 'YYYY-MM-DD hh:mm:ss'.

hmm, what if you called now_hour just before and now_day just after you
cross midnight? BUG!! those should all take a time() value as input so
you can force them all to use the exact same time.

  TA>     is_leap_year( $year ) - Returns TRUE/1 if $year is a leap year.

and what if you have only time()? localtime does this

  TA>     day_of_week( $date ) - Returns the day of the week for $date.
  TA>     day_of_year( $date ) - Returns the day of the year for $date.

what is date's format?

  TA>     days_in_month( $year, $month ) - Returns the number of days in the
  TA>                                      given year/month.
  TA>     days_in_year( $year ) - Returns 365 or 366 depending on wether the
  TA>                             year is a leap year or not.

you have just reinvented (poorly) another date/time module. like
templates, everyone has to do one in their lifetime.

  TA> Well.  These are the majority of the functions I've gathered.  There are a
  TA> few more, but never mind them for now.  All the functions are written in
  TA> pure Perl, so no modules - of course - or "anything else" is required.

  TA> I find these functions very valuable when programming.  Whenever I need to
  TA> check if a date from the user is valid, I just:

  TA>   unless ( is_date($date) ) {

does that handle all possible date formats? i kinda doubt it. see the
newish suite in the DateTime:: namespace. 

  TA> This is a RFC - Request For Comment - so I want to hear what you all
  TA> thing?  Should this be a "swiss army" module in the Perl core?  I think
  TA> so.

no way it should be in the core. you have api issues and bugs. you don't
handle all possible legal inputs or outputs.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Wed, 11 Feb 2004 17:52:02 GMT
From: thumb_42@yahoo.com
Subject: Re: RFC: utils.pm
Message-Id: <6ZtWb.273160$I06.2926404@attbi_s01>

Tore Aursand <tore@aursand.no> wrote:
 
> I find these functions very valuable when programming.  Whenever I need to
> check if a date from the user is valid, I just:
> 
>  unless ( is_date($date) ) {
>      # Error
>  }

I think it's a good idea, but as you've said earlier, no one wants to
slurp in a boatload of modules to do basic things. 

Basic things is kind of a relative term, for me, the date stuff would be
really handy at times, other times I wouldn't use it at all. The
random_string() I'd almost never use. Someone else might have a LOT of use
for something like that. I'd find it useful to add a routine that converts a
24/hr time into a 12/hr am/pm time, someone else would think it'd be great if
it provided an 'input()' function that automatically handled IO flushing and
a prompt.

I guess my view is that a module or collection of code like that is really
the sort of thing that would do well in a plain text file, people who want
it just copy and season to taste. 

Thats kind of what I do sometimes. I know some where some place I've done
XYZ, but.. I don't need the whole module much less the hassles of keeping 2
copies with different versions etc... I also use 'perldoc -m Module'
just to figure out how someone else did something, then I'll implement just
that one function modified for whatever I need.

Jamie


------------------------------

Date: Wed, 11 Feb 2004 19:48:56 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: RFC: utils.pm
Message-Id: <pan.2004.02.11.18.48.55.908731@aursand.no>

On Wed, 11 Feb 2004 17:17:59 +0000, Tassilo v. Parseval wrote:
>>> The real reasons though for not including them is indeed the size
>>> argument. A recent Perl distribution is really big and the amount of
>>> code in it (that has to be maintained) scary.

>> I agree on this one.  The core size of Perl should always be a minimum,
>> but I don't think that a module like this one would have much impact on
>> the size. :)

> Haha, you are too optimistic, I am afraid. :-)  If such functions ever
> made it into the core, clearly they would be heavily optimized. In the
> end, they'd be written in C (note that there is no core function that is
> written in pure Perl).

My fault entirely:  I did _not_ mean the Perl *core*, but the set of
standard modules shipped with Perl.  Doh.  Can't blame that I haven't
slept too little in the last few days, either. :)

All the functions I listed are pure Perl at the moment.  I'm not too
familiar with C, but I understand that "XS programming" is something to
investigate further.


-- 
Tore Aursand <tore@aursand.no>
"Nothing is certain but death and taxes. Of the two, taxes happen
 annually." -- Joel Fox


------------------------------

Date: Wed, 11 Feb 2004 16:15:35 GMT
From: "Ian Cass" <ian.cass@mblox.com>
Subject: Re: Search and replace string
Message-Id: <HysWb.2049$Qd5.18951301@news-text.cableinet.net>

ajay wrote:

> i expected a clearcut solution

I think the guys here will help you to help yourself but won't do your work
for you.

--
Ian Cass




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6115
***************************************


home help back first fref pref prev next nref lref last post