[25954] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8173 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 15 09:05:31 2005

Date: Wed, 15 Jun 2005 06:05:07 -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           Wed, 15 Jun 2005     Volume: 10 Number: 8173

Today's topics:
    Re: Filetoad.com Latest Software Virus and spyware  <jurgenex@hotmail.com>
    Re: Fixed: ActiveState: Can't spawn "cmd.exe"? <sisyphus1@nomail.afraid.org>
    Re: Hash Sorting (Anno Siegel)
    Re: Hash Sorting <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: iterating over a hashref of hashrefs (Anno Siegel)
    Re: Masking by columns for grep <djames@thehub.com.au>
    Re: Masking by columns for grep (Anno Siegel)
    Re: perl one liner to display the third line from the e <chriss@activestate.com>
    Re: perl one liner to display the third line from the e <djames@thehub.com.au>
    Re: perl one liner to display the third line from the e <pilkowsk@informatik.uni-marburg.de>
        Regular Expression not working (Fritz Bayer)
    Re: Regular Expression not working (Greg Bacon)
    Re: Which are the "CPAN superstars"? <chriss@activestate.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 15 Jun 2005 04:23:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Filetoad.com Latest Software Virus and spyware 
Message-Id: <M2Ore.11263$9a1.2730@trnddc01>

"Filetoad.com" wrote:
> We are a new website providing  the Latest software and latest virus and 
> spyware updates
> for your computer it will save you lots of time in the future please take 
> a look
[...]

Only question is: are there really people who are dump enough to install the 
latest virus and spyware on their computer....

jue 




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

Date: Wed, 15 Jun 2005 19:31:25 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Fixed: ActiveState: Can't spawn "cmd.exe"?
Message-Id: <42aff578$0$16493$afc38c87@news.optusnet.com.au>


"Daniel Pfeiffer" <occitan@esperanto.org> wrote in message
news:42AF457A.9060709@esperanto.org...

[snip]

> I had a hard time getting MinGW together, even though Msys is supposed to
give
> all you need.  I picked up a lot of packages, before I finally had a Perl.
> It's the Perl 5.6.1 they deliver on their server.  I compiled nothing
myself.

