[25976] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8195 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 23 18:05:43 2005

Date: Thu, 23 Jun 2005 15:05:10 -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, 23 Jun 2005     Volume: 10 Number: 8195

Today's topics:
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <1usa@llenroc.ude.invalid>
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <a.newmane.remove@eastcoastcz.com>
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <clarkcox3@gmail.com>
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <1usa@llenroc.ude.invalid>
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <eric.sosman@sun.com>
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <a.newmane.remove@eastcoastcz.com>
    Re: [OT] Re: "use CGI " hangs  "CGI time out " <cbfalconer@yahoo.com>
    Re: Fixed: ActiveState: Can't spawn "cmd.exe"? <occitan@esperanto.org>
    Re: How can I pick up those big numbers <usenet@vyznev.invalid>
    Re: ignoring SIGCHLD <moritz.karbach@desy.de>
    Re: ignoring SIGCHLD (Anno Siegel)
        issue with Text::ParseWords <keithclay@gmail.com>
        Newbie Help <tony@heagren.com>
    Re: Newbie Help (Anno Siegel)
    Re: Newbie Help <scobloke2@infotop.co.uk>
    Re: Newbie Help <john@castleamber.com>
    Re: Newbie Help (Anno Siegel)
    Re: remove specific line from al ltext fiels in dir? <tadmc@augustmail.com>
    Re: Sorting on sub-hash values <richard@zync.co.uk>
    Re: Sorting on sub-hash values <someone@somewhere.com>
    Re: Sorting on sub-hash values <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Sorting on sub-hash values <someone@somewhere.com>
    Re: summarize bytes <dave@nospam.com>
    Re: summarize bytes <1usa@llenroc.ude.invalid>
    Re: The non-terminating script, revisited <mddibern@uwaterloo.ca>
    Re: The non-terminating script, revisited <mddibern@uwaterloo.ca>
    Re: The non-terminating script, revisited xhoster@gmail.com
    Re: The non-terminating script, revisited <mddibern@uwaterloo.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Jun 2005 18:28:33 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <lbDue.351300$cg1.117405@bgtnsc04-news.ops.worldnet.att.net>

Alfred Z. Newmane wrote:
> Bart Lateur wrote:
> 
>>Tassilo v. Parseval wrote:
>>
>>
>>>Hence your analogy to declaring both a double and and int in the same
>>>statement is not applicable. In:
>>>
>>>   int a, *p;
>>>
>>>both 'a' and '*p' are integers.
>>
>>But it doesn't declare *p, it declares p. That's what it's for. *p
>>does actually even exist yet, as p is NULL.
> 
> 
> in c and c++ variables that are uninialized usually have a random value, 
> not NULL or 0 (zero.)
> 
> Someone correct me if I'm wrong, 

I don't think you are wrong, however, you might want to move this 
discussion to comp.lang.c

Sinan


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

Date: Thu, 23 Jun 2005 11:38:33 -0700
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <3i0dtjFj2afvU1@individual.net>

A. Sinan Unur wrote:
> Alfred Z. Newmane wrote:
>> Bart Lateur wrote:
>>
>>> Tassilo v. Parseval wrote:
>>>
>>>
>>>> Hence your analogy to declaring both a double and and int in the
>>>> same statement is not applicable. In:
>>>>
>>>>   int a, *p;
>>>>
>>>> both 'a' and '*p' are integers.
>>>
>>> But it doesn't declare *p, it declares p. That's what it's for. *p
>>> does actually even exist yet, as p is NULL.
>>
>>
>> in c and c++ variables that are uninialized usually have a random
>> value, not NULL or 0 (zero.)
>>
>> Someone correct me if I'm wrong,
>
> I don't think you are wrong, however, you might want to move this
> discussion to comp.lang.c

Thats probably a good idea.

Also, please be careful with your quoting, you cut off my sentance, thus 
throwing off the context a little:

From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Newsgroups: comp.lang.perl.misc
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Date: Thu, 23 Jun 2005 10:21:06 -0700
Message-ID: <3i09ccFivgcoU1@individual.net>

Bart Lateur wrote:
> Tassilo v. Parseval wrote:
>
>> Hence your analogy to declaring both a double and and int in the same
>> statement is not applicable. In:
>>
>>    int a, *p;
>>
>> both 'a' and '*p' are integers.
>
> But it doesn't declare *p, it declares p. That's what it's for. *p
> does actually even exist yet, as p is NULL.

in c and c++ variables that are uninialized usually have a random value,
not NULL or 0 (zero.)

Someone correct me if I'm wrong, but it's the value of an uninialized
variable simply the value that was last i nthe address the new var now
occupies? (I never really thought about it like this before this
thread.)





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

Date: Thu, 23 Jun 2005 15:02:12 -0400
From: Clark S. Cox III <clarkcox3@gmail.com>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <2005062315021250073%clarkcox3@gmailcom>

