[17172] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4584 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 11 14:05:37 2000

Date: Wed, 11 Oct 2000 11:05:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971287518-v9-i4584@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Oct 2000     Volume: 9 Number: 4584

Today's topics:
    Re: A lot of s///g; feels like a slow idea. mexicanmeatballs@my-deja.com
    Re: A lot of s///g; feels like a slow idea. <godzilla@stomp.stomp.tokyo>
    Re: Calculating in Perl. (Logan Shaw)
        CGI.pm & the query string (Wyatt R Johnson)
    Re: CGI.pm & the query string <jeff@vpservices.com>
    Re: CGI.pm & the query string <flavell@mail.cern.ch>
    Re: CGI.pm & the query string <rmore1@my-deja.com>
    Re: Convert array to string? <MBalenger@att.net>
    Re: Convert array to string? (Rafael Garcia-Suarez)
    Re: Convert array to string? <MBalenger@att.net>
    Re: Convert array to string? (Randal L. Schwartz)
        Cutesy Arrows - Just say no! (was Re: Convert array to  (Randal L. Schwartz)
    Re: Cutesy Arrows - Just say no! (was Re: Convert array (Rafael Garcia-Suarez)
    Re: Cutesy Arrows - Just say no! (was Re: Convert array (Randal L. Schwartz)
    Re: Cutesy Arrows - Just say no! (was Re: Convert array <MBalenger@att.net>
    Re: Cutesy Arrows - Just say no! (was Re: Convert array <MBalenger@att.net>
    Re: Defining an Operator (not overloading) <foo@bar.va>
    Re: Defining an Operator (not overloading) (Rafael Garcia-Suarez)
    Re: Defining an Operator (not overloading) <MBalenger@att.net>
    Re: Defining an Operator (not overloading) (Mark-Jason Dominus)
    Re: File::Find How to pass parameters to wanted functio (Randal L. Schwartz)
        files changes when uploading. <johan.ditmar@era.ericsson.se>
    Re: How to remove all white spaces <james@NOSPAM.demon.co.uk>
    Re: How to remove all white spaces <anmcguire@ce.mediaone.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Oct 2000 17:16:16 GMT
From: mexicanmeatballs@my-deja.com
Subject: Re: A lot of s///g; feels like a slow idea.
Message-Id: <8s278o$ill$1@nnrp1.deja.com>

In article <39E475C3.531BB3DC@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> Jimmy Lantz wrote:
>
> > I have the sub below and it's full of s///g; I think
> > I've seen a better way to do this somewhere,
>
> I am very certain you have.
>
> (snipped)
>
> There is no need to envoke a series of regex
It's 'invoke', I wouldn't normally bother with spelling
mistakes, but it highlights the big lie about your academic
qualifications.
http://www.merriam-webster.com/cgi-bin/dictionary?va=invoke

> substitution engines for your input if your
> input does not need to be filtered. Should
> your input need to be filtered, there is no
> need to envoke a series of regex substitution
> engines for each and every character to be
> filtered. You will find this code more efficient
> for your stated parameters.

But that's exactly what your code does, in a loop.

> Best of all, there is no need to use a memory
> bloating module which will also slow down your
> script, significantly.

Hmmm..... Sometimes modules are more heavy than you would
like, but you get tried, tested and corrected code.

Besides, if they use the shit you post it'll be worse, I note
you seem to have misplaced the ';' that marks the end of an
entity, not to mention carrying out a gazzilion regex
recompilations.

How about an alternative:

#!/usr/bin/perl -w
use strict;

my %translations = qw( à &agrave; á &aacute; â &acirc; ä &auml; à
&agrave; á &aacute; â &acirc; ä &auml; è &egrave; é &eacute; ê &ecirc; ë
&euml; È &Egrave; É &Eacute; Ê &Ecirc; Ë &Euml; ì &igrave; î &icirc; í
&iacute; ï &iuml; Ì &Igrave; Î &Icirc; Í &Iacute; Ï &Iuml; ò &ograve; ó
&oacute; ô &ocirc; ö &ouml; ù &ouml; ú &ugrave; û &uacute; ü &uuml; Ò
&Ograve; Ó &Oacute; Ô &Ocirc; Ö &Ouml; Ù &Uuml; Ú &Ugrave; Û &Uacute; Ü
&Uuml;);
my $char_list= '(['.join("", keys(%translations)).'])';

my $line="à, á, â, ä, à, á, â, ä, è, é, ê, ë, È, É, Ê, Ë, ì, î, í, ï, Ì,
Î, Í, Ï, ò, ó, ô, ö, ù, ú, û, ü, Ò, Ó, Ô, Ö, Ù, Ú, Û, Ü";
print "[$line]\n";
$line=~s/$char_list/$translations{$1}/gsoe;
print "[$line]\n";

Translations are best kept in a file, and loaded in at
initialization, they change a lot more than you expect.

Benchmarks:

Godzilla: 54 wallclock secs (53.81 usr +  0.01 sys = 53.82 CPU) @
185.80/s (n=10000)
My Way:  8 wallclock secs ( 8.17 usr +  0.00 sys =  8.17 CPU) @
1223.99/s (n=10000)

So, code bloat, slow, and high memory usage, sounds like your version.
I'd get paid bugger all if they were measuring klocs though.

--
Jon
perl -e 'print map {chr(ord($_)-3)} split //, "MrqEdunhuClqdph1frp";'


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 11 Oct 2000 10:39:54 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: A lot of s///g; feels like a slow idea.
Message-Id: <39E4A5EA.D9194FF7@stomp.stomp.tokyo>

mexican "Frank" meathead wrote:

>  Godzilla! wrote:
> > Jimmy "Frank" Lantz wrote:

> > There is no need to envoke a series of regex

> It's 'invoke', I wouldn't normally bother with spelling
> mistakes, but it highlights the big lie about your academic
> qualifications.

> Besides, if they use the shit you post it'll be worse, 


Gosh, was it something I said, Frank?

Godzilla!


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

Date: 11 Oct 2000 13:00:11 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Calculating in Perl.
Message-Id: <8s29rb$qm7$1@provolone.cs.utexas.edu>

In article <Pine.LNX.4.21.0010111607490.1337-100000@crocodile.iis.nsk.su>,
Paul Dortman  <paul@crocodile.iis.nsk.su> wrote:
>I'm writing program in Perl, that must perform calculation with certain
>accuracy. I'll try to explain what I mean: I need to have all
>calculations (addition, subtraction,  multiplication and division) only
>with two or three digits after decimal point.

Well, first of all it's important to note that most of the time
computers don't internally do any calculations before or after the
decimal point, because they do calculations in binary and not decimal.

Each binary digit is equivalent to about log(2)/log(10) = 0.30103
decimal digits.  So, to do three decimal places calculations in binary,
you'd need about 9.96578 binary digits.  Obviously, this cannot be
done.

So, if you really need to do this, you will need something like
binary-coded decimal.  I thought I might suggest that you look at
Math::BigFloat, but it seems to do calculations in base 100000, which
is fine but not what you want.  There is also Math::SigFigs, whose
documentation on http://search.cpan.org/ says it does calculations with
the correct number of significant figures, but I'm not sure this is
what you've asked for either.

I think perhaps the best route might be to write your own routines
that do calculation in base 10.  It's really not a terribly hard thing
to do, although it can be time-consuming.

Another approach is to convert your numbers to integers and do the
calculation that way.  So, for instance, if you want to add the numbers
3.27 and 6.89, convert them to 327 and 689, add to get 1016, and then
convert that to 10.16.  For division, you would need to multiply by 100
first, so that 3.27 / 6.89 is computed by the following steps:

	convert 3.27 and 6.89 to 327 and 689.
	compute the result 327 * 100 / 689 = 41.444866920.
	round the result to 41 (which represents 0.41).

Of course, to print that out, you have to divide by 100.

Hope that helps.

  - Logan


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

Date: 11 Oct 2000 16:35:29 GMT
From: wjohnson@roger.ecn.purdue.edu (Wyatt R Johnson)
Subject: CGI.pm & the query string
Message-Id: <8s24sh$6ui$1@mozo.cc.purdue.edu>


Is there a method in CGI.pm to have the contents of the query string
dumped into a hash? I'd use code like

my $q=new CGI

 ... $q->param("whatever") ...

except that I won't know beforehand what the "whatever" is. I'd like to
be able to loop on the keys without reinventing the wheel.

As a last resort, I know I could split the query string on & and then =, and
go from there...but I'd rather not.

Wyatt
there



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

Date: Wed, 11 Oct 2000 09:51:27 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: CGI.pm & the query string
Message-Id: <39E49A8F.9A87EB5B@vpservices.com>

Wyatt R Johnson wrote:
> 
> Is there a method in CGI.pm to have the contents of the query string
> dumped into a hash? I'd use code like

See the section of the CGI.pm documentation titled "FETCHING THE
PARAMETER LIST AS A HASH".
 
> my $q=new CGI
> 
> ... $q->param("whatever") ...
> 
> except that I won't know beforehand what the "whatever" is. I'd like to
> be able to loop on the keys without reinventing the wheel.

You don't need a hash to do that, just loop through the param() array:

for my $key( $q->param() ) {
    print "$key " . $q->param($key) . "<br>";
}

-- 
Jeff


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

Date: Wed, 11 Oct 2000 18:56:07 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI.pm & the query string
Message-Id: <Pine.GHP.4.21.0010111847100.28061-100000@hpplus03.cern.ch>

On 11 Oct 2000, Wyatt R Johnson wrote:

> Is there a method in CGI.pm to have the contents of the query string
> dumped into a hash? 

Does CGI.pm come with comprehensive documentation?  [1]

http://stein.cshl.org/WWW/software/CGI/

 Fetching the Parameter List as a Hash

Is this not precisely what you were asking for, and with an obvious
heading to boot?  I'd recommend reading the accompanying text.

This information also seems to be in "perldoc CGI".


[1] The answer to that seems to be actually "no", judging from
yesterday's interchange where I found out something for myself that
wasn't in the documentation, and then got told that it was documented
in the book  :-}    So the documentation is extensive, but not
entirely comprehensive.  Subtle difference.  Ho hum, not to worry.





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

Date: Wed, 11 Oct 2000 17:15:45 GMT
From: Rich More <rmore1@my-deja.com>
Subject: Re: CGI.pm & the query string
Message-Id: <8s277p$il6$1@nnrp1.deja.com>

In article <8s24sh$6ui$1@mozo.cc.purdue.edu>,
  wjohnson@roger.ecn.purdue.edu (Wyatt R Johnson) wrote:
>
> Is there a method in CGI.pm to have the contents of the query string
> dumped into a hash? I'd use code like
>
> my $q=new CGI
>
> ... $q->param("whatever") ...
>
> except that I won't know beforehand what the "whatever" is. I'd like
to
> be able to loop on the keys without reinventing the wheel.
>
> As a last resort, I know I could split the query string on & and then
=, and
> go from there...but I'd rather not.

From perl's online docs
'perldoc CGI'

     FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR
     SCRIPT:

          @names = $query->param



--
=============================
Richard More
http://www.richmore.com/


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 11 Oct 2000 15:53:40 GMT
From: "Mike Balenger" <MBalenger@att.net>
Subject: Re: Convert array to string?
Message-Id: <820F5.5616$524.342821@bgtnsc05-news.ops.worldnet.att.net>

Summary: "=>" works similarly to ",". I would suggest using comma in the
proposed solution.


=> (equal-greater) is another way to say , (comma) except that it acts like
a binary operator, forcing the lefthand side to be interpreted as a string.
That behavior is most often useful in ARRAYS that are used to initialize
HASHES.  They aren't really used *directly* in hashes.  Ala ...

%ocean_view = (
    NJ => "Atlantic",
    CA => "Pacific",
    "Puerto Rico" => "Caribbean",
    "American Samoa", undef
);

You see that the => is actually used in an *array*.  The array is then used
to initialize the hash.  Notice also that whitespace is not preserved on the
LHS of the => operator, so I have to use quotes to preserve it myself.
Notice also, that comma works just as well, but that the => is asthetically
more pleasing, especially when it's a one liner:

    %hash = (k1 => 101, k2 => 102, k3 => 103, k4 => "something different");


It works in Rafael's example, but as you noticed, it looks weird.  I'd
suggest using a comma if I were the style police or on the code review team.
Here's how I do it.

$string = join "", @array;


Andrew Tkachenko <bugfixxer@yahoo.com> wrote in message
news:8s13kd$1ir$1@arcom.rcom.spb.su...
>
> Rafael Garcia-Suarez <rgarciasuarez@free.fr> ÐÉÛÅÔ ×
> ÓÏÏÂÝÅÎÉÉ:slrn8u846u.hkt.rgarciasuarez@rafael.kazibao.net...
> > Michael wrote in comp.lang.perl.misc:
> > >Is is possible to convert an array of characters to a string. I know
this
> is
> > >possible in java via typecast. But I am not able to find anyting in any
> book
> > >on how to do it in perl.  Does anybody know if this is possible?  If so
> how
> > >might I go about doing this?
> >
> > Apparently you don't think in Perl yet.
> >
> >   $string = join '' => @array;
> >
>
> BTW, could you explain me, please - how is it possible to use
> >join '' => @array;
> instead of
> >join '', @array
> I mean arrow instead of comma? I thought, that '=>' used only in hashes,
but
> '=>' works too. Strange, I am puzzled?
> Thanks for advance, Andrew
>
>




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

Date: Wed, 11 Oct 2000 16:06:40 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Convert array to string?
Message-Id: <slrn8u94di.jqv.rgarciasuarez@rafael.kazibao.net>

Mike Balenger wrote in comp.lang.perl.misc:
>
>It works in Rafael's example, but as you noticed, it looks weird.  I'd
>suggest using a comma if I were the style police or on the code review team.
>Here's how I do it.
>
>$string = join "", @array;

Well, it doesn't look weird once you're used to it.
What's the more readable between :

  $str = join 'a', 'b', 'c', 'd', 'e';

or

  $str = join 'a' => 'b', 'c', 'd', 'e';

The second way to write it stresses the semantic difference between the
first argument and the rest of the arguments.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
use overload '""' => sub { shift @{ ( shift ) } };
sub japh { bless [ split /(?= )/ => $_[1] ] => $_[0] }
$_ = japh main "Just another Perl hacker,\n"; print; print; print; print;


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

Date: Wed, 11 Oct 2000 16:27:38 GMT
From: "Mike Balenger" <MBalenger@att.net>
Subject: Re: Convert array to string?
Message-Id: <_x0F5.5659$524.344163@bgtnsc05-news.ops.worldnet.att.net>

----- Original Message -----
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Newsgroups: comp.lang.perl.misc
Sent: Wednesday, October 11, 2000 12:06 PM
Subject: Re: Convert array to string?


> Mike Balenger wrote in comp.lang.perl.misc:
> >
> >It works in Rafael's example, but as you noticed, it looks weird.  I'd
> >suggest using a comma if I were the style police or on the code review
team.
> >Here's how I do it.
> >
> >$string = join "", @array;
>
> Well, it doesn't look weird once you're used to it.
> What's the more readable between :
>
>   $str = join 'a', 'b', 'c', 'd', 'e';
>
> or
>
>   $str = join 'a' => 'b', 'c', 'd', 'e';
>
> The second way to write it stresses the semantic difference between the
> first argument and the rest of the arguments.
>
> --
> # Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
> use overload '""' => sub { shift @{ ( shift ) } };
> sub japh { bless [ split /(?= )/ => $_[1] ] => $_[0] }
> $_ = japh main "Just another Perl hacker,\n"; print; print; print; print;

Cute.  I see your point.  AND, I'd still prefer to avoid it.

I don't tend to pass scalars to join, so don't usually need to differentiate
the fist argument.

This code does both:
    1) avoid => when comma will work
    2) set the first (scalar) argument apart from the remaining (list of)
arguments

@array = qw(b c d e);
$str = join 'a', @array;





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

Date: 11 Oct 2000 09:44:37 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Convert array to string?
Message-Id: <m1hf6jnx8q.fsf@halfdome.holdit.com>

>>>>> "Mike" == Mike Balenger <MBalenger@att.net> writes:

Mike> => (equal-greater) is another way to say , (comma) except that it acts like
Mike> a binary operator, forcing the lefthand side to be interpreted as a string.
Mike> That behavior is most often useful in ARRAYS that are used to initialize
Mike> HASHES.  They aren't really used *directly* in hashes.  Ala ...

Mike> %ocean_view = (
Mike>     NJ => "Atlantic",
Mike>     CA => "Pacific",
Mike>     "Puerto Rico" => "Caribbean",
Mike>     "American Samoa", undef
Mike> );

Mike> You see that the => is actually used in an *array*.  The array is then used
Mike> to initialize the hash.  Notice also that whitespace is not preserved on the
Mike> LHS of the => operator, so I have to use quotes to preserve it myself.
Mike> Notice also, that comma works just as well, but that the => is asthetically
Mike> more pleasing, especially when it's a one liner:

Uh, s/array/list/ig on that.  I don't see any arrays there at all.
Just lists.

Mike> It works in Rafael's example, but as you noticed, it looks weird.  I'd
Mike> suggest using a comma if I were the style police or on the code review team.
Mike> Here's how I do it.

Mike> $string = join "", @array;

Yes, I agree.  For reasons I posted elsewhere.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <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!


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

Date: 11 Oct 2000 09:12:56 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Cutesy Arrows - Just say no! (was Re: Convert array to string?)
Message-Id: <m18zrvpd9z.fsf_-_@halfdome.holdit.com>

>>>>> "Rafael" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:

Rafael> Well, it doesn't look weird once you're used to it.
Rafael> What's the more readable between :

Rafael>   $str = join 'a', 'b', 'c', 'd', 'e';

Rafael> or

Rafael>   $str = join 'a' => 'b', 'c', 'd', 'e';

Rafael> The second way to write it stresses the semantic difference between the
Rafael> first argument and the rest of the arguments.

And then you get bit with:

    use constant MY_SEPARATOR => 'a';

    $result1 = join MY_SEPARATOR, 'b', 'c', 'd', 'e';
    $result2 = join MY_SEPARATOR => 'b', 'c', 'd', 'e';

    print "$result1 vs $result2\n";

which results in

     bacadae vs bMY_SEPARATORcMY_SEPARATORdMY_SEPARATORe

And you swear NEVER to be "cutesy" again, and stick with the comma
the way Larry intended it.

Just say no to cutesy arrows.

print "Just another Perl hacker,";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <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!


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

Date: Wed, 11 Oct 2000 16:23:57 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Cutesy Arrows - Just say no! (was Re: Convert array to string?)
Message-Id: <slrn8u95dv.js5.rgarciasuarez@rafael.kazibao.net>

Randal L. Schwartz wrote in comp.lang.perl.misc:
>Rafael> Well, it doesn't look weird once you're used to it.
>Rafael> What's the more readable between :
>
>Rafael>   $str = join 'a', 'b', 'c', 'd', 'e';
>
>Rafael> or
>
>Rafael>   $str = join 'a' => 'b', 'c', 'd', 'e';
>
>Rafael> The second way to write it stresses the semantic difference between the
>Rafael> first argument and the rest of the arguments.
>
>And then you get bit with:
>
>    use constant MY_SEPARATOR => 'a';
>
>    $result1 = join MY_SEPARATOR, 'b', 'c', 'd', 'e';
>    $result2 = join MY_SEPARATOR => 'b', 'c', 'd', 'e';
>
>    print "$result1 vs $result2\n";
>
>which results in
>
>     bacadae vs bMY_SEPARATORcMY_SEPARATORdMY_SEPARATORe
>
>And you swear NEVER to be "cutesy" again, and stick with the comma
>the way Larry intended it.

Of course, using => means being aware of the side-effects...
I think about at least one other legitimate use of => outside of literal
hashes :
  my %x = map { $_ => &somefunc($_) } @y;

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 11 Oct 2000 09:33:12 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Cutesy Arrows - Just say no! (was Re: Convert array to string?)
Message-Id: <m1lmvvnxrr.fsf@halfdome.holdit.com>

>>>>> "Rafael" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:

Rafael> Of course, using => means being aware of the side-effects...

But your posting didn't qualify that, so that creates a cargo-cult
misunderstanding, and people start passing along your "tip" untested
and unaware that they WILL GET BURNED someday soon. You handed a laser
raygun to a child without saying "don't point this into your eyes".
That's dangerous.

So I post for the onlookers, not for you.  Perhaps you know which way
to point that thing, but you weren't clear for the others.

Much easier to type a comma than to type a cutesy arrow anyway!

print "Just another Perl hacker," =>

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <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!


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

Date: Wed, 11 Oct 2000 17:10:57 GMT
From: "Mike Balenger" <MBalenger@att.net>
Subject: Re: Cutesy Arrows - Just say no! (was Re: Convert array to string?)
Message-Id: <Ba1F5.5724$524.345809@bgtnsc05-news.ops.worldnet.att.net>


Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote in message
news:slrn8u95dv.js5.rgarciasuarez@rafael.kazibao.net...
> Randal L. Schwartz wrote in comp.lang.perl.misc:
> >Rafael> Well, it doesn't look weird once you're used to it.
> >Rafael> What's the more readable between :
> >
> >Rafael>   $str = join 'a', 'b', 'c', 'd', 'e';
> >
> >Rafael> or
> >
> >Rafael>   $str = join 'a' => 'b', 'c', 'd', 'e';
> >
> >Rafael> The second way to write it stresses the semantic difference
between the
> >Rafael> first argument and the rest of the arguments.
> >
> >And then you get bit with:
> >
> >    use constant MY_SEPARATOR => 'a';
> >
> >    $result1 = join MY_SEPARATOR, 'b', 'c', 'd', 'e';
> >    $result2 = join MY_SEPARATOR => 'b', 'c', 'd', 'e';
> >
> >    print "$result1 vs $result2\n";
> >
> >which results in
> >
> >     bacadae vs bMY_SEPARATORcMY_SEPARATORdMY_SEPARATORe
> >
> >And you swear NEVER to be "cutesy" again, and stick with the comma
> >the way Larry intended it.
>
> Of course, using => means being aware of the side-effects...
> I think about at least one other legitimate use of => outside of literal
> hashes :
>   my %x = map { $_ => &somefunc($_) } @y;
>

I'd have to agree that I do prefer "=>" to "," here.  It fits into the idiom
where we lists (thanks for the distinction from arrays, Randal) to
initialize hashes.

%x = ( A => 0x41, B => 0x42, C => 0x43, a => 0x61, b => 0x62, c => 0x63);

%x_again = map { $_ => ord($_) } qw(A B C a b c);







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

Date: Wed, 11 Oct 2000 17:10:58 GMT
From: "Mike Balenger" <MBalenger@att.net>
Subject: Re: Cutesy Arrows - Just say no! (was Re: Convert array to string?)
Message-Id: <Ca1F5.5725$524.345772@bgtnsc05-news.ops.worldnet.att.net>

Randal L. Schwartz <merlyn@stonehenge.com> wrote in message
news:m1lmvvnxrr.fsf@halfdome.holdit.com...
> >>>>> "Rafael" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:
>
> Rafael> Of course, using => means being aware of the side-effects...
>
> But your posting didn't qualify that, so that creates a cargo-cult
> misunderstanding, and people start passing along your "tip" untested
> and unaware that they WILL GET BURNED someday soon. You handed a laser
> raygun to a child without saying "don't point this into your eyes".
> That's dangerous.
>
> So I post for the onlookers, not for you.  Perhaps you know which way
> to point that thing, but you weren't clear for the others.
>
> Much easier to type a comma than to type a cutesy arrow anyway!
>
> print "Just another Perl hacker," =>
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <merlyn@stonehenge.com> <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!

Cargo-cult?





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

Date: Wed, 11 Oct 2000 17:11:36 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: Defining an Operator (not overloading)
Message-Id: <39E48328.D46125AC@bar.va>

Daniel,

Daniel Yacob wrote:
> My interest is to simply define a new operator, imported from its 
> own package via 'use', and have it be functional for scalars, it 
> can reject any arguements that are refs.  

  I am afraid that, since operators are recognized by the parser,
creating a new one is impossible.
 
> What I'm after is a prefix operator that would be similar to .=, 
> lets call it `= though the choice is arbitrary for discussion:
> $string `= $prefix;
> performs:
> $string = $prefix . $string;
> which happens to be a common occurance for me, I expect others 
> as well.

  At the cost of few keystrokes only you can obtain the same results
with the following syntax:

	$string=$prefix.=$string;


	Best regards,
		Marco


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

Date: Wed, 11 Oct 2000 15:12:53 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Defining an Operator (not overloading)
Message-Id: <slrn8u918n.jnq.rgarciasuarez@rafael.kazibao.net>

Daniel Yacob wrote in comp.lang.perl.misc:
>Greetings,
>
>I've been searching for how to define a new operator in Perl and have
>been coming up with lots of info on overloading operators which is not
>what I want to do.
>
>My interest is to simply define a new operator, imported from its own
>package via 'use', and have it be functional for scalars, it can reject
>any arguements that are refs.  What I'm after is a prefix operator that
>would be similar to .=, lets call it `= though the choice is arbitrary
>for discussion:
>
>  $string `= $prefix;
>
>performs:
>
>  $string = $prefix . $string;
>
>which happens to be a common occurance for me, I expect others as well.
>Any help would be appreciated.

Hack the source code of the Perl interpreter (and make sure you don't
introduce grammar conflicts). There is no other way.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
use overload '""' => sub { shift @{ ( shift ) } };
sub japh { bless [ split /(?= )/ => $_[1] ] => $_[0] }
$_ = japh main "Just another Perl hacker,\n"; print; print; print; print;


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

Date: Wed, 11 Oct 2000 15:33:31 GMT
From: "Mike Balenger" <MBalenger@att.net>
Subject: Re: Defining an Operator (not overloading)
Message-Id: <fL%E5.5592$524.341446@bgtnsc05-news.ops.worldnet.att.net>

> I've been searching for how to define a new operator in Perl and have
> been coming up with lots of info on overloading operators which is not
> what I want to do.

Do you know of another language that lets you do this?  I know that C++ does
not.  It's a parser problem -- all operators are recognized at the parser
level.  They can be overloaded later, but whether they are operators is
already fixed.  As is the definition of identifiers, keywords, block
delimiters, etc.






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

Date: Wed, 11 Oct 2000 17:36:50 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Defining an Operator (not overloading)
Message-Id: <39e4a531.44db$2a8@news.op.net>
Keywords: longleg, proportionate, secretion, senior


In article <fL%E5.5592$524.341446@bgtnsc05-news.ops.worldnet.att.net>,
Mike Balenger <MBalenger@att.net> wrote:
>> I've been searching for how to define a new operator in Perl and have
>> been coming up with lots of info on overloading operators which is not
>> what I want to do.
>
>Do you know of another language that lets you do this?  

You can do this in ML, except that the proposed symbol, '=, happens to
be illegal in ML.

In ML you would say something like this:

        infix 3 .== ;
        fun s .== p   =           s := !s ^ p;

(The '3' indicates the relative precedence of the new .== operator.  ^
is the ML string concatenation operator and := is assignment.  s is a
reference to a string; !s dereferences s.  You can't assign directly
to a string because in ML variable names don't necessarily refer to
storage unless they are references, so the assignment operator only
works on a reference.)

I'm working on an experimental Perl-like language that supports this feature.

The parser details are not difficult.  The only hard part is that you
cannot use YACC.


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

Date: 11 Oct 2000 08:35:02 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: File::Find How to pass parameters to wanted function
Message-Id: <m1snq3pf15.fsf@halfdome.holdit.com>

>>>>> "James" == James Taylor <james@NOSPAM.demon.co.uk> writes:

James> sub makewanted ($) {
James>     my $p = shift;

James>     return sub {
James>         print $p, "\n";
James>     }
James> }

James> find (makewanted(3), 'my_dir');
James> # ...
James> find (makewanted(17), 'my_dir');

I usually just construct my "wanted" on the fly:

    sub do_something {
      my $parameter = shift;
      find sub {
        stuff stuffy stuff seeing $parameter just fine;
        more stuffy stuff;
      }, @_;
    }

I don't know why people do this the hard way trying to get "wanted"
outside the scope as seperate named subroutine.  I can't recall
a recent time I've written a named subroutine for find!

print "Just another Perl hacker,"
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <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!


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

Date: Wed, 11 Oct 2000 18:56:11 +0200
From: "Johan Ditmar" <johan.ditmar@era.ericsson.se>
Subject: files changes when uploading.
Message-Id: <8s25kd$l29$1@newstoo.ericsson.se>

Hi,

I am trying to upload a file and I am using the code below to do that:

----
open (SAVE,">./bitfile.bit") || die $!;

   while (read($bitfile,$data,1024)) {
     print SAVE $data;

   }
   close SAVE;
----
For my application, it's very important that the uploaded file is not
changed in any way. It seems though that it is changed when using my code.
It becomes a little larger also. Is there some way to upload files without
changing them?

Thanks,

Johan




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

Date: Wed, 11 Oct 2000 15:51:44 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: How to remove all white spaces
Message-Id: <ant111444868fNdQ@oakseed.demon.co.uk>

In article <Pine.GSO.4.21.0010111018460.14163-100000@crusoe.crusoe.net>,
Jeff Pinyan <URL:mailto:jeffp@crusoe.net> wrote:
> 
> Either use s/// or tr///.  I'd suggest
> 
>   $string =~ tr/\r\n\t\f //d;
> 
> for speed.

Why is tr/\r\n\t\f //d; considered faster than s/\s+//; ?

I would have thought that the tr///d would have to shuffle the string
tail down in memory for each char it removed whereas the s/// only
needs to do so for each block of chars it removes. I obviously don't
know anything about how perl implements this internally so can you
explain the difference? Thanks.

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Wed, 11 Oct 2000 11:06:22 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: How to remove all white spaces
Message-Id: <Pine.LNX.4.21.0010111105150.19242-100000@hawk.ce.mediaone.net>

On Wed, 11 Oct 2000, alichambers@madasafish.com quoth:

> Hi there
> 
> I have a designed a HTML form that allows users to enter their
> address.  The form is processed with a PERL script and the form
> postcode is assigned to $postcode.
> 
> I'd like to be able to remove all the whitespaces from the string. Eg-
> BS1 1AA or BS 1 1 AA would both become BS11AA.

[ snip ]

$postcode =~ tr/ //d;

anm
-- 
package News::NNTPClient;use subs q;warn;;sub warn{0}package main;use
News::NNTPClient;$;=News::NNTPClient->new();($==>$$)=($;->group(($|||
((<comp.lang.perl.misc>)))));for$)(<$=>..<$$>){map{$\=v12;die 1?qq{$1
}:q--while s<^.+(j..T .{6}(r) p.R. .{5}\2).+>[$1]mig}$;->article($))}



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4584
**************************************


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