[23076] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5297 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 31 11:05:42 2003

Date: Thu, 31 Jul 2003 08:05:08 -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           Thu, 31 Jul 2003     Volume: 10 Number: 5297

Today's topics:
        Announcing issue 2 of The Agile Developer's Life free e <DevCoach@see.sig.for.address>
        Emacs support for DB? <irving_kimura@lycos.com>
    Re: how to know the week of today? <Dov.Levenglick@motorola.com>
    Re: how to know the week of today? <noreply@gunnar.cc>
    Re: parsing large (>1gb) strings..how? (Tad McClellan)
    Re: parsing large (>1gb) strings..how? <Dov.Levenglick@motorola.com>
    Re: Perl Objects (Paul)
    Re: Perl Objects (Paul)
    Re: removing some text (Tad McClellan)
        semaphore example needed <perseus_medusa@hotmail.com>
        Sorting question <nomail@hursley.ibm.com>
    Re: Sorting question <noreply@gunnar.cc>
    Re: Sorting question <simon.andrews@bbsrc.ac.uk>
    Re: Sorting question <abigail@abigail.nl>
    Re: Sorting question <john.thetenant-s@moving-picture.com>
    Re: Sorting question <noreply@gunnar.cc>
        Transmutation of objects?? <jill_krugman@yahoo.com>
    Re: using post method (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 31 Jul 2003 15:17:28 +0100
From: DevCoach <DevCoach@see.sig.for.address>
Subject: Announcing issue 2 of The Agile Developer's Life free eZine
Message-Id: <l49iivciln0uhttc7seeb339gplev7lua8@4ax.com>

I have just published the second issue of The Agile Developer's Life
(formerly called The Agile Life), a free eZine devoted to the human
side of software development. This issue contains an article on
creativity and software development.  

The Agile Developer's Life is a collection of tools, techniques and
ideas to enable software professionals and teams to go beyond the
status quo and achieve more than they thought possible. Drawing on
ideas from agile software development, psychology, creativity,
complexity, system dynamics and life/business coaching, The Agile
Developer's Life is for anyone in the IT industry who want to find new
ways of improving their work and their lives.

You can read the latest issue at
http://www.thedeveloperscoach.com/AgileLife.htm, or subscribe by
sending a blank email to agile_life-subscribe@topica.com.

Dave Kirby -  The Developers' Coach
Helping software professionals and teams achieve peak performance

email: dave
       @thedeveloperscoach
       .com

web: http://www.thedeveloperscoach.com 
  - sign up for my new free eZine, The Agile Developer's Life


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

Date: Thu, 31 Jul 2003 15:04:51 +0000 (UTC)
From: Irving Kimura <irving_kimura@lycos.com>
Subject: Emacs support for DB?
Message-Id: <bgbb6j$d4o$1@reader1.panix.com>



The manpage for perldebtut says that "the command line interface
is tightly integrated with an emacs extension", but it doesn't say
what this emacs extension is, or where to find it.  The manpage
for perldebug also alludes to DB/Emacs integration, but is equally
vague on the details.  Where can I find more information on using
Emacs as an IDE for Perl?

Thanks!

	-Irv



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

Date: Thu, 31 Jul 2003 15:18:14 +0300
From: DOV LEVENGLICK <Dov.Levenglick@motorola.com>
Subject: Re: how to know the week of today?
Message-Id: <3F290906.70807@motorola.com>


--------------050202040103050007090504
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit



$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];



C&J wrote:

>Hi,
>Is there any way to know what is the current week?
>January 1 is the first week.
>Thanks
>Chris
>
>
>  
>

-- 
Regards,
Dov Levenglick



--------------050202040103050007090504
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<blockquote> 
  <pre class="programlisting">$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];</pre>
 </blockquote>
<br>
<br>
C&amp;J wrote:<br>
<blockquote type="cite"
 cite="midOWlVa.662$Qb7.504188001@newssvr12.news.prodigy.com">
  <pre wrap="">Hi,
Is there any way to know what is the current week?
January 1 is the first week.
Thanks
Chris


  </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="$mailwrapcol">-- 
Regards,
Dov Levenglick
</pre>
<br>
</body>
</html>

--------------050202040103050007090504--



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