Aaah - that would have been a perl package that came with one of the
"extras" MSYS packages - probably msysDTK I'm guessing.
Fyi: I don't know of anyone actually using that perl build - and had
forgotten that I had read of its existence. Needless to say, I haven't
actually tried it out. It sounds like it has a particularly nixy flavour
(similar to Cygwin's perl ?). Any people I know of who are using MinGW-built
perl built it as I outlined in my last post. That way you get a native Win32
perl - same as ActiveState perl, but built with the MinGW port of the gcc
compiler. Built that way, MinGW perl and ActiveState perl are binary
compatible (assuming the MinGW perl has been built, like ActiveState perl,
with threads support). I doubt that you could swap binaries around between
your MinGW perl and an ActiveState perl 5.6 (even if your MinGW perl *is*
multithreaded).

Cheers,
Rob




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

Date: 15 Jun 2005 09:40:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Hash Sorting
Message-Id: <d8ot2u$1o3$1@mamenchi.zrz.TU-Berlin.DE>

Mark Clements  <mark.clementsREMOVETHIS@wanadoo.fr> wrote in comp.lang.perl.misc:
> On Tue, 14 Jun 2005 13:49:56 -0700, Brad wrote:
> 
> > I have a hash like this:
> > 
> > $HASH{'key'}{'date'} = some date
> > $HASH{'key'}{'status'} = some status
> > 
> > I'd like to sort and display this by date:
> > 
> > key | date | status
> > 
> > I cannot seem to find any references to sorting this type of hash in this 
> > way. I need some assistance finding some documentation, or a copy/paste of 
> > the code for this type of sort.
> > 
> You can do it with a double map and sort.
> 
> Google for 
> 
> "schwarzian transform" perl

Why do you think that's useful?

A Schwartzian transform is an efficiency hack that saves time when the
extraction of sort keys from the elements is expensive.  It doesn't
facilitate any particular ordering, you'll have to do that either way.

Since the sort keys are available through hash access, there isn't much
a Schwartzian can gain in this case.

Anno


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

Date: Wed, 15 Jun 2005 12:37:56 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Hash Sorting
Message-Id: <evdy5xkjohd6$.npy4ehwu8hby.dlg@40tude.net>

On 15 Jun 2005 09:40:46 GMT, Anno Siegel wrote:

> Mark Clements  <mark.clementsREMOVETHIS@wanadoo.fr> wrote in comp.lang.perl.misc:
>> On Tue, 14 Jun 2005 13:49:56 -0700, Brad wrote:
>> 
>>> I have a hash like this:
>>> 
>>> $HASH{'key'}{'date'} = some date
>>> $HASH{'key'}{'status'} = some status
>>> 
>>> I'd like to sort and display this by date:
>>> 
>>> key | date | status
>>> 
>>> I cannot seem to find any references to sorting this type of hash in this 
>>> way. I need some assistance finding some documentation, or a copy/paste of 
>>> the code for this type of sort.
>>> 
>> You can do it with a double map and sort.
>> 
>> Google for 
>> 
>> "schwarzian transform" perl
> 
> Why do you think that's useful?
It demonstrates passing different comparison operations to sort, and the
use of multiple maps, though I didn't realise that the Schwarzian transform
was specific to non-prekeyed data. 

> 
> A Schwartzian transform is an efficiency hack that saves time when the
> extraction of sort keys from the elements is expensive.  It doesn't
> facilitate any particular ordering, you'll have to do that either way.

> Since the sort keys are available through hash access, there isn't much
> a Schwartzian can gain in this case.
Fair enough, but the suggestion was intended more as a learning exercise
than as a "do it this way".

Mark


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

Date: 15 Jun 2005 10:44:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: iterating over a hashref of hashrefs
Message-Id: <d8p0rb$46m$1@mamenchi.zrz.TU-Berlin.DE>

Sam <perlquestions@mail.com> wrote in comp.lang.perl.misc:
> I have a data structure that looks like this:
> $self->{'foo'}->{'bar'}->{'dog'} = "fred";
> $self->{'foo'}->{'bar'}->{'blue'}->{'cat'} = "barney";
> 
> 
> $self->{'foo'}->{'ban'}->{'dog'} = "wilma";
> $self->{'foo'}->{'ban'}->{'cat'} = "betty";
> 
> 
> $self->{'foo'}->{'bas'}->{'dog'}= "bambam";
> $self->{'foo'}->{'bas'}->{'cat'} = "dino";
> 
> Where I want all entries which have a key = "cat". The trick is that the 
> depth of the hashref tree is not constant. (line2) otherwise I'd just use a 
> bunch of nested foreach statements. 

You haven't said what else you want to do with the data, but for
the problem at hand what you want is not a hash of hashes but
multidimensional array emulation (see "$;" in perlvar).

    my $self;
    $self->{'foo', 'bar', 'dog'} = "fred";
    $self->{'foo', 'bar', 'blue', 'cat'} = "barney";

    $self->{'foo', 'ban', 'dog'} = "wilma";
    $self->{'foo', 'ban', 'cat'} = "betty";

    $self->{'foo', 'bas', 'dog'}= "bambam";
    $self->{'foo', 'bas', 'cat'} = "dino";

    $self->{'foo', 'cat', 'paw'} = "wilma";

    /\bcat\b/ and print "$_ => $self->{ $_}\n" for keys %$self;

Anno


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

Date: Tue, 14 Jun 2005 23:00:06 GMT
From: Damian James <djames@thehub.com.au>
Subject: Re: Masking by columns for grep
Message-Id: <slrndaum6j.gf6.djames@puli.home>

On 14 Jun 2005 11:16:37 GMT, Anno Siegel said:
> ...
> Rewriting it
> 
>     @foo = grep /\G\Q$theString/, map { pos = 50; $_ } @foo;
> 
> still suffers from the fact that the elements that map() returns don't
> have their pos() set.  I admit that I don't quite understand that.

Me either from my reading of the docs. 

> $_ in map should be an alias to the current element of @foo, and
> grep should see an alias to that, with its position set.
> 
> This works as intended:
> 
>     pos = 50 for @foo;
>     @foo = grep /\G\Q$theString/, @foo;

Curious. I would find the following more obvious about what it does:

    @foo = grep { pos = 50; /\G\Q$theString/ } @foo; 

I don't really understand where the position is being kept in your
version (or rather, how grep() knows about it).

--damian


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

Date: 15 Jun 2005 08:12:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Masking by columns for grep
Message-Id: <d8onsm$ro9$1@mamenchi.zrz.TU-Berlin.DE>

Damian James  <djames@thehub.com.au> wrote in comp.lang.perl.misc:
> On 14 Jun 2005 11:16:37 GMT, Anno Siegel said:
> > ...
> > Rewriting it
> > 
> >     @foo = grep /\G\Q$theString/, map { pos = 50; $_ } @foo;
> > 
> > still suffers from the fact that the elements that map() returns don't
> > have their pos() set.  I admit that I don't quite understand that.
> 
> Me either from my reading of the docs. 
> 
> > $_ in map should be an alias to the current element of @foo, and
> > grep should see an alias to that, with its position set.
> > 
> > This works as intended:
> > 
> >     pos = 50 for @foo;
> >     @foo = grep /\G\Q$theString/, @foo;
> 
> Curious. I would find the following more obvious about what it does:
> 
>     @foo = grep { pos = 50; /\G\Q$theString/ } @foo; 

Of course!  Much better.

> I don't really understand where the position is being kept in your
> version (or rather, how grep() knows about it).

The position is a property of every string and lives as long as
the string lives.  Once the position is set for all strings in @foo, 
the regex in grep() can use it.

The position is fragile in that it isn't copied with the string:

    $x = '123';
    pos $x = 2;
    $y = $x;

leaves $x with a position of 2, but $y has undefined position.

Anno


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

Date: Wed, 15 Jun 2005 01:04:00 -0700
From: Chris <chriss@activestate.com>
Subject: Re: perl one liner to display the third line from the end of a file
Message-Id: <d8ong8$98d$1@nntp.itservices.ubc.ca>

Glenn Jackman wrote:
> At 2005-06-07 03:27PM, Oxnard <shankeypNO_SPAM@comcast.net> wrote:
> 
>> perl v5.8.0
>> 
>> Assuming the file is a random length text file.
>> I know I can do this in a Perl script, however I would like to add the one 
>> liner to an shell script.
>> Anyone have idea ideas on how to do this?
> 
> 
> Not a high golf score, but you don't have to read every line in the
> file.  It assumes that the final 3 lines can be contained in the last
> 1024 bytes of the file though.
> 
> perl -e '
>     open $fid, "<", shift;
>     $buf = 1024;
>     seek $fid, -$buf, 2;
>     $bytes = read $fid, $data, $buf;
>     @lines = split /\n/, $data, -1; # preserve trailing blank lines
>     pop @lines; # but ignore the trailing newline that ends the file
>     print $lines[-3], "\n"
> ' file
> 
> 

Funny that you mention golf scores. A problem very similar to this came 
up at work the other day, and a few of the heavyweight perl gurus played 
golf with it. I think the question was "how do I return the last 10 
lines of a file".

Without slurping the whole file into memory, the two lowest golf scores 
were:
    perl -ne 'END{print@l}shift@l,if+10<push@l,$_' file
    perl -ne 'END{print@l}10<push@l,$_,&&shift@l' file

Including slurping, we got the following gem:

    perl -e 'print+(<>)[-10..-1]' file

-chris


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

Date: Wed, 15 Jun 2005 11:07:17 GMT
From: Damian James <djames@thehub.com.au>
Subject: Re: perl one liner to display the third line from the end of a file
Message-Id: <slrndb02kq.go6.djames@puli.home>

On Wed, 15 Jun 2005 01:04:00 -0700, Chris said:
> Funny that you mention golf scores. A problem very similar to this came 
> up at work the other day, and a few of the heavyweight perl gurus played 
> golf with it. I think the question was "how do I return the last 10 
> lines of a file".
> 
> Without slurping the whole file into memory, the two lowest golf scores 
> were:
>     perl -ne 'END{print@l}shift@l,if+10<push@l,$_' file
>     perl -ne 'END{print@l}10<push@l,$_,&&shift@l' file

If it's golf score that matters:

      perl -ne '10<push@l,$_,&&shift@l}{print@l' file

> Including slurping, we got the following gem:
> 
>     perl -e 'print+(<>)[-10..-1]' file

Looks optimised to me.

--damian


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

Date: Wed, 15 Jun 2005 14:35:37 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: perl one liner to display the third line from the end of a file
Message-Id: <3hali6FfvpkfU1@individual.net>

* Damian James schrieb:
> On Wed, 15 Jun 2005 01:04:00 -0700, Chris said:
>>
>> I think the question was "how do I return the last 10 
>> lines of a file".
>> 
>> Without slurping the whole file into memory, the two lowest golf scores 
>> were:
>>     perl -ne 'END{print@l}shift@l,if+10<push@l,$_' file
>>     perl -ne 'END{print@l}10<push@l,$_,&&shift@l' file
> 
> If it's golf score that matters:
> 
>      perl -ne '10<push@l,$_,&&shift@l}{print@l' file

Without using push() and shift() we could write:

       perl -ne '@l=(@l[-9..-1],$_)}{print@l' file

Btw, nice trick with unbalanced "}{" ;-)

