[25141] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7390 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 11 00:05:22 2004

Date: Wed, 10 Nov 2004 21:05:08 -0800 (PST)
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, 10 Nov 2004     Volume: 10 Number: 7390

Today's topics:
    Re: 'stat' and it's exceptions <fred@localhost.net>
    Re: 'stat' and it's exceptions <emschwar@pobox.com>
    Re: better way using IO::Select and pool of non-blockig <notvalid@email.com>
    Re: better way using IO::Select and pool of non-blockig <usenet_05_08_2004@stuartmoore.org.uk>
    Re: better way using IO::Select and pool of non-blockig <and11@rol.ru>
    Re: CBC/BLOWFISH, NEWBIE HELP - CAN'T DECRYPT FROM SAVE <gregs@trawna.com>
    Re: CBC/BLOWFISH, NEWBIE HELP - CAN'T DECRYPT FROM SAVE <see@sig.invalid>
        FAQ 9.16: How do I decode a CGI form? <comdog@panix.com>
    Re: how greedy is nongreedy in regexp ? <usenet_05_08_2004@stuartmoore.org.uk>
    Re: Jumping to machine code <see@sig.invalid>
    Re: Legacy End of File Problems with 012 and 000 (Greg Ennis)
    Re: not logical <ahamm@mail.com>
    Re: OT (Re: casting question) <ahamm@mail.com>
    Re: perldoc problem on linux <jwillmore@fastmail.us>
        regexp s// too greedy (bettyann)
    Re: regexp s// too greedy <usenet_05_08_2004@stuartmoore.org.uk>
    Re: regexp s// too greedy <usenet_05_08_2004@stuartmoore.org.uk>
    Re: regexp s// too greedy <noreply@gunnar.cc>
        sorting multiple arrays <Rene.Scheibe@stud.tu-ilmenau.de>
    Re: sorting multiple arrays <and11@rol.ru>
    Re: sorting multiple arrays <jurgenex@hotmail.com>
    Re: sorting multiple arrays <see@sig.invalid>
    Re: Using $SIG{"ALRM"}  assignment inside a subroutine  torahul@gmail.com
    Re: Using $SIG{"ALRM"}  assignment inside a subroutine  <jgibson@mail.arc.nasa.gov>
        warnings on non-text hash keys? (was Re: better way usi <usenet_05_08_2004@stuartmoore.org.uk>
    Re: why is pattern matching using '|' slower than 2 sep <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Nov 2004 18:41:12 -0500
From: fred <fred@localhost.net>
Subject: Re: 'stat' and it's exceptions
Message-Id: <pan.2004.11.10.23.41.06.851803@localhost.net>


> You welcome and I mean it.
> 
> 
> Michele

That's another reason I rarely post here (a fact I'm sure your glad of..)
and that is because more time is spent here discussing discussing perl
rather than actually discussing perl.

If a person was to exhaust every known document on perl before posting
here, and had made an honest effort to that extent, there would be very
few posts here. Nobody to chide.

If something is in a doc or faq ( and there are people who will take time
to point off the diff) what does it hurt to discuss it? I mean you can
ignore it, right?

And about the freeloading stuff, I was KIDDING, get it? I ADMITTED I was
free loading and at the moment lazy... and a couple of people answered me
with excellent replies... and I'm grateful. And a couple of people didn't
"get it".
Sometimes it is just nice to talk about things..

And the killfile stuff was silly. There are many servers to post from and
many ways to obscure who you are.... I have NEVER used my real name on
usenet... I'm gratefully not a member of your "community" in the same way
a homeless person under an LA bridge is not a memeber of that community.

Ah, but for the good old days... well just killfile 'em all!



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

Date: Wed, 10 Nov 2004 18:18:52 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: 'stat' and it's exceptions
Message-Id: <etobre5rxmr.fsf@wilson.emschwar>

fred <fred@localhost.net> writes:
> If a person was to exhaust every known document on perl before posting
> here, and had made an honest effort to that extent, there would be very
> few posts here.

And the ones that were left would be more interesting.

> Nobody to chide.

And what a relief that would be!

> If something is in a doc or faq ( and there are people who will take time
> to point off the diff) what does it hurt to discuss it? I mean you can
> ignore it, right?

It's more that it hurts you, because people who are very knowledgeable
about Perl generally get sick and tired of answering the same question
100 times.  Being basically nice people, they put the answer in a FAQ,
or in the standard documentation.

