[31903] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3166 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 9 21:09:43 2010

Date: Sat, 9 Oct 2010 18:09:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 9 Oct 2010     Volume: 11 Number: 3166

Today's topics:
        ANNE HATHAWAY Hot and sexy images and video <use2356@gmail.com>
    Re: becoming superuser <hjp-usenet2@hjp.at>
    Re: becoming superuser <john@example.invalid>
    Re: becoming superuser <tadmc@seesig.invalid>
    Re: becoming superuser sln@netherlands.com
    Re: becoming superuser <john@example.invalid>
    Re: becoming superuser <jurgenex@hotmail.com>
    Re: FAQ 3.30 What's MakeMaker? <john@example.invalid>
    Re: FAQ 3.30 What's MakeMaker? <ben@morrow.me.uk>
    Re: toy list processing problem: collect similar terms <hjp-usenet2@hjp.at>
    Re: toy list processing problem: collect similar terms sln@netherlands.com
    Re: toy list processing problem: collect similar terms <john@example.invalid>
    Re: toy list processing problem: collect similar terms <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 9 Oct 2010 15:34:06 -0700 (PDT)
From: sam <use2356@gmail.com>
Subject: ANNE HATHAWAY Hot and sexy images and video
Message-Id: <68e84267-9cfc-4ccf-bb13-f185d84feb9c@o2g2000vbh.googlegroups.com>

Due to high sex content, i have hidden the Wallpapers in an image.
in that website on left side below search box and click on image
 and watch Videos.               http://annehathaway.tk/



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

Date: Sat, 9 Oct 2010 10:26:32 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: becoming superuser
Message-Id: <slrnib09ps.h2v.hjp-usenet2@hrunkner.hjp.at>

On 2010-10-09 03:08, John Smith <john@example.invalid> wrote:
> myfunc(<< "THIS", 23, <<THAT);
> Here's a line
> or two.
> THIS
> and here's another.
> THAT
> #comment
>
> # perl l3.pl
> ron@dan-desktop:~/source$
>
> When I was saying that I couldn't get anything rolling with a 
> declaration

A declaration is a construct which declares that a "thing" exists and has
a certain name. For example,

    my $x;

is a declaration: It declares that there is a lexical, scalar variable
named "$x" (or just "x" - it is debatable whether the dollar sign is
part of the name).

    sub double {
        my ($x) = @_;
        return $x * 2;
    }

is also a declaration. It declares a subroutine named "double", which
returne the value of its first argument multiplied by 2. Finally,

    sub half;

is a declaration which declares that a subroutine "half" exists, but it
doesn't define what "half" does - that would be elsewhere.

But

    myfunc(<< "THIS", 23, <<THAT);
    Here's a line
    or two.
    THIS
    and here's another.
    THAT

is not a declaration. It doesn't declare anything. It is an expression
statement which calls the subroutine "myfunc" with 3 arguments. It is
exactly equivalent to 

    myfunc("Here's a line\nor two.\n", 23, "and here's another.\n");


> is that I can't judge the author's intent and fill in the 
> gaps on the last couple.  I can see by their complexity that they are 
> not ways that I'll be using a here doc anytime soon.

I would advise against using here documents in any case. You have to
understand them because you will encounter them in Perl code, but I
think they are hard to read and ugly. You can just include newlines in
normal strings, so you could write 

    myfunc(qq{Here's a line
    or two
    }, 23,
    qq{and here's another.
    });

instead (qq{} is just another way of writing double quotes), but that
has the same problem as here documents: It cannot be indented properly.
I intended the indentation only as a visual indication that this is code
and not text, but if you actually write it like this the blanks are
included in the string, so it is really equivalent to:

    myfunc("Here's a line\n    or two.    \n", 23, "and here's another.    \n");

Probably not what you wanted. You would have to write (no extra
indentation this time):

    myfunc(qq{Here's a line
or two
}, 23,
    qq{and here's another.
});

or

    myfunc(<< "THIS", 23, <<THAT);
Here's a line
or two.
THIS
and here's another.
THAT

Both of which are butt-ugly.

There are some ways around that (see the FAQ) but all of them work at
runtime. So I'd write that as

    myfunc(
        "Here's a line\n" .
        "or two.\n",
        23,
        "and here's another.\n"
    );

if the spaces matter. The Perl compiler optimizes
""Here's a line\n" .  "or two.\n" 
into a single string.