Date: Thu, 31 Jul 2003 14:49:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to know the week of today?
Message-Id: <bgb3g0$mjrnq$2@ID-184292.news.uni-berlin.de>

DOV LEVENGLICK wrote:
> C&J wrote:
>>Is there any way to know what is the current week?
>>January 1 is the first week.
> 
> $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];

Err.. How is that solution related to OP's question?

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



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

Date: Thu, 31 Jul 2003 06:09:09 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: parsing large (>1gb) strings..how?
Message-Id: <slrnbihu6l.a4h.tadmc@magna.augustmail.com>

Patrick Cotner <eternaluxe@comcast.net> wrote:

> Is there a way to
> skip to the next line in a file if the first x characters of the
> current line don't contain what I'm looking for without reading the
> entire string (which can be >1gb at times)?


    perldoc -f read
    perldoc -f seek


But those work strictly on the "number of bytes" rather than
"look for a newline".

You can put your own code together with those to look for "lines".


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


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

Date: Thu, 31 Jul 2003 15:30:52 +0300
From: DOV LEVENGLICK <Dov.Levenglick@motorola.com>
Subject: Re: parsing large (>1gb) strings..how?
Message-Id: <3F290BFC.3040409@motorola.com>

try searching on a substring the size you want:
next unless (substr($_, 0 , 10000) =~ m/\n/)

Patrick Cotner wrote:

>I've written a short perl script which scan an accidentally (or
>stupidly) initialised harddrive for lost files.  Here is the code i
>have thus far (note that the drive I'm scanning is *not* the drive I
>intend to parse once the program is complete...it's just for testing):
>
># 	This program is *not* finished.  All it does now is read lines from
>the
>#	HD and prints them to the terminal window.
>
>
>use warnings;
>use strict;
>
>open (DRIVE, "/dev/disk1s9") || die "Whoops! $!";
>
>while (<DRIVE>) {
>	print $_;	
>
>}
>#    End of program
>
>
>Ok, it's not much anything.  I'll figure the rest out on my own
>(hopefully), but what I need for now is a way to span large (and
>mostly empty) chunks of HD that don't contain \n.  Is there a way to
>skip to the next line in a file if the first x characters of the
>current line don't contain what I'm looking for without reading the
>entire string (which can be >1gb at times)?
>
>Any help would be appreciated.  I just need to be pointed in the right
>direction.
>
>Thanks,  
>Patrick
>  
>

-- 
Regards,
Dov Levenglick




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

Date: 31 Jul 2003 06:33:50 -0700
From: elegans@lycos.com (Paul)
Subject: Re: Perl Objects
Message-Id: <d2992faa.0307310533.614a8904@posting.google.com>

Thanks Bart.  I didn't think my solution agreed with OOP philosophy. 
As a Java programmer, I sometimes have a little trouble with OOP in
Perl!

I implemented your first solution (using closures).  This seems to be
working quite well.  To break the circular reference I simply added a
DESTROY method that undefined the handlers (I think/hope this was
enough).

sub DESTROY {
   my $self = shift;
   $self->{handlers} = undef;
}

Thanks again for your response, it was quite helpful.

Paul


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

Date: 31 Jul 2003 06:40:44 -0700
From: elegans@lycos.com (Paul)
Subject: Re: Perl Objects
Message-Id: <d2992faa.0307310540.324905ed@posting.google.com>

Hi Dave,

Thanks!  I implemented and tested this out... works like a charm!

> Use closures:
> 
> [untested]
> 
>       $parser = new XML::Parser(Handlers => {
> 			Start => sub { $self->handle_start( @_ ) },
> 			End   => sub { $self->handle_end  ( @_ ) },
> 			Char  => sub { $self->handle_char ( @_ ) },
> 		    } );
>   ...
> 
>   sub handle_start {
>       my ($self, $expat, $elem, @atvals) = @_;
>       ...
>   }

Paul


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

Date: Thu, 31 Jul 2003 06:04:11 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: removing some text
Message-Id: <slrnbihttb.a4h.tadmc@magna.augustmail.com>

Tony W <tonyw@shelter.org.uk> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbig4bm.7vr.tadmc@magna.augustmail.com>...
>> Tony W <tonyw@shelter.org.uk> wrote:


>> > I want a line that will remove any a href link, except for the term
>> > (eg landlords - as below)


>> s/(<A HREF="Javascript:popup\('[0-9]+',[^>]*>([^<]*)<\/A>)/
>>   $2 eq 'Landlords' ? $1 : $2
>>  /ige;


> There will be no javascript:popup text.  Therefore what I require is
> some code to get rid of the html anchor,


You already have code to get rid of the html anchor, modify
the code I gave you so that it does not require the Javascript part.


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


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

Date: Thu, 31 Jul 2003 20:44:16 +0800
From: "j" <perseus_medusa@hotmail.com>
Subject: semaphore example needed
Message-Id: <3f290da9$1@newsgate.hknet.com>

Hi all,

    I tried to use IPC::Semaphore but tried for a long time without success.

    What I want to do is like this :
    I want to limit a perl script to be run by 10 users concurrently only. I
want to create 10 semaphore and each user before runing the script, check if
any one of the semaphore available. If not then it die. If there is
available, it takes one. After the script ended, they release the semaphore.

    Please help.

    Thanks.

Perseus




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

Date: Thu, 31 Jul 2003 19:34:17 +0800
From: Derek Fountain <nomail@hursley.ibm.com>
Subject: Sorting question
Message-Id: <3f28fe70$0$23609$5a62ac22@freenews.iinet.net.au>

I have a set of names, each of which has an associated size value. I want to
list these names in size order.

The obvious way is to create a hash where the sizes are the keys and the
associated names are the values, then sort the keys. The problem with that
is that in my data two names might have the same size, so one would replace
the other in my hash.

How do I do this?


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

Date: Thu, 31 Jul 2003 13:45:14 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sorting question
Message-Id: <bgavnj$mbo0i$1@ID-184292.news.uni-berlin.de>

Derek Fountain wrote:
> I have a set of names, each of which has an associated size value.
> I want to list these names in size order.
> 
> The obvious way is to create a hash where the sizes are the keys
> and the associated names are the values, then sort the keys.

Don't know about obvious. It's one way.

The problem with that
> is that in my data two names might have the same size, so one would
> replace the other in my hash.
> 
> How do I do this?

One way: Hash where the names are keys and the sizes values. Sort per
value.

Don't know how? That's a FAQ. See perlfaq4.

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



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

Date: Thu, 31 Jul 2003 12:56:10 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Sorting question
Message-Id: <3F2903DA.1060706@bbsrc.ac.uk>



Derek Fountain wrote:
> I have a set of names, each of which has an associated size value. I want to
> list these names in size order.
> 
> The obvious way is to create a hash where the sizes are the keys and the
> associated names are the values, then sort the keys. The problem with that
> is that in my data two names might have the same size, so one would replace
> the other in my hash.
> 
> How do I do this?

One way would be to make an array of hashes and sort that:

Simon.



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

my @sort_list;

while (<DATA>){
   chomp;
   my ($name,$size) = split(/\s+/);
   push @sort_list, {name=>$name,size=>$size};
}

@sort_list = sort {$a->{size} <=> $b->{size}} @sort_list;

foreach (@sort_list) {
   print "$_->{name} $_->{size}\n";
}


__DATA__
a_file 10
b_file 20
c_file 10
d_file 5



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

Date: 31 Jul 2003 11:57:15 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Sorting question
Message-Id: <slrnbii10r.4g0.abigail@alexandra.abigail.nl>

Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMDCXXI September
MCMXCIII in <URL:news:bgavnj$mbo0i$1@ID-184292.news.uni-berlin.de>:
~~  Derek Fountain wrote:
~~ > I have a set of names, each of which has an associated size value.
~~ > I want to list these names in size order.
~~ > 
~~ > The obvious way is to create a hash where the sizes are the keys
~~ > and the associated names are the values, then sort the keys.
~~  
~~  Don't know about obvious. It's one way.
~~  
~~  The problem with that
~~ > is that in my data two names might have the same size, so one would
~~ > replace the other in my hash.
~~ > 
~~ > How do I do this?
~~  
~~  One way: Hash where the names are keys and the sizes values. Sort per
~~  value.

Just like in the way that failed for the OP (non-unique sizes) yours
will fail if the names aren't unique.


Abigail
-- 
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'


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

Date: Thu, 31 Jul 2003 12:52:16 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Sorting question
Message-Id: <20030731125216.79360d1a.john.thetenant-s@moving-picture.com>

On Thu, 31 Jul 2003 19:34:17 +0800
Derek Fountain <nomail@hursley.ibm.com> wrote:
>
> I have a set of names, each of which has an associated size value. I want to
> list these names in size order.
> 
> The obvious way is to create a hash where the sizes are the keys and the
> associated names are the values, then sort the keys. The problem with that
> is that in my data two names might have the same size, so one would replace
> the other in my hash.
> 
> How do I do this?

if your names are unique, you could sort 
by value rather than key.

this should "sort" you out:
perldoc -q "How do I sort a hash"

if neither your names nor sizes are unique, 
you'll need a more complex hash. and a more
complex sort.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Thu, 31 Jul 2003 14:44:12 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sorting question
Message-Id: <bgb367$mjrnq$1@ID-184292.news.uni-berlin.de>

Abigail wrote:
> Gunnar Hjalmarsson wrote:
>> Derek Fountain wrote:
>>> The problem with that is that in my data two names might have
>>> the same size, so one would replace the other in my hash.
>>> 
>>> How do I do this?
>> 
>> One way: Hash where the names are keys and the sizes values. Sort
>> per value.
> 
> Just like in the way that failed for the OP (non-unique sizes)
> yours will fail if the names aren't unique.

Yes, of course. But there are reasons to assume that, if that's the 
case, OP would realize that...

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



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

Date: Thu, 31 Jul 2003 14:54:18 +0000 (UTC)
From: J Krugman <jill_krugman@yahoo.com>
Subject: Transmutation of objects??
Message-Id: <bgbaiq$d3c$1@reader1.panix.com>



I'm trying to sort out a bug in my code, and I've come across a
strange, and definitely unwanted, "transmutation" of an object's
class.  We can see it in action in the following transcript from
DB (I've added my comments preceded by ### ):

DB<13> c 233
HTTP::Daemon::ClientConn::get_request(/usr/lib/perl5/HTTP/Daemon.pm:233):
233:        vec($fdset, $self->fileno, 1) = 1;

### we print $self to see what it is
  DB<14> p $self
My_Connection=GLOB(0x867223c)

### OK, we step into the fileno method
  DB<15> s
IO::Handle::fileno(/usr/lib/perl/5.6.1/IO/Handle.pm:129):
129:        @_ == 1 or croak 'usage: $io->fileno()';
  DB<15> n
IO::Handle::fileno(/usr/lib/perl/5.6.1/IO/Handle.pm:130):
130:        fileno($_[0]);

### we print $_[0] to see what it is
  DB<15> p $_[0]
My_Connection=GLOB(0x867223c)

### OK, it is what we expect
### we step into the fileno($_[0]) call
  DB<16> s
IO::Socket::SSL::SSL_HANDLE::FILENO(/usr/lib/perl5/IO/Socket/SSL.pm:496):
496:        my $handle = shift;

### huh?  what are we doing in IO::Socket::SSL::SSL_HANDLE?
  DB<16> p $_[0]
IO::Socket::SSL::SSL_HANDLE=SCALAR(0x84def38)

### HUH???
### My_Connection does not inherit from it, directly or indirectly...
### ...and My_Connection->isa confirms it
  DB<17> p My_Connection->isa('IO::Socket::SSL::SSL_HANDLE') ? "it is" : "it ain't"
it ain't
  DB<18>


How can this be???  What is going on here?

More importantly, how can I prevent it from happening?

Thanks for the cluebricks!

	-Jill




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

Date: Thu, 31 Jul 2003 06:30:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: using post method
Message-Id: <slrnbihve9.a4h.tadmc@magna.augustmail.com>

hash <hash_q@yahoo.com> wrote:

> I am trying to use the post method in perl to fill a form.

> but my phone doesn't get the message. 


You need to get at least a little bit of debugging information
before you can do any debugging...


> use LWP::UserAgent;


   use LWP::Debug qw(+);


> my $res = $ua->request($req);


   die 'ERROR: ', $res->status_line(), "\n", $res->error_as_HTML()
      unless $res->is_success;


> print $res->as_string;


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


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

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.  

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


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