When you ask a FAQ, two things happen:

1) People who know a lot plonk you, and you lose the further benefit
   of their wisdom when you get to a REALLY hard problem.

2) What's left is people who don't know so much, and they will often
   give you wrong answers, or take 87 times as long to work it out as
   you would have needed had you simply looked in the FAQ (or docs, or
   what-have-you).

The Posting Guidelines (you know, the ones that say "read the FAQ" and
"read the docs") are there for YOUR benefit, not everyone else's.  If
you choose to ignore them, then you get worse help from fewer, less
competent (in general) people.  If you're okay with that, have fun.

Note: asking questions ABOUT a FAQ is okay; asking FAQ is not.

> Sometimes it is just nice to talk about things..

This is a newsgroup for discussing Perl.  If you just want to talk
about things, misc.talk is <---- thataway.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Wed, 10 Nov 2004 23:37:24 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <UCxkd.40533$QJ3.37223@newssvr21.news.prodigy.com>

Andrew Tkachenko wrote:
>  %socks = ();
>  for (0 .. 10) {
>          my $sock = new IO::Socket::INET(..);
>          $socks{$sock} = $_;

That won't do what you think it will. You can NOT access the IO::Socket 
objects using 'keys %socks' since the keys of the hash are stringified.
I would go with:

	$socks[$_] = $sock;

--Ala


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

Date: Wed, 10 Nov 2004 23:40:28 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmu8t3$8gq$1@gemini.csx.cam.ac.uk>

Andrew Tkachenko wrote:
> Sorry, mistaken a bit.
> I've meant:
> 
>  %socks = ();
>  for (0 .. 10) {
>          my $sock = new IO::Socket::INET(..);
>          $socks{$sock} = $_;
>  }
> 

Without Tie::RefHash, any hash keys are strings, so the key would be a 
stringified version of the reference to the socket. This might well seem 
to work for most stuff, if something else (IO::Select for example) is 
keeping a copy of the socket, but e.g. you won't be able to use the 
output of 'keys' as a reference to the socket.

Stuart


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

Date: Thu, 11 Nov 2004 04:03:21 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: better way using IO::Select and pool of non-blockig socks
Message-Id: <cmudth$9so$1@news.rol.ru>

event.pm is a really good thing, but unfortunately not in my case.
I'm still guessing how to embed it into existing project and still didn't find any not 'expensive' solution, because:

1. event.pm forces me to switch to async. way of event processing. 
2. not all of events generated by current code may be represented as io,var,timer and idle events.
3. my 'engine' is inherited by wide range of classes and I'd like to have event processing to be transparent for
all of them.

So when I say 'expensive' I mean just amount of time needed to rewrite existing code to match event.pm demands.
Of course I'd be happy to upload base concepts of my proj. and ask for help to improve it, but I'm not sure
this is a right place for such a things, besides, I'm not sure that this would be a good idea to worry local community with my 
terrible english :)

Thanks for your attention,
Andrew




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

Date: Wed, 10 Nov 2004 18:51:55 -0500
From: Greg Schmidt <gregs@trawna.com>
Subject: Re: CBC/BLOWFISH, NEWBIE HELP - CAN'T DECRYPT FROM SAVED FILE
Message-Id: <3g4d2q9c1ghp$.dlg@trawna.com>

On 10 Nov 2004 12:39:49 -0800, Homer J. wrote:

> I'm stuck.  I'm trying to use Crypt::CBC using Blowfish to encrypt
> some data.  I can get it to encrypt and decrypt OK as long as I assign
> the ciphertext to a variable and decrpyt it from that variable all
> within the same script execution.  However, when I save the ciphertext
> to a text file and then subsequently open the file and read in the
> ciphertext to a variable and finally try to decrypt the cipheredtext I
> get garbage instead of my original test message.
> 
> Someone please help!   I'm sure it's, something obviously wrong that
> I've done, but I can't seem to figure out what it is.

Are you writing and reading the file in binary mode?  Text mode may do odd
things to binary data such as cipertext.

-- 
Greg Schmidt  gregs@trawna.com
  Trawna Publications  http://www.trawna.com/


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

Date: Wed, 10 Nov 2004 21:04:22 -0500
From: Bob Walton <see@sig.invalid>
Subject: Re: CBC/BLOWFISH, NEWBIE HELP - CAN'T DECRYPT FROM SAVED FILE
Message-Id: <4192c665_3@127.0.0.1>