On 2005-06-23 14:38:33 -0400, "Alfred Z. Newmane" 
<a.newmane.remove@eastcoastcz.com> said:

> Bart Lateur wrote:
>> Tassilo v. Parseval wrote:
>> 
>>> Hence your analogy to declaring both a double and and int in the same
>>> statement is not applicable. In:
>>> 
>>> int a, *p;
>>> 
>>> both 'a' and '*p' are integers.
>> 
>> But it doesn't declare *p, it declares p. That's what it's for. *p
>> does actually even exist yet, as p is NULL.
> 
> in c and c++ variables that are uninialized usually have a random value,
> not NULL or 0 (zero.)

Correct.

> Someone correct me if I'm wrong, but it's the value of an uninialized
> variable simply the value that was last i nthe address the new var now
> occupies? (I never really thought about it like this before this
> thread.)

It might be, it might not be. It is entirely legal for a particular C 
implementation to zero-out all variables before their use; of course it 
is also legal for them to do absolutely nothing to them. You simply 
can't count on either behavior. Whether or not that value has any 
relation to what was in memory before is not specified by the C 
language.



-- 
Clark S. Cox, III
clarkcox3@gmail.com



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

Date: Thu, 23 Jun 2005 19:20:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <Xns967E9C09421A7asu1cornelledu@127.0.0.1>

"Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com> wrote in
news:3i0dtjFj2afvU1@individual.net: 

> A. Sinan Unur wrote:
>> Alfred Z. Newmane wrote:
>>> Bart Lateur wrote:
>>>
>>>> Tassilo v. Parseval wrote:
>>>>
>>>>
>>>>> Hence your analogy to declaring both a double and and int in the
>>>>> same statement is not applicable. In:
>>>>>
>>>>>   int a, *p;
>>>>>
>>>>> both 'a' and '*p' are integers.
>>>>
>>>> But it doesn't declare *p, it declares p. That's what it's for. *p
>>>> does actually even exist yet, as p is NULL.
>>>
>>>
>>> in c and c++ variables that are uninialized usually have a random
>>> value, not NULL or 0 (zero.)
>>>
>>> Someone correct me if I'm wrong,
>>
>> I don't think you are wrong, however, you might want to move this
>> discussion to comp.lang.c
> 
> Thats probably a good idea.
> 
> Also, please be careful with your quoting, you cut off my sentance,
> thus throwing off the context a little:

My comments were not related to your theorizing regarding the value of 
an uninitialized variable. I have been trying to point out that this 
topic is not appropriate for c.l.p.misc for a while now.

I am so sorry that my attempt at correcting your bogus explanation of 
why the OP my the mistake of declaring variables as in

my $x, $y, $z;

has led to this to the materialization of this thread.

Please, if you want to discuss C, comp.lang.c is the place. There was no 
reason to bring C into this thread (which you originally did, and which 
is why I marked my response to you OT).

I have lost patience.

*PLONK*

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Thu, 23 Jun 2005 15:32:44 -0400
From: Eric Sosman <eric.sosman@sun.com>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <d9f2ot$qhr$1@news1brm.Central.Sun.COM>



Clark S. Cox III wrote:
> On 2005-06-23 14:38:33 -0400, "Alfred Z. Newmane" 
> <a.newmane.remove@eastcoastcz.com> said:
>>
>>in c and c++ variables that are uninialized usually have a random value,
>>not NULL or 0 (zero.)
> 
> 
> Correct.

    Well, partly correct.  An uninitialized variable of
`auto' or `register' storage class "contains garbage" --
formally, its value is indeterminate.

    Things are different, though, for variables declared