If leading whitespace doesn't matter I just use normal single or doube
quotes:

    my $result
        = $dbh->selectall_hashref(
                    q{
                       select distinct value+0 as gid
                       from service, attribute
                       where service.type='group'
                         and attribute.service=service.id and attribute.key='gid'
                         and value+0 >= ? and value+0 <= ?
                      },
                    'gid',
                    {},
                    $gid_min, $gid_max
                );
    do_something_with($result);


	hp




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

Date: Sat, 09 Oct 2010 15:19:22 -0600
From: John Smith <john@example.invalid>
Subject: Re: becoming superuser
Message-Id: <x5ednaK9udfGQS3RnZ2dnUVZ5judnZ2d@giganews.com>

Peter J. Holzer wrote:

[snipped a lot; I'll get to that part later]

> A declaration is a construct which declares that a "thing" exists and has
> a certain name. For example,
> 
>     my $x;
> 
> is a declaration: It declares that there is a lexical, scalar variable
> named "$x" (or just "x" - it is debatable whether the dollar sign is
> part of the name).
> 
>     sub double {
>         my ($x) = @_;
>         return $x * 2;
>     }
> 
> is also a declaration. It declares a subroutine named "double", which
> returne the value of its first argument multiplied by 2. Finally,
> 
>     sub half;
> 
> is a declaration which declares that a subroutine "half" exists, but it
> doesn't define what "half" does - that would be elsewhere.

So, I'd like to figure out the qq equivalents, but I don't understand 
why the compiler couldn't just optimize the whole thing away:

ron@dan-desktop:~/source$ perl l5.pl
Use of uninitialized value $g in print at l5.pl line 10.
ron@dan-desktop:~/source$ cat l5.pl
#!/usr/bin/perl
use strict;
use warnings;

my $g;
my $h;
sub myfunc{};

$g = myfunc();
print $g;

myfunc(<< "THIS", 23, <<THAT);
Here's a line
or two.
THIS
and here's another.
THAT
#comment

print myfunc();

# perl l5.pl
ron@dan-desktop:~/source$

Why would anybody on god's green earth write this function, in any of 
its forms?
-- 
John Smith


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

Date: Sat, 09 Oct 2010 18:14:02 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: becoming superuser
Message-Id: <slrnib1tup.b6u.tadmc@tadbox.sbcglobal.net>

John Smith <john@example.invalid> wrote:
> Peter J. Holzer wrote:
>
> [snipped a lot; I'll get to that part later]
>
>> A declaration is a construct which declares that a "thing" exists and has
>> a certain name. For example,
>> 
>>     my $x;
>> 
>> is a declaration: It declares that there is a lexical, scalar variable
>> named "$x" (or just "x" - it is debatable whether the dollar sign is
>> part of the name).
>> 
>>     sub double {
>>         my ($x) = @_;
>>         return $x * 2;
>>     }
>> 
>> is also a declaration. It declares a subroutine named "double", which
>> returne the value of its first argument multiplied by 2. Finally,
>> 
>>     sub half;
>> 
>> is a declaration which declares that a subroutine "half" exists, but it
>> doesn't define what "half" does - that would be elsewhere.
>
> So, I'd like to figure out the qq equivalents, 


the qq equivalents to *what*?

There are no double quoted strings in what you quoted, so there
is nothing to make a qq equivalent for.

Why did you quote all of that? It is about declarations yet you
do not have a question about declarations. None of it has to do 
with strings yet you have a question about strings.

here-docs, double-quotes and qq are simply strings.


> myfunc(<< "THIS", 23, <<THAT);
> Here's a line
> or two.
> THIS
> and here's another.
> THAT

Those are the only two strings in your post, so I'll assume you
want the qq equivalents to those (untested).

    myfunc(qq/Here's a line\nor two.\n/, 23, qq/and here's another.\n/);

or use literal newlines (which looks quite horrid):

    myfunc(qq/Here's a line
or two.
/, 23, qq/and here's another.
/);


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sat, 09 Oct 2010 16:17:09 -0700
From: sln@netherlands.com
Subject: Re: becoming superuser
Message-Id: <5pt1b6deqf5u1bd5cdia8u4s20lp16dhlj@4ax.com>

On Sat, 09 Oct 2010 15:19:22 -0600, John Smith <john@example.invalid> wrote:

>So, I'd like to figure out the qq equivalents, but I don't understand 
>why the compiler couldn't just optimize the whole thing away:
>
>ron@dan-desktop:~/source$ perl l5.pl
>Use of uninitialized value $g in print at l5.pl line 10.
>ron@dan-desktop:~/source$ cat l5.pl
>#!/usr/bin/perl
>use strict;
>use warnings;
>
>my $g;
>my $h;
>sub myfunc{};
>
>$g = myfunc();
>print $g;
>
>myfunc(<< "THIS", 23, <<THAT);
>Here's a line
>or two.
>THIS
>and here's another.
>THAT
>#comment
>
>print myfunc();
>
># perl l5.pl
>ron@dan-desktop:~/source$
>
>Why would anybody on god's green earth write this function, in any of 
>its forms?

Its nice to put in arbitrary debug structure in code.
In this case, within myfunc() subroutine. No fancy syntax
so you can see whats going on.

-sln
------------
use strict;
use warnings;

my $g;
my $h;

sub myfunc {
    if (defined $_[0]) {
        return  join( "=\n", @_ ) . "=\n";
    }
    else {
        return "++undefined\n";
    }
}

$g = myfunc();
print $g;

print myfunc(<< "THIS", 23, <<THAT);
Here's a line
or two.
THIS
and here's another.
THAT
#comment

print myfunc();



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

Date: Sat, 09 Oct 2010 17:41:57 -0600
From: John Smith <john@example.invalid>
Subject: Re: becoming superuser
Message-Id: <dqednV5DUK1YYC3RnZ2dnUVZ5hCdnZ2d@giganews.com>

sln@netherlands.com wrote:

> Its nice to put in arbitrary debug structure in code.
> In this case, within myfunc() subroutine. No fancy syntax
> so you can see whats going on.
> 
> -sln
> ------------
> use strict;
> use warnings;
> 
> my $g;
> my $h;
> 
> sub myfunc {
>     if (defined $_[0]) {
>         return  join( "=\n", @_ ) . "=\n";
>     }
>     else {
>         return "++undefined\n";
>     }
> }
> 
> $g = myfunc();
> print $g;
> 
> print myfunc(<< "THIS", 23, <<THAT);
> Here's a line
> or two.
> THIS
> and here's another.
> THAT
> #comment
> 
> print myfunc();
> 

Thanks, sjouke, that's what I was looking for.
ron@dan-desktop:~/source$ perl l5.pl
++undefined
Here's a line
or two.
=
23=
and here's another.
=
++undefined
ron@dan-desktop:~/source$
-- 
John Smith


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

Date: Sat, 09 Oct 2010 17:13:48 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: becoming superuser
Message-Id: <sr02b6lgrraueef2pvu5imndiesl7jr7ko@4ax.com>

John Smith <john@example.invalid> wrote:
>sub myfunc{};

Ok, so you are defining the function myfunc to do exactly nothing.
Well, ok, if that's what you want it do....


>$g = myfunc();

Ok, so now $g is undefined because myfunc() doesn't return any value,

>print $g;
>
>myfunc(<< "THIS", 23, <<THAT);

And it doesn't matter one bit which parameters you are passing, myfunc()
still does nothing and returns nothing.

>print myfunc();

And it doesn't matter one bit in which context you are calling myfunc(),
it still does nothing and returns nothing.

>Why would anybody on god's green earth write this function, in any of 
>its forms?

The only function you wrote is myfunc(), you wrote it in exactly one
form, and why anybody would choose this form (except as temporary
placeholder during development) is indeed a good question.

jue


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

Date: Sat, 09 Oct 2010 16:54:25 -0600
From: John Smith <john@example.invalid>
Subject: Re: FAQ 3.30 What's MakeMaker?
Message-Id: <w6-dnT8poqo8by3RnZ2dnUVZ5j2dnZ2d@giganews.com>

PerlFAQ Server wrote:

> 3.30: What's MakeMaker?
> 
>     (contributed by brian d foy)
> 
>     The "ExtUtils::MakeMaker" module, better known simply as "MakeMaker",
>     turns a Perl script, typically called "Makefile.PL", into a Makefile.
>     The Unix tool "make" uses this file to manage dependencies and actions
>     to process and install a Perl distribution.

Does anyone have an example of this?
-- 
John Smith


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

Date: Sun, 10 Oct 2010 00:54:54 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 3.30 What's MakeMaker?
Message-Id: <evb7o7-3lu.ln1@osiris.mauzo.dyndns.org>


Quoth John Smith <john@example.invalid>:
> PerlFAQ Server wrote:
> 
> > 3.30: What's MakeMaker?
> > 
> >     (contributed by brian d foy)
> > 
> >     The "ExtUtils::MakeMaker" module, better known simply as "MakeMaker",
> >     turns a Perl script, typically called "Makefile.PL", into a Makefile.
> >     The Unix tool "make" uses this file to manage dependencies and actions
> >     to process and install a Perl distribution.
> 
> Does anyone have an example of this?

Pick a module on CPAN. It will have either a Makefile.PL or a Build.PL,
and if it has a Makefile.PL it will use either MakeMaker or
Module::Install.

Ben



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

Date: Sat, 9 Oct 2010 09:48:28 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <slrnib07id.h2v.hjp-usenet2@hrunkner.hjp.at>

On 2010-10-08 22:22, Ertugrul Söylemez <es@ertes.de> wrote:
> Josef <e9427749@stud4.tuwien.ac.at> wrote:
>> Am 08.10.2010 04:38, schrieb Ertugrul Söylemez:
>> > Josef<e9427749@stud4.tuwien.ac.at>  wrote:
>> >> I don't know the reason of the silence,
>> >> but if anybody of the c.l.f people indeed fall sick.
>> >> This time the code example is attempt for resuscitation, or
>> >> at least to sedate your hearts.   ;-)
>> >
>> > Functional programmers write obfuscated code, too.  But unlike Perl,
                                  ^^^^^^^^^^
>> > it still looks beautiful.
>>
>> Ok, what i learned now, is that perception of beautifulness could be
>> very different.
>
> Well, in fact the code I posted is beautiful in a number of ways.  It's
> easy to read, very fast and also elegant.  However, it is not beautiful
  ^^^^^^^^^^^^

Code cannot be both "obfuscated" and "easy to read" at the same time.
"Obfuscated" means hard to read (it can still be beautiful, though).


>> If you would say that      sub goiter { [ map @$_,@_ ] }
>> is better than my previous version, you are of course right.
>
> The problem is that you need to understand those Perl symbols to
> understand this.  In contrast to understand my code you just need to
> understand language syntax

"Those Perl symbols" are part of the language syntax. So saying you need
to understand those Perl symbols is the same as saying you just need to
understand the language syntax.

> More functional, but I still don't understand all those Perl symbols,
> but I'm not a Perl programmer anyway.

Your code also contains some syntactic elements ("those symbols") which
are not at all obvious to someone not familiar with the language (e.g.,
"->", "\", "_"). I think this is true for all languages. Some use a
large collection of non-word symbols (APL is probably the extreme case,
but Perl is also quite far along this axis), some very few (COBOL comes
to mind, but also Lisp), most are somewhere between.

	hp


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

Date: Sat, 09 Oct 2010 02:40:09 -0700
From: sln@netherlands.com
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <r0d0b65cnon1aaq0r5353ktqtle5phup5u@4ax.com>

On Fri, 08 Oct 2010 19:20:10 +0200, Josef <e9427749@stud4.tuwien.ac.at> wrote:

>Am 08.10.2010 04:38, schrieb Ertugrul Söylemez:
>> Josef<e9427749@stud4.tuwien.ac.at>  wrote:
>>
>>> I don't know the reason of the silence,
>>> but if anybody of the c.l.f people indeed fall sick.
>>> This time the code example is attempt for resuscitation, or
>>> at least to sedate your hearts.   ;-)
>>
>> Functional programmers write obfuscated code, too.  But unlike Perl, it
>> still looks beautiful.
>
>Ok, what i learned now, is that perception of beautifulness could be 
>very different.
>
>If you would say that      sub goiter { [ map @$_,@_ ] }
>is better than my previous version, you are of course right.
>
>Hey i say this only, so the perliatic pitbulls don't snarl to you
>"that has nothing to do with perl" and tear you afterwards.
>
>Ey. Oh, maybe i shouldn't have written this.
>Brave dog. brave. search this nice ball. be a nice dog. no no no ...
>
>
>But yet to something completely different:
>Maybe you like the following version more.
>
>...
># charpter 1
>sub fun
>{@{+ reduce { my ($o,$map)=@$a; my ($k)=$b->[0];
>               my @k=exists $map->{$k} ? () : $k;
>               [[@$o,@k],
>                { %$map,$k =>
>                  [!@k?@{$map->{$k}}:(),@{$b}[1..$#$b]] }]
>             } @_
>}}
>my ($order,$map)=fun [[],{}],@inp;
>dump @{$map}{@$order};
>
>whatever^H^H^H^H^H^H^H^H* and have fun, josef
>
>PS: Ok, i have tried to write functional code in a imperative language.
>     How does look your imperative code written in a functional language?
>;-)

In general, making a new hash (or array) by recopying the
original for every element in the old one, apparently seems
to takes some exponentially serious cpu time.

-sln
----------------------
use strict;
use warnings;
use Benchmark ':hireswallclock';

my $hash = {};
for my $multiplier ( 10 .. 20 )
{
    my $number_of_lists = $multiplier * 100;
    my $t0 = new Benchmark;
    for my $key (1 .. $number_of_lists)
    {
         $hash->{$key} = ['a','b'];
    }
    my $t1 = new Benchmark;
    print "$number_of_lists = ".( timestr(timediff($t1, $t0)) )."\n";
}

print "\n\n";

$hash = {};
for my $multiplier ( 10.. 20 )
{
    my $number_of_lists = $multiplier * 100;
    my $t0 = new Benchmark;
    for my $key (1 .. $number_of_lists)
    {
         $hash = { %$hash };
         $hash->{$key} = ['a','b'];
    }
    my $t1 = new Benchmark;
    print "$number_of_lists = ".( timestr(timediff($t1, $t0)) )."\n";
}

__END__

1000 = 0.0024159 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1100 = 0.00256991 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1200 = 0.00275707 wallclock secs ( 0.02 usr +  0.00 sys =  0.02 CPU)
1300 = 0.00299716 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1400 = 0.00329781 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1500 = 0.00346112 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1600 = 0.00370002 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1700 = 0.00393891 wallclock secs ( 0.01 usr +  0.00 sys =  0.01 CPU)
1800 = 0.00404406 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
1900 = 0.00440192 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
2000 = 0.00462699 wallclock secs ( 0.02 usr +  0.00 sys =  0.02 CPU)


1000 = 0.241532 wallclock secs ( 0.23 usr +  0.00 sys =  0.23 CPU)
1100 = 0.528928 wallclock secs ( 0.53 usr +  0.00 sys =  0.53 CPU)
1200 = 0.687361 wallclock secs ( 0.69 usr +  0.00 sys =  0.69 CPU)
1300 = 0.812351 wallclock secs ( 0.81 usr +  0.00 sys =  0.81 CPU)
1400 = 0.937367 wallclock secs ( 0.94 usr +  0.00 sys =  0.94 CPU)
1500 = 1.06237 wallclock secs ( 1.06 usr +  0.00 sys =  1.06 CPU)
1600 = 1.203 wallclock secs ( 1.19 usr +  0.00 sys =  1.19 CPU)
1700 = 1.34361 wallclock secs ( 1.34 usr +  0.00 sys =  1.34 CPU)
1800 = 1.48424 wallclock secs ( 1.49 usr +  0.00 sys =  1.49 CPU)
1900 = 1.6405 wallclock secs ( 1.64 usr +  0.00 sys =  1.64 CPU)
2000 = 1.81238 wallclock secs ( 1.81 usr +  0.00 sys =  1.81 CPU)



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

Date: Sat, 09 Oct 2010 14:32:45 -0600
From: John Smith <john@example.invalid>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <tsednRopRZXwTC3RnZ2dnUVZ5rKdnZ2d@giganews.com>

Josef wrote:

> This posting is cross-posted to c.l.f only, because even some of the
> stuff in the appended code looks familiar at first, it holds
> things in it which can cause heart attacks to this guys.
> So be warned.

I saw that in c.l.f. in my main identity and thought, gosh, he needs 
perl.  Did you get it squared away?
-- 
John Smith


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

Date: Sat, 09 Oct 2010 18:16:28 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <slrnib1u3b.b6u.tadmc@tadbox.sbcglobal.net>

John Smith <john@example.invalid> wrote:

> in my main identity


I suggest choosing something other than "John Smith" as others have
used that name and behaved badly, I have it killfiled.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3166
***************************************


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