Homer J. wrote:

 ...
> I'm stuck.  I'm trying to use Crypt::CBC using Blowfish to encrypt
> some data.  I can get it to encrypt and decrypt OK as long as I assign
> the ciphertext to a variable and decrpyt it from that variable all
> within the same script execution.  However, when I save the ciphertext
> to a text file and then subsequently open the file and read in the
> ciphertext to a variable and finally try to decrypt the cipheredtext I
> get garbage instead of my original test message.

    perldoc -f binmode

 ...
> Homer
 ...
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: Thu, 11 Nov 2004 05:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 9.16: How do I decode a CGI form?
Message-Id: <cmurq6$82g$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

9.16: How do I decode a CGI form?

    You use a standard module, probably CGI.pm. Under no circumstances
    should you attempt to do so by hand!

    You'll see a lot of CGI programs that blindly read from STDIN the number
    of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
    decoding GETs. These programs are very poorly written. They only work
    sometimes. They typically forget to check the return value of the read()
    system call, which is a cardinal sin. They don't handle HEAD requests.
    They don't handle multipart forms used for file uploads. They don't deal
    with GET/POST combinations where query fields are in more than one
    place. They don't deal with keywords in the query string.

    In short, they're bad hacks. Resist them at all costs. Please do not be
    tempted to reinvent the wheel. Instead, use the CGI.pm or CGI_Lite.pm
    (available from CPAN), or if you're trapped in the module-free land of
    perl1 .. perl4, you might look into cgi-lib.pl (available from
    http://cgi-lib.stanford.edu/cgi-lib/ ).

    Make sure you know whether to use a GET or a POST in your form. GETs
    should only be used for something that doesn't update the server.
    Otherwise you can get mangled databases and repeated feedback mail
    messages. The fancy word for this is ``idempotency''. This simply means
    that there should be no difference between making a GET request for a
    particular URL once or multiple times. This is because the HTTP protocol
    definition says that a GET request may be cached by the browser, or
    server, or an intervening proxy. POST requests cannot be cached, because
    each request is independent and matters. Typically, POST requests change
    or depend on state on the server (query or update a database, send mail,
    or purchase a computer).



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Thu, 11 Nov 2004 00:39:13 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: how greedy is nongreedy in regexp ?
Message-Id: <cmucb9$ff6$1@gemini.csx.cam.ac.uk>

Brian McCauley wrote:
> 
> But since this is a question about canonicalising URLs it would seem 
> more appropriate to use the URI module.  However the canonical() method 
> of URI doesn't do this.  Is this right or should it be considered a bug 
> in URI?

Is www.foo.com/a/b/../c/d always the same as www.foo.com/a/c/d ?

I'd guess on most webservers it is, but surely you can't guarantee it in 
general. Suppose the dots were instead input to a script?

Stuart


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

Date: Wed, 10 Nov 2004 21:33:15 -0500
From: Bob Walton <see@sig.invalid>
Subject: Re: Jumping to machine code
Message-Id: <4192cd2c$1_1@127.0.0.1>

Derek Fountain wrote:

> I have a string in my Perl which contains the machine code for a short
> program I want to run. I want Perl to jump to it. It's the last thing my
> script will do, so I don't care about returning safely, etc. Ideally the
> Perl will just exit neatly, but I really don't mind. I just need that
> machine code to execute. I'm on Win32, but a cross platform method would be
> good.
> 
> How can I do that?

CPAN is your friend.  Check it out, particularly for modules with 
"inline" in their name.  http://www.cpan.org

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: 10 Nov 2004 19:32:21 -0800
From: PoMec@PoMec.Net (Greg Ennis)
Subject: Re: Legacy End of File Problems with 012 and 000
Message-Id: <6c2fdba7.0411101932.303d95a1@posting.google.com>

Bob Walton <see@sig.invalid> wrote in message news:<41917dca$1_4@127.0.0.1>...

> 
> perldoc -f seek
> 
> print $fh "\x00";
> 
> Also check out
> 
>     perldoc perlvar
> 
> particularly the variable $\ .
> ...
Bob,

Thanks much for your help.  I still have not been able to make it work
like I need, but I need to read more about your suggestions.  Thanks
again for the help!!!

Greg


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

Date: Thu, 11 Nov 2004 11:38:08 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: not logical
Message-Id: <2vfqjkF2kre2kU1@uni-berlin.de>

Tassilo v. Parseval wrote:
>
> I am afraid that's entirely untrue. From perlre:

Well that freaking tragic. I looked into the Camel book (3rd ed) and
missed that point. I like my regex's but confess to not using these
specials within character classes.

I stand corrected. Might even use it one day!




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

Date: Thu, 11 Nov 2004 11:43:09 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: OT (Re: casting question)
Message-Id: <2vfqt1F2jm3jaU1@uni-berlin.de>

daniel kaplan wrote:
>
> i'm sorry sinan, what was this then that you wrote?
>
>>> You could not have been much of a C  programmer not knowing the
>>> difference between casting and dereferencing.
>
> go look in the mirror...and tell me who threw out personal insults

Ummmm, to me, Sinan made a perfectly valid statement. It's like saying
"you can't be much of an astronaut if you haven't been into space".

Casting and de-referencing are enormously different.

If you made a simple mistake in choice of words, explain and your position
will be accepted. If you are surprised by the claim, check out a book or
two. Either way, leave the ego out of it.

Anyway, this is why I rarely visit perl newsgroups unless I have a
question I cannot answer myself. It's such a wasteland of brittle
personalities and abuse. What's Duncezilla's current handle?

I'm out of here. Thanks for all the fish.




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

Date: Wed, 10 Nov 2004 23:57:01 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: perldoc problem on linux
Message-Id: <pan.2004.11.11.04.56.59.309864@fastmail.us>

On Wed, 10 Nov 2004 13:30:34 -0800, Zhiliang Hu wrote:

<snip>
> Yes, I did - 'perldoc' is in /usr/local/bin/ and it is in both my and
> ~root's path.  (I double checked them and I still got the same as
> before).
> 
> Following commands work fine:
>  > perloc -V
>  > perldoc -h
>  > perldoc NONEexist    (this returns "No documentation found")
>  > perldoc -l WWW::Search
> 
> but "perldoc WWW::Search" will show nothing but login prompts.