at file scope (outside any function) or for function-local
variables declared `static'.  If no initializer is present,
these variables are initialized to zero or NULL before
the program starts executing.  At file scope,

	int i;
	double d;
	char *p;

is equivalent to

	int i = 0;
	double d = 0.0;
	char *p = 0;    /* NULL */

-- 
Eric.Sosman@sun.com



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

Date: Thu, 23 Jun 2005 14:59:58 -0700
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <3i0pn8Fj2gdtU1@individual.net>

A. Sinan Unur wrote:
> "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com> wrote in
> news:3i0dtjFj2afvU1@individual.net:
>
>> A. Sinan Unur wrote:
>>> Alfred Z. Newmane wrote:
>>>> Bart Lateur wrote:
>>>>
>>>>> Tassilo v. Parseval wrote:
>>>>>
>>>>>
>>>>>> Hence your analogy to declaring both a double and and int in the
>>>>>> same statement is not applicable. In:
>>>>>>
>>>>>>   int a, *p;
>>>>>>
>>>>>> both 'a' and '*p' are integers.
>>>>>
>>>>> But it doesn't declare *p, it declares p. That's what it's for. *p
>>>>> does actually even exist yet, as p is NULL.
>>>>
>>>>
>>>> in c and c++ variables that are uninialized usually have a random
>>>> value, not NULL or 0 (zero.)
>>>>
>>>> Someone correct me if I'm wrong,
>>>
>>> I don't think you are wrong, however, you might want to move this
>>> discussion to comp.lang.c
>>
>> Thats probably a good idea.
>>
>> Also, please be careful with your quoting, you cut off my sentance,
>> thus throwing off the context a little:
>
> My comments were not related to your theorizing regarding the value of
> an uninitialized variable. I have been trying to point out that this
> topic is not appropriate for c.l.p.misc for a while now.
>
> I am so sorry that my attempt at correcting your bogus explanation of
> why the OP my the mistake of declaring variables as in
>
> my $x, $y, $z;
>
> has led to this to the materialization of this thread.
>
> Please, if you want to discuss C, comp.lang.c is the place. There was
> no reason to bring C into this thread (which you originally did, and
> which is why I marked my response to you OT).

I originally mentioned C/C++ as an example of where the OP's thinking 
may have come from. It branched off from there. I did not know it was 
such a heinous crime. I'm sorry, but there is nothing wrong with side 
discussions, it's something that happens sometimes UseNet and even real 
life conversations.

Why you need to act like you're being forced into this thread is beyond 
me, as the user of a news reader can pick what they want to read, and 
pass on the ones they don't like. Try it sometime.

> I have lost patience.

Why are you replying then?

> *PLONK*

And you really think anyone else with a brain and a life gives a 
flipping damn?

Why are you even replying then if you don't care about it? Is it that 
hard for you to just go on to other threads instead of acting like this 
thread should be ignored by everyone just because /YOU/ deem it 
unworthy? If so, it seems others disagree with you as there appeared to 
be a good wholesome conversation going on here, involving others besides 
myself.

A lot of people here have been programming for quite a while, and it's a 
no-brainier that plenty of Perl programmers started in C and/or C++. The 
reason I added comp.lang.c to the ng list was that I wanted to move the 
discussion to the c group, but not leave out the folks in c.l.p.m who 
were following it out in the cold, which to me would seem like a rude 
thing to do. 




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

Date: Thu, 23 Jun 2005 22:02:52 GMT
From: CBFalconer <cbfalconer@yahoo.com>
Subject: Re: [OT] Re: "use CGI " hangs  "CGI time out "
Message-Id: <42BB293E.991291C1@yahoo.com>

"A. Sinan Unur" wrote:
> 
 ... snip ...
> 
> Please, if you want to discuss C, comp.lang.c is the place. There
> was no reason to bring C into this thread (which you originally
> did, and which is why I marked my response to you OT).
> 
> I have lost patience.
> 
> *PLONK*

If you had taken the trouble to look around you you would have seen
that this is in c.l.c, where any mention of perl is OT.  Since you
failed to set follow-ups, that is obviously just fine with you.

-- 
"If you want to post a followup via groups.google.com, don't use
 the broken "Reply" link at the bottom of the article.  Click on 
 "show options" at the top of the article, then click on the 
 "Reply" at the bottom of the article headers." - Keith Thompson




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

Date: Thu, 23 Jun 2005 22:10:28 +0200
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: Fixed: ActiveState: Can't spawn "cmd.exe"?
Message-Id: <42BB1734.8040003@esperanto.org>

la 22.06.2005 00:16 A. Sinan Unur skribis:
> Daniel Pfeiffer <occitan@esperanto.org> wrote in
> news:42B88A3F.9050805@esperanto.org: 
>
>>la 21.06.2005 12:22 A. Sinan Unur skribis:
>>
>>>File::Spec->path
>>
>>However, checking the coding of those functions, they are broken. 
>>Cygwin wrongly inherits from Unix, and that only splits on :, which
>>will completely fail on the like of '/bin:"C:/WINNT":"/Path/with
>>space"'. 
>
> What are you talking about??? Let me fire up Cygwin shell ... Oooops, 
> better add a directory with spaces to my path ... Done, now I fire up 
> the shell.

The problem are the quotes, which can occur both in native Windows and Cygwin. 
  Neither module eliminates them.  And in the latter they also protect the 
colon in C:/, which is not a separator.  Makepp gets this right, because it 
parses the path.  File::Spec::Unix (superclass of Cygwin) just does split(':', 
$ENV{PATH}), splitting right through the middle of C:/ pathes :-(

> FYI:
> 
> $ perl -v
> This is perl, v5.8.6 built for cygwin-thread-multi-64int
> 
> $ perl -MFile::Spec -e 'print $File::Spec::VERSION'
> 3.01
> 
> So, I guess, I need to update.

Updating may help the individual.  But say this is fixed in 5.8.7 or .8, then 
a widely distributed program, which has to cater to older buggy versions, can 
wait years before relying on this.

>>>> Even the file system related ones are handled too
>>>>superficially, e.g. only string manipulations 
>>>
>>>What you were doing was string manipulation using the wrong strings. 
>>>Using File::Spec->path would have been the right thing to do.
>>
>>I wasn't referring to that.  Makepp needs to know when two files point
>>to the same physical file.
>
> That is not what you originally identified as the issue with your code:

Sure, but you brought up a Module as the solution, so I went and looked if it 
would help makepp.  As discussions go, then the scope of this thread 
widenened.  If we were to use the module you propose, then in its full 
breadth, since all of its methods are relevant to makepp.

> Besides, I do not see why your application is interested in figuring out 
> if two paths refer to the same physical file.

Makepp goes far beyond the erratic "timestamp changed" checks of older makes. 
  It takes many aspects of a file into consideration to find out if a 
dependency *really* requires rebuilds.

>>>There was a very illuminating discussion on this in the last few
>>>months. Check the archives.
>>
>>There's quite a bit of discussion -- not sure which you mean.  But
>>what I see, is that for the nitty details you have to do quite a bit
>>of coding around the provided methods.  And even then the authors are
>>often not sure their thing is still portable.
>
> Given your reputation, I am inclined not believe the assertions above. 
> File::Spec has never failed me.

Wow, I have a reputaion — how exciting ;-)  When people post various 20-30 
line wrappers around File::Spec to chase symlinks, then an important task is 
clearly missing in this module.

>>I agree that rebasing makepp's FileInfo.pm on this might make some
>>sence.  But given the problems and incompleteness of File::Spec it is
>>hardly a panacea... 
>
> What are the problems with File::Spec?

If you still don't know, reread this mail, which reiterates two things I 
noticed even before really going into depth.  I had also mentioned 
case_tolerant being wrong on Unix, because not all file systems respect case, 
and on Cygwin, where it doesn't bother to override the wrong inherited value.

Further analysis might or might not reveal more problems.  Software 
correctness is not proveable, and most certainly not with a casual "I never 
had a problem."  But proof to the contrary is not contestable!  (Unless you 
disproove the proofs, which you got wrong on the path case.)

>>Not sure about performance either.  FileInfo is very central to
>>makepp, and when I took out the method lookup, converting it to 
>>function calls, makepp became noticeably faster.
>
> I am inclined to believe any performance problems you had were not due to 
> method versus function calls.

Inclinations may be an interesting hobby, but I am only interested in facts:

$ time perl -e '1 for 0..1000000' # just to show nop does get called
     0.41s real     0.39s user     0.01s system
$ time perl -e 'sub nop {}; nop for 0..1000000'
     2.18s real     2.11s user     0.01s system
$ time perl -e 'sub nop {}; $x = bless {}; $x->nop for 0..1000000'
     2.95s real     2.84s user     0.02s system

That's a 34% overhead for method lookup.  This is especially penalizing for 
accessor methods which do no real work.

coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer

-- 
lerne / learn / apprends / lär dig / ucz się    Esperanto:
                               http://lernu.net/


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

Date: Thu, 23 Jun 2005 13:06:27 +0300
From: Ilmari Karonen <usenet@vyznev.invalid>
Subject: Re: How can I pick up those big numbers
Message-Id: <slrndbl2d3.2vh.usenet@boojum.home.vyznev.net>

* Tong * <sun_tong@users.sourceforge.net> kirjoitti 22.06.2005:
> On Wed, 22 Jun 2005 21:01:53 +0000, A. Sinan Unur wrote:
>>
>> while($s =~ /&#(\d+);/g) {
>
> Hmm, never thought a match can be used like this before -- in each loop,
> $1 get a new match...

Another way to solve your problem is with s///eg.  Something like:

  $string =~ s/&#(\d+);/$1 < 256 ? chr $1 : "[WIDE CHAR $1]"/eg;

If you want to do something more complex with the characters, you
might want to use paired delimiters for the substitution operator:

  $string =~ s(&#(\d+);) {
      my $char;
      if ($1 < 256) {
          $char = chr $1;
      } else {
          $char = "[WIDE CHAR $1]";
      }
      $char;
  }eg;

(Yes, that's exactly the same as the first example, just longer.)

-- 
Ilmari Karonen
To reply by e-mail, please replace ".invalid" with ".net" in address.


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

Date: Thu, 23 Jun 2005 14:26:35 +0200
From: Moritz Karbach <moritz.karbach@desy.de>
Subject: Re: ignoring SIGCHLD
Message-Id: <d9e9ps$3rol$1@claire.desy.de>

Anno Siegel wrote:

> You don't, but close() does.

Is it really necessary to close the pipe then?

- Moritz


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

Date: 23 Jun 2005 12:41:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ignoring SIGCHLD
Message-Id: <d9eamk$djo$1@mamenchi.zrz.TU-Berlin.DE>

Moritz Karbach  <moritz.karbach@desy.de> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> 
> > You don't, but close() does.
> 
> Is it really necessary to close the pipe then?

It can't stay open after your program finishes, can it?  Every filehandle
is closed during global destruction.

Anno


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

Date: Thu, 23 Jun 2005 15:47:17 -0500
From: "Keith A. Clay" <keithclay@gmail.com>
Subject: issue with Text::ParseWords
Message-Id: <d9f74h01b7d@news4.newsguy.com>

Folks,

I have a line like the following:
tcp_intranet ims-ms E 8 Bloomingdales@e.bloomingdales.com 
rfc822;jkg00b@acu.edu jkg00b@ims-ms-daemon 20 
/opt/SUNWmsgsr/data/queue/ims-ms/001/ZZe0F2yUp6iTs.00 
<Bloomingdale's.6j4cnxhfq.hw@e.bloomingdales.com> sunone ipmg2.acu.edu 
([192.168.0.2])


When I do:

  my @ln=parse_line('\s+','1',$al);  # $al contains the line above,

I get nothing in @ln.  If I remove the "'" in Bloomingdale's, it works 
fine.  Is there a way around this?

keith


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

Date: Thu, 23 Jun 2005 10:34:24 GMT
From: Tony heagren <tony@heagren.com>
Subject: Newbie Help
Message-Id: <2005062311342416807%tony@heagrencom>

Hi all...

slightly new to this, need to accomplish something simple.

I have 12 jpgs in a directory called "copy"
I need a script to rename "news1.jpg" to "news2.jpg"
and so on through the list.
So 1 becomes 2, 2 becmes 3, 3 becomes 4 etc...

The path from perl script to jpgs is simply:
 ../copy/news1.jpg

All and any help much appreciated.
Tony



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

Date: 23 Jun 2005 10:39:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newbie Help
Message-Id: <d9e3h9$ae6$1@mamenchi.zrz.TU-Berlin.DE>

Tony heagren  <tony@heagren.com> wrote in comp.lang.perl.misc:
> Hi all...
> 
> slightly new to this, need to accomplish something simple.
> 
> I have 12 jpgs in a directory called "copy"
> I need a script to rename "news1.jpg" to "news2.jpg"
> and so on through the list.
> So 1 becomes 2, 2 becmes 3, 3 becomes 4 etc...
> 
> The path from perl script to jpgs is simply:
> ../copy/news1.jpg

perldoc -f opendir
perldoc -f readdir
s/(\d+)/$1 +1/e;
perldoc -f rename

That should give you a start.

Anno


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

Date: Thu, 23 Jun 2005 10:48:28 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Newbie Help
Message-Id: <d9e41s$7ev$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>

Anno Siegel wrote:
> Tony heagren  <tony@heagren.com> wrote in comp.lang.perl.misc:
> 
>>Hi all...
>>
>>slightly new to this, need to accomplish something simple.
>>
>>I have 12 jpgs in a directory called "copy"
>>I need a script to rename "news1.jpg" to "news2.jpg"
>>and so on through the list.
>>So 1 becomes 2, 2 becmes 3, 3 becomes 4 etc...
>>
>>The path from perl script to jpgs is simply:
>>../copy/news1.jpg
> 
> 
> perldoc -f opendir
> perldoc -f readdir
> s/(\d+)/$1 +1/e;
> perldoc -f rename
> 

Mightn't you also need
  perldoc -f sort
So that you rename foo3 to foo4 before renaming foo2 to foo3?


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

Date: 23 Jun 2005 10:56:35 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Newbie Help
Message-Id: <Xns967E3C4908F0castleamber@130.133.1.4>

Tony heagren <tony@heagren.com> wrote:

> Hi all...

Hi: pick your subject with more care.

> I have 12 jpgs in a directory called "copy"
> I need a script to rename "news1.jpg" to "news2.jpg"
> and so on through the list.

I would fire up my editor, open a dos box, get the list of file names,
paste them in the editor, record a macro, and let that one do the trick.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 23 Jun 2005 11:01:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newbie Help
Message-Id: <d9e4q0$ae6$2@mamenchi.zrz.TU-Berlin.DE>

Ian Wilson  <scobloke2@infotop.co.uk> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Tony heagren  <tony@heagren.com> wrote in comp.lang.perl.misc:
> > 
> >>Hi all...
> >>
> >>slightly new to this, need to accomplish something simple.
> >>
> >>I have 12 jpgs in a directory called "copy"
> >>I need a script to rename "news1.jpg" to "news2.jpg"
> >>and so on through the list.
> >>So 1 becomes 2, 2 becmes 3, 3 becomes 4 etc...
> >>
> >>The path from perl script to jpgs is simply:
> >>../copy/news1.jpg
> > 
> > 
> > perldoc -f opendir
> > perldoc -f readdir
> > s/(\d+)/$1 +1/e;
> > perldoc -f rename
> > 
> 
> Mightn't you also need
>   perldoc -f sort
> So that you rename foo3 to foo4 before renaming foo2 to foo3?

You could move them to another directory at the same time.

The list isn't complete.  "perldoc -f -f" would be another candidate,
to eliminate not-plain files.  I wanted to give the OP enough material
to come up with an attempt at a solution.  Then we could discuss that.

Anno


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

Date: Thu, 23 Jun 2005 14:59:04 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: remove specific line from al ltext fiels in dir?
Message-Id: <slrndbm548.460.tadmc@magna.augustmail.com>

Snail <snail@localhost.com> wrote:
> I've been trying to find a way to remove a line containing a specific 
> string.

> more than 95% of the text in the logs making them rather big.
                                   ^^^^

Are these "live" logs? That is, will logging writes be happening
when you run your cleanup program?

If so, then you better work file locking into the mix.


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


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

Date: Thu, 23 Jun 2005 11:09:37 +0100
From: Richard Gration <richard@zync.co.uk>
Subject: Re: Sorting on sub-hash values
Message-Id: <pan.2005.06.23.10.09.37.527632@zync.co.uk>

On Thu, 23 Jun 2005 10:30:21 +0100, IanW wrote:

> If I have a hash of hashes like this:
> 
> my %hash= ( 'bob' => { 'age' => 35,  'weight' => 160 },
>     'john' => { 'age' => 22,  'weight' => 138 }, 'sue' => { 'age' => 31, 
>     'weight' => 143 } );
> 
> and I want to sort people by their age, how would I go about it?

Well, presumably, you already know how to sort the keys of %hash
alphabetically?

# Note to gurus: I know the coderef is not needed, but
# it clarifies the explanation

my @sorted_keys = sort { $a cmp $b } keys %hash;

Here, $a and $b will be varying keys of %hash when the sort coderef is
called.

I would expect that you also know how to get the age of a person out of
your data structure, for any particular person:

my $johns_age = $hash{john}->{age};

Putting these 2 ideas together leads pretty quickly to:

my @sorted_keys = sort {$hash{$a}->{age}<=>$hash{$b}->{age}} keys %hash

Can you see what's going on here? You're feeding a list of the keys of
%hash to the sort function. In the coderef for the sort, you're using the
keys that are passed in (in $a and $b) to dive into %hash and produce the
age values so they are compared for the sort.

HTH
Rich


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

Date: Thu, 23 Jun 2005 11:09:54 +0100
From: "IanW" <someone@somewhere.com>
Subject: Re: Sorting on sub-hash values
Message-Id: <X4Sdnep7n9zlFyffRVnytw@giganews.com>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message 
news:d9e13b$8b6$2@mamenchi.zrz.TU-Berlin.DE...
> IanW <someone@somewhere.com> wrote in comp.lang.perl.misc:
>> If I have a hash of hashes like this:
>>
>> my %hash= ( 'bob' => { 'age' => 35,  'weight' => 160 },
>>     'john' => { 'age' => 22,  'weight' => 138 },
>>     'sue' => { 'age' => 31,  'weight' => 143 } );
>>
>> and I want to sort people by their age, how would I go about it?
>
> What have you tried?

nothing as yet.. I've been surfing on the matter for a while now but haven't 
found anyone asking/describing the same question/desire

> Given a name, how would you access the age
> of that person?

foreach my $k (keys %hash) {
    print $hash{$k}{age};
}

Ian 




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

Date: Thu, 23 Jun 2005 12:10:09 +0200
From: Mark <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Sorting on sub-hash values
Message-Id: <42ba8a85$0$3116$8fcfb975@news.wanadoo.fr>

IanW wrote:
> If I have a hash of hashes like this:
> 
> my %hash= ( 'bob' => { 'age' => 35,  'weight' => 160 },
>     'john' => { 'age' => 22,  'weight' => 138 },
>     'sue' => { 'age' => 31,  'weight' => 143 } );
> 
> and I want to sort people by their age, how would I go about it?
> 
> Thanks

perldoc -q sort

Mark


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

Date: Thu, 23 Jun 2005 11:19:51 +0100
From: "IanW" <someone@somewhere.com>
Subject: Re: Sorting on sub-hash values
Message-Id: <tamdnTZ8Le9TESffRVnyvw@giganews.com>


"Richard Gration" <richard@zync.co.uk> wrote in message 
news:pan.2005.06.23.10.09.37.527632@zync.co.uk...
> On Thu, 23 Jun 2005 10:30:21 +0100, IanW wrote:
>
>> If I have a hash of hashes like this:
>>
>> my %hash= ( 'bob' => { 'age' => 35,  'weight' => 160 },
>>     'john' => { 'age' => 22,  'weight' => 138 }, 'sue' => { 'age' => 31,
>>     'weight' => 143 } );
>>
>> and I want to sort people by their age, how would I go about it?
>
> Well, presumably, you already know how to sort the keys of %hash
> alphabetically?


Yes

> # Note to gurus: I know the coderef is not needed, but
> # it clarifies the explanation
>
> my @sorted_keys = sort { $a cmp $b } keys %hash;
>
> Here, $a and $b will be varying keys of %hash when the sort coderef is
> called.
>
> I would expect that you also know how to get the age of a person out of
> your data structure, for any particular person:

Yes

> my $johns_age = $hash{john}->{age};
>
> Putting these 2 ideas together leads pretty quickly to:
>
> my @sorted_keys = sort {$hash{$a}->{age}<=>$hash{$b}->{age}} keys %hash

<sound of penny dropping>

> Can you see what's going on here? You're feeding a list of the keys of
> %hash to the sort function. In the coderef for the sort, you're using the
> keys that are passed in (in $a and $b) to dive into %hash and produce the
> age values so they are compared for the sort.
>
> HTH

It most certainly does.. THANKYOU! :-)

Ian





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

Date: Thu, 23 Jun 2005 12:00:57 +0000
From: "Dave A." <dave@nospam.com>
Subject: Re: summarize bytes
Message-Id: <vaadnbj6PJznOSffRVn-iw@rcn.net>

bastardx wrote:

> ID - is client id
> Date - is server access date
> IN - bytes sent to server
> OUT - bytes received from server
>
> ID    DATE    IN    OUT
> id12    2005-06-07    12    1091
> [...]
> id34    2005-06-07    145    512
> id12    2005-06-07    88    1667
>
> I want to summarize IN and OUT bytes for particular ID per day

> ID    DATE    TOTAL_IN    TOTAL_OUT
> id12 2005-06-07 12314  8098794

(Note: my apologizes to the newsgroup if this appears twice.  I had
somehow managed to subscribe to the "nonexistent" comp.lang.perl in
addition to this group when refreshing my list of newsgroups a couple
of weeks ago.)

=Example code
#!/usr/bin/perl -w

use strict;

sub date_sort(@);

my %clients;
my $separator = '=' x 52;

while (<DATA>) {
  next if /^$/;
  next unless ( scalar (my @fields = split(/\s+/, $_)) == 4);
  my ($id, $date, $bytes_in, $bytes_out) = @fields;
  $clients{$id}{$date}{IN} += $bytes_in unless ($bytes_in !~ /^\d+$/);
  $clients{$id}{$date}{OUT} += $bytes_out unless ($bytes_out !~ /^\d+$/);
}
printf('%-8s %-16s %-16s %-16s', qw[ID DATE BYTES_IN BYTES_OUT]);
print "\n$separator\n";

for my $id (sort keys %clients) {
  my $href = $clients{$id};
  for my $date ( date_sort(keys %$href) ) {
    printf('%-8s %-16s %-16s %-16s', $id, $date, map { $href->{$date}{$_} } qw[IN OUT]);
    print "\n";
  }
  print "$separator\n";
}

sub date_sort(@) {

return map { $_->[0] }
    sort { $a->[1] <=> $b->[1] }
    map  { (my $n = $_) =~ s/[^\d]+//g; [$_, int($n)] } @_;
}

END {
eval(pack('H*', '73797374656d28277065726c646f63207065726c696e74726f2729'));
}

__END__
id12    2005-06-07    12    1091
id16    2005-06-07    893    17881
id12    2005-06-07    53    9912
id34    2005-06-07    323    7211
id34    2005-06-07    15    2381
id34    2005-06-07    542    9771
id16    2005-06-07    90    9912
id16    2005-06-07    409    6712
id12    2005-06-07    311    3443
id34    2005-06-07    342    1123
id12    2005-06-07    90    7455
id34    2005-06-07    145    512
id12    2005-06-07    88    1667
id12    2005-06-08    159    7455
id34    2005-06-08    145    4759
id12    2005-06-08    77    8207
=cut

Dave





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

Date: Thu, 23 Jun 2005 12:35:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: summarize bytes
Message-Id: <Xns967E575E751DDasu1cornelledu@127.0.0.1>

"Dave A." <dave@nospam.com> wrote in
news:vaadnbj6PJznOSffRVn-iw@rcn.net: 

> sub date_sort(@);

FYI, There is no point to having this prototype.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Thu, 23 Jun 2005 15:24:00 -0400
From: Debo <mddibern@uwaterloo.ca>
Subject: Re: The non-terminating script, revisited
Message-Id: <Pine.GSO.4.58.0506231519120.29338@cpu18.student.cs.uwaterloo.ca>

M> Are you using Linux? Multiple threads appear as separate processes with
M> a ps/top listing under Linux.

Cygwin -- and that not by choice.

M> Does Bioperl create separate threads, or,
M> for that matter, is it multiprocessed?

I investigated this, and the answer seems to be no. The library I'm using
is essentially a parser that uses HTTP::Requst::Common to push data
around.

M> Next write a small script that tests that Bioperl is behaving
M> as expected.

I did this before the putting everything together the first time, and it
appeared that Bioperl was doing what it was supposed to. Now, though, I've
narrowed the problem down to a specific Bioperl module, and for the first
time I'm able to consistently reproduce the bug.

So, at this point, this discussion is no longer really topical -- nor
recommended for oral delivery, for that matter.

Thanks for your suggestions.

-Debo




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

Date: Thu, 23 Jun 2005 15:29:14 -0400
From: Debo <mddibern@uwaterloo.ca>
Subject: Re: The non-terminating script, revisited
Message-Id: <Pine.GSO.4.58.0506231524090.29338@cpu18.student.cs.uwaterloo.ca>


ASU> See
ASU>
ASU> perldoc perlsub
ASU>
ASU> for why you should not use & in subroutines call unless you know what
ASU> you are doing.

That's bizarre -- for some reason, the & does the exact opposite of what I
thought it did. I'm not sure exactly where I picked up that habit, but
thank you for pointing out my mistake.

ASU> > #!/usr/bin/perl -w
ASU> BTW:
ASU>
ASU> use warnings;
ASU>
ASU> is better because it allows you turn specific classes of warnings on and
ASU> off in lexical scopes.

Will do. Again, thanks for this.

ASU> It seems clear to me that whatever behavior you are observing must be
ASU> created by code you have not shown us.

And that was sort of the case... see my reply to the previous poster, if
you are (for some reason) curious in the outcome.

Thank you for your helpful suggestions.

-Debo


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

Date: 23 Jun 2005 19:32:48 GMT
From: xhoster@gmail.com
Subject: Re: The non-terminating script, revisited
Message-Id: <20050623153248.992$4w@newsreader.com>

Debo <mddibern@uwaterloo.ca> wrote:
> I have a script that is severely misbehaving. Its purpose is simple: It
> is supposed to retrieve some records from a local database, compare these
> records to others fetched from the NCBI genbank database via BioPerl, and
> then insert the results of these comparisons into the local database.
>
> It does all of these things admirably: However, it seems that it is
> implicitly forking or something because after it terminates, execution
> still continues. I'll elaborate on this in a bit.

Put near the top of your program:

my $oldpid=$$;

Then, after every other statment of your program, put:

die "$oldpid is not $$" unless $oldpid==$$;

> use lib "D:/cygwin/site/www";
> use Site;
> use Bio::Seq;
> use Bio::DB::GenPept;
> <SNIP: Many more Bio:: includes>
> use DBI;
> use Error qw(:try);
> use File::Copy;
> use Log::Log4perl qw(get_logger :levels);

grep through all those module sources for fork or thread.

>
> The Site::createHandle/Stmt etc. commands are just calls to the
> corresponding DBI commands (connect, prepare, execute, etc.) wrapped
> in evals. I'm using PrintError=0, RaiseError=1.

Why oh why do people do this?  Over and over I've had to clean up code
where people used their own no-value-added, buggy, half-assed wrappers
around DBI.  If you are going to use DBI, why not use DBI?

Also, what is the point of setting RaiseError=1 if you are just going
to put evals around every single call?

>
> The abbreviated output (in the log file) looks like this (note that
> there are about 24650 records to be processed):
>
> 2005/06/22 09:44:53 INFO> Job started.
> 2005/06/22 09:44:53 INFO> Examining genbank N. crassa homologues.
> 2005/06/22 09:47:32 INFO>       50 processed.

Can you configure your logger to log the pid along with the time?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 23 Jun 2005 15:48:47 -0400
From: Debo <mddibern@uwaterloo.ca>
Subject: Re: The non-terminating script, revisited
Message-Id: <Pine.GSO.4.58.0506231541490.29338@cpu18.student.cs.uwaterloo.ca>


> > The Site::createHandle/Stmt etc. commands are just calls to the
> > corresponding DBI commands (connect, prepare, execute, etc.) wrapped
> > in evals. I'm using PrintError=0, RaiseError=1.
>
> Why oh why do people do this?  Over and over I've had to clean up code
> where people used their own no-value-added, buggy, half-assed wrappers
> around DBI.  If you are going to use DBI, why not use DBI?

Well, I don't know why those people did it, but I can tell you why I did
it.

I did a quick perusal through Programming the Perl DBI, and they suggested
putting evals around your calls to DBI methods so that you could catch a
raised error when it occurred. However, I got sick of seeing evals all
over my code, and so I pushed them all into one general interface. When
an error is raised, it is logged by a different logger located in the
Site module, so I can still see the output; it doesn't just quash the error.


> Also, what is the point of setting RaiseError=1 if you are just going
> to put evals around every single call?

Am I totally missing the point here? It is possible that I am. I set
RaiseError to 1, place an eval around the call, and then check $@ to see
if anything has gone awry. Most of the time, I don't *want* my script to
die if the call fails -- I would like to attempt some sort of recovery.

Is eval-wrapping a bad thing to do? Again, it was
something I picked up in Programming the Perl DBI. (Admittedly, setting
PrintError to 0 was an asinine thing to do. I've since fixed that.)

Perhaps I should move these questions to a more DBI-centric forum.

> Can you configure your logger to log the pid along with the time?
>
> Xho

I believe I can. If this becomes an issue again, that's what I'll do.

Thanks.

-Debo



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

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


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