regards,
fabian


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

Date: 15 Jun 2005 04:25:51 -0700
From: fritz-bayer@web.de (Fritz Bayer)
Subject: Regular Expression not working
Message-Id: <a9c0aa9e.0506150325.1faffd66@posting.google.com>

Hello,

I'm trying to extract urls from a document. 

The following code does not work correctly:

while ($content =~ m!$(<p
class=(["']?)g\2>.*?>.*?<a.*?href=(["'])?(http://([^\3]+)))!ig)
	{
		print "1 $1\n";
		print "2 $2\n";
		print "3 $3\n";
		print "4 $4\n";
		print "5 $5\n";
	}

The problem is that 

([^\3]+)

is also matching the character " or ' from the third capturing group,
even though it should NOT.

If matches them not because the third capturing is empty (not " or '),
but because somehow \3 can't be used inside a [...] block.

Why is that and whats the workaround for this?

Fritz


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

Date: Wed, 15 Jun 2005 12:19:22 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Regular Expression not working
Message-Id: <11b076agfgk51a2@corp.supernews.com>

In article <a9c0aa9e.0506150325.1faffd66@posting.google.com>,
    Fritz Bayer <fritz-bayer@web.de> wrote:

: I'm trying to extract urls from a document. 
: [...]
: Why is that and whats the workaround for this?

The workaround is to use the HTML::LinkExtor module from CPAN:

http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm

I also see brian d foy's HTML::SimpleLinkExtor, but I haven't
used it.

Hope this helps,
Greg
-- 
Capitalism got better press in Pravda than our Ballot Initiative
to End the Income Tax gets from the Big Boston Media.
    -- Carla Howell


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

Date: Wed, 15 Jun 2005 00:38:02 -0700
From: Chris <chriss@activestate.com>
Subject: Re: Which are the "CPAN superstars"?
Message-Id: <d8olvh$7n3$1@nntp.itservices.ubc.ca>

kj wrote:
> CPAN is a somewhat overwhelming resource.  The number of available
> modules is huge, but there is little to guide the user towards "the
> best of CPAN."  (I'm aware of the star rating system, but it doesn't
> seem to be very much used.)
> 
> Is there some to find out which modules are the "CPAN superstars"?
> 
> One proxy for "best" would be "most downloaded."  The rationale
> for this approximation is that the better modules get more
> word-of-mouth advertising, and therefore more downloads.  Certainly,
> it is quite likely that this approach will miss many unsung gems,
> but it's better than nothing.
> 
> Is there a way to get statistics such as number of downloads that
> may help discern the hottest CPAN modules?
> 
> Thanks!
> 
> kj
> 

An overall CPAN "best of" list doesn't make much sense. The "best" 
module for the job is not necessarily indicated by number of downloads. 
You should identify the problem, then look for a module, not the other 
way around. The fact that DBI is very popular won't help you much if 
you're trying to use gnuplot.

That said, a per-category statistics list may be a good idea...

-chris


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

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 8173
***************************************


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