As a "quick fix", you could (since you're on a *nix box) try:
perldoc -t WWW::Search | less

If this works, then you can at least use perldoc until you hunt down the
cause of the problem.

HTH

Jim


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

Date: 10 Nov 2004 19:38:35 -0800
From: bettyann@campbell.com (bettyann)
Subject: regexp s// too greedy
Message-Id: <287ea6c.0411101938.36e6aa41@posting.google.com>

hi all,

can anyone help me limit the greediness of my substitution pattern?  i
have a CSV file and i want to insert a new column of values after the
6th column.  but the new data to be inserted is dependent upon the
value of the 6th column.

example original data:
2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1 
1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1 
5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1 
8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1 

i want to put "0" after the 6th column if the 6th column contains
"hold.bmp".
i want to put "-1" after the 6th column if the 6th column contains
"NaN".

i thought i could do this with two substitutions commands:

s/^((.*?,){5}?(hold.bmp))/$1,0/
s/^((.*?,){5}?(NaN))/$1,-1/

i cannot limit the matching of "hold.bmp" or "NaN".  i want this
pattern to match *only* if "hold.bmp" or "NaN" immediately follows the
5th column.

my test code:
#!/usr/local/bin/perl

use strict;
use warnings;

my $input = <<EOF;
2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1
1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1
5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1
8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1
EOF

my @oData = split( '\n', $input );
my $line;
my $cnt = 0;
foreach $line ( @oData ) {
   printf( "$cnt)  $line \n" );
   $cnt++;
}

my $prevCol = 5;
my @txtList = ( "hold.bmp",   "NaN" );
my @valList = ( "0",          "-1" );
my ( $txt, $cmd, $i );
$i = 0;
foreach $txt ( @txtList ) {
   $cmd = sprintf( '$line =~ s/^((.*?,){%d}?(%s))/$1,%s/;',
      $prevCol, $txt, $valList[$i] );
   printf( "\ncmd >>$cmd<< \n" );
   foreach $line ( @oData ) {
      printf( "orig line |$line| \n" );
      eval $cmd;
      printf( " new line |$line| \n---------------------\n" );
   }
   $i++;
}

exit;

output:
% test2.pl
0)  2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1 
1)  1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1 
2)  5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1 
3)  8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1 

cmd >>$line =~ s/^((.*?,){5}?(hold.bmp))/$1,0/;<< 
orig line |2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
 new line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
---------------------
orig line |1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1|
 new line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,NaN,NaN,hold.bmp,3,1|
---------------------
orig line |5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1| 
 new line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,NaN,8,go.bmp,NaN,1| 
---------------------
orig line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1| 
 new line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,0,NaN,1| 
---------------------

cmd >>$line =~ s/^((.*?,){5}?(NaN))/$1,-1/;<< 
orig line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,NaN,NaN,hold.bmp,NaN,1|
 new line |2,NaN,NaN,NaN,64,hold.bmp,0,1607444,NaN,-1,NaN,NaN,hold.bmp,NaN,1|
---------------------
orig line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,NaN,NaN,hold.bmp,3,1|
 new line |1,NaN,NaN,NaN,32,hold.bmp,0,1607488,NaN,-1,NaN,NaN,hold.bmp,3,1|
---------------------
orig line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,NaN,8,go.bmp,NaN,1| 
 new line |5,NaN,NaN,4,32,hold.bmp,0,1607503,NaN,-1,NaN,8,go.bmp,NaN,1|
---------------------
orig line |8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,0,NaN,1| 
 new line |8,NaN,NaN,4,32,NaN,-1,1607564,NaN,NaN,8,hold.bmp,0,NaN,1| 
---------------------

thanks,
- bettyann


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

Date: Thu, 11 Nov 2004 03:48:35 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: regexp s// too greedy
Message-Id: <cmuneb$71c$1@gemini.csx.cam.ac.uk>

bettyann wrote:

> hi all,
> 
> can anyone help me limit the greediness of my substitution pattern?  i
> have a CSV file and i want to insert a new column of values after the
> 6th column.  but the new data to be inserted is dependent upon the
> value of the 6th column.
> 
> example original data:
> 2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1 
> 1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1 
> 5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1 
> 8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1 
> 
> i want to put "0" after the 6th column if the 6th column contains
> "hold.bmp".
> i want to put "-1" after the 6th column if the 6th column contains
> "NaN".
> 
> i thought i could do this with two substitutions commands:
> 
> s/^((.*?,){5}?(hold.bmp))/$1,0/
> s/^((.*?,){5}?(NaN))/$1,-1/

                ^ Not sure that you want that ?

I suggest replacing (.*?,) with ([^,]*) assuming there isn't some way of 
commas appearing escaped within the data.


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

Date: Thu, 11 Nov 2004 04:02:25 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: regexp s// too greedy
Message-Id: <cmuo89$7or$1@gemini.csx.cam.ac.uk>

Stuart Moore wrote:

> I suggest replacing (.*?,) with ([^,]*) assuming there isn't some way of 
> commas appearing escaped within the data.

That should have been ([^,]*,) of course


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

Date: Thu, 11 Nov 2004 05:15:23 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp s// too greedy
Message-Id: <2vg7jeF2j4ntiU1@uni-berlin.de>

bettyann wrote:
> can anyone help me limit the greediness of my substitution pattern?  i
> have a CSV file and i want to insert a new column of values after the
> 6th column.  but the new data to be inserted is dependent upon the
> value of the 6th column.
> 
> example original data:
> 2,NaN,NaN,NaN,64,hold.bmp,1607444,NaN,NaN,NaN,hold.bmp,NaN,1 
> 1,NaN,NaN,NaN,32,hold.bmp,1607488,NaN,NaN,NaN,hold.bmp,3,1 
> 5,NaN,NaN,4,32,hold.bmp,1607503,NaN,NaN,8,go.bmp,NaN,1 
> 8,NaN,NaN,4,32,NaN,1607564,NaN,NaN,8,hold.bmp,NaN,1 
> 
> i want to put "0" after the 6th column if the 6th column contains
> "hold.bmp".
> i want to put "-1" after the 6th column if the 6th column contains
> "NaN".
> 
> i thought i could do this with two substitutions commands:
> 
> s/^((.*?,){5}?(hold.bmp))/$1,0/
> s/^((.*?,){5}?(NaN))/$1,-1/
> 
> i cannot limit the matching of "hold.bmp" or "NaN".  i want this
> pattern to match *only* if "hold.bmp" or "NaN" immediately follows the
> 5th column.

Limiting to a fixed number of occurrences while using '.*' is 
contradictory, irrespective of greediness. Besides a few other things, I 
believe that the most important change you should make is to get rid of 
that problem by replacing the '.' meta character with the character 
class '[^,]'. This might do it, using only one substitution:

     s/^((?:[^,]*,){5}(?:(hold\.bmp)|NaN))/"$1,".($2 ? '0' : '-1')/e;

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


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

Date: Thu, 11 Nov 2004 02:33:13 +0100
From: =?ISO-8859-1?Q?Ren=E9_Scheibe?= <Rene.Scheibe@stud.tu-ilmenau.de>
Subject: sorting multiple arrays
Message-Id: <2vftqcF2lc592U1@uni-berlin.de>

hi folks,
i am a bit new to perl and cant get my problem solved.

i do some network statistics which i have read into 4 arrays.
   1. @hosts: holding the hostnames or ips
   2. @in: bytes in
   3. @out: bytes out
   4. @total: bytes in + out
so for one host i have an entry in every array with the same index.

how can i now sort them?
i want them to be ordered depending on @total.

many thanks in advance
rene


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

Date: Thu, 11 Nov 2004 04:45:35 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: sorting multiple arrays
Message-Id: <cmugcn$a6j$1@news.rol.ru>

IMHO, this way:

for (sort {$total[$a] <=> $total[$b]} (0 .. $#total)) {
        print join ("\t", $hosts[$_], $in[$_], $out[$_], $total[$_]),"\n"
}

check  
perldoc -f sort

Regards,
Andrew

René Scheibe wrote:

> hi folks,
> i am a bit new to perl and cant get my problem solved.
> 
> i do some network statistics which i have read into 4 arrays.
>    1. @hosts: holding the hostnames or ips
>    2. @in: bytes in
>    3. @out: bytes out
>    4. @total: bytes in + out
> so for one host i have an entry in every array with the same index.
> 
> how can i now sort them?
> i want them to be ordered depending on @total.
> 
> many thanks in advance
> rene

-- 
Andrew


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

Date: Thu, 11 Nov 2004 01:57:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: sorting multiple arrays
Message-Id: <0Gzkd.730$ho6.177@trnddc05>

René Scheibe wrote:
> hi folks,
> i am a bit new to perl and cant get my problem solved.
>
> i do some network statistics which i have read into 4 arrays.
>   1. @hosts: holding the hostnames or ips
>   2. @in: bytes in
>   3. @out: bytes out
>   4. @total: bytes in + out
> so for one host i have an entry in every array with the same index.
>
> how can i now sort them?
> i want them to be ordered depending on @total.

Poor choice of data structure. Why four independant arrays which you have to 
keep in sync manually?
A far better approach would be an array of hashes where each array element 
is (a pointer to) a hash containing four values: host, in, out, and total. 
Then it would be trivial to use sort() to sort that array.

The way you implemented the data structure I'm kind of afraid you will have 
to implement your own sort. At least I don't see a straigh-forward way to 
leverage the build-in sort() function to read from one array and manipulate 
four arrays simultaneously.

jue 




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

Date: Wed, 10 Nov 2004 20:58:14 -0500
From: Bob Walton <see@sig.invalid>
Subject: Re: sorting multiple arrays
Message-Id: <4192c4f5_3@127.0.0.1>

René Scheibe wrote:

> hi folks,
> i am a bit new to perl and cant get my problem solved.
> 
> i do some network statistics which i have read into 4 arrays.
>   1. @hosts: holding the hostnames or ips
>   2. @in: bytes in
>   3. @out: bytes out
>   4. @total: bytes in + out
> so for one host i have an entry in every array with the same index.
> 
> how can i now sort them?
> i want them to be ordered depending on @total.
> 
> many thanks in advance
> rene

Have you looked at the FAQ:

    perldoc -q "sort an array"

?  You don't say what is in @total, but I'll assume it is numbers, and 
that you want to sort numerically.  You could alter your data structure 
to make it a bit more natural to your problem, perhaps making it an 
array of hashes, with four keys in each hash.  But assuming you don't 
want to do that, you would be best off to generate an index which will 
sort your arrays, maybe something like:

    my @index=sort {$total[$a] <=> $total[$b]} (0..$#total);
    @hosts=@hosts[@index];
    @in=@in[@index];
    @out=@out[@index];
    @total=@total[@index];
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: 10 Nov 2004 16:13:20 -0800
From: torahul@gmail.com
Subject: Re: Using $SIG{"ALRM"}  assignment inside a subroutine ...
Message-Id: <e713d286.0411101613.d8f5b08@posting.google.com>

Brian McCauley <nobull@mail.com> wrote in message news:<cmtnnm$33f$1@sun3.bham.ac.uk>...
> torahul@gmail.com wrote:
> 
> > [...] regarding calling subroutine withour '&' prefix, I wasn't aware of
> > 'this' way of calling subroutine (and hence difference between both!).
> > The book which I am reading might be either older edition or has not
> > make these things clear about subroutine -- at least till the point I
> > have finished reading :-).
> > 
> > Usage of 'my' instead of 'local', 'use strict' are also new to me --
> > and after browsing little thru online perl documentation, is making
> > things clearer now.
> 
> Sounds like your book predates Perl5.  A lot changed between Perl4 and 
> Perl5.  There is no point trying to learn Perl5 using a book about Perl4.

You are very correct -- I looked at the Perl version this book uses
and it's 4.036! Anyway, nothing goes waste -- will now be able to
appreciate new features of Perl 5 and later versions, more easily :-)

I'm now planning to read 3rd editions of "Learning Perl" by Randal and
then "Programming Perl" by Larry Wall -- any other recommendations ?


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

Date: Wed, 10 Nov 2004 16:48:59 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Using $SIG{"ALRM"}  assignment inside a subroutine ...
Message-Id: <101120041648590375%jgibson@mail.arc.nasa.gov>

In article <e713d286.0411101613.d8f5b08@posting.google.com>,
<torahul@gmail.com> wrote:


> 
> I'm now planning to read 3rd editions of "Learning Perl" by Randal and
> then "Programming Perl" by Larry Wall -- any other recommendations ?

See 'perldoc -q book' for book recommendations and links.


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

Date: Thu, 11 Nov 2004 01:37:43 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: warnings on non-text hash keys? (was Re: better way using IO::Select and pool of non-blockig socks)
Message-Id: <cmufou$m4t$1@gemini.csx.cam.ac.uk>

Stuart Moore wrote:

> Andrew Tkachenko wrote:
> 
>> Sorry, mistaken a bit.
>> I've meant:
>>
>>  %socks = ();
>>  for (0 .. 10) {
>>          my $sock = new IO::Socket::INET(..);
>>          $socks{$sock} = $_;
>>  }
>>
> 
> Without Tie::RefHash, any hash keys are strings, so the key would be a 
> stringified version of the reference to the socket. This might well seem 
> to work for most stuff, if something else (IO::Select for example) is 
> keeping a copy of the socket, but e.g. you won't be able to use the 
> output of 'keys' as a reference to the socket.

Just a thought, would attempting to use a reference as a hash key be a 
suitable thing to mention when "use warnings;" is on? Neither warnings 
nor diagnostics seems to do anything


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

Date: Thu, 11 Nov 2004 01:20:09 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: why is pattern matching using '|' slower than 2 separate ones?
Message-Id: <cmueo9$1lo0$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Dave
<daveandniki@ntlworld.com>], who wrote in article <3r4kd.189$Av5.115@newsfe4-gui.ntli.net>:

$a = 'ZZZZZZZZZ'; # Or some such

> >     $a=1    if $z=~/xxxxx|yyyyy/;
> > #    $a=1    if $z=~/xxxxx/ or $z=~/yyyyy/;

> For the answer to this and more (if you are interested) have a look at
> Mastering Regular Expressions by Jeremy Friedl

Did not see the newer edition.  Does it describe the operation of REx
optimizer?

> The short answer is that the behaviour is entirely expected. The first 
> version caused the Regex engine to do lots of switching at each position in 
> the string to swap between looking for one then the other. It also hinders 
> the engine from doing certain optimisations which are easy with the simple 
> literal string.

This has little relation to what actually happens.  The REx engine
proper is not even entered with these patterns.  It is the optimizer
who rejects the match.  And with the first version it tries to find
'x' or 'y' inside the string - which is much slower that looking for
'x' at each 5th position - as the second version does.

IMO, it is the "each 5th position" which helps - not switching between
two possibilities.

Run with use re 'debugcolor' for details,
Ilya



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

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


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