[11042] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4642 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 13 13:17:24 1999

Date: Wed, 13 Jan 99 10:00:18 -0800
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, 13 Jan 1999     Volume: 8 Number: 4642

Today's topics:
    Re: a question for perl gurus (I think) (M.J.T. Guy)
    Re: associative arrays (hashes) niemeyer@my-dejanews.com
    Re: BUG: getpwnam()? - Perl shipped with RedHat5.2 (M.J.T. Guy)
    Re: CONCLUSIVE PROOF: Jesus *is* King of the Jews  !    <Ultima2K@NOSPAMaol.com>
    Re: CONCLUSIVE PROOF: The Beatles are bigger than Jesus <lava333@hotmail.com>
    Re: Help needed with locking <jdf@pobox.com>
    Re: How can I compare two arrays? (Ilya Zakharevich)
        Mysterious "Killed" response - help needed. <tttoivan@cc.hut.fi>
        need help with net::telnet... rlopes@securitydynamics.com
    Re: Newbie Question - Matt's wwwboard (Clinton Pierce)
    Re: Perl and LDAP <jim.gillespie@usa.net>
    Re: Perl Criticism (Matt Knecht)
    Re: Perl Criticism <staffan@ngb.se>
    Re: Perl Criticism <staffan@ngb.se>
    Re: Perl Criticism <staffan@ngb.se>
    Re: Perl Criticism <staffan@ngb.se>
    Re: Regular Expression Question <barmar@bbnplanet.com>
        substituting nth occurrence of character matt_1@my-dejanews.com
    Re: substituting nth occurrence of character (Sean McAfee)
    Re: Using a Form in HTML and a Perl Script. <jtb@bekkers.com.au>
        vim perl and makeprg (John Nielsen)
    Re: Year 2038 problem <cmcurtin@interhack.net>
    Re: Year 2038 problem (Bart Lateur)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 13 Jan 1999 17:41:22 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: a question for perl gurus (I think)
Message-Id: <77ils2$k1f$1@pegasus.csx.cam.ac.uk>

Larry Rosler <lr@hpl.hp.com> wrote:
>[Posted to comp.lang.perl.misc and copy mailed.]
>
>In article <77ct61$r06@linux1.netconx.de> on Mon, 11 Jan 1999 14:11:23 
>+0100, Stefan Berger <s.berger@intershop.de> says...
>> 1. does keys %hash always return the same array (elements in the same order)
>
>Yes, but why should you care?

Strictly, "Yes until the set of keys changes".    The order after a key
addition might bear no relation to that before.

You would only care about keys() on its own being the same if you had
a time-inefficient (but perhaps space efficient) program.
But this is a special case of keys(), values() and each() using a
consistent order, and that is essential for common paradigms such as

    @hash2{keys %hash1} = values %hash1;


Mike Guy


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

Date: Wed, 13 Jan 1999 17:19:37 GMT
From: niemeyer@my-dejanews.com
Subject: Re: associative arrays (hashes)
Message-Id: <77ikiu$104$1@nnrp1.dejanews.com>

Hi!


> I want to use an associative array with IP addresses as index.
>
> $ip1="123.456.123.456";
> $ip2="123.123.123.123";
>
> %no=();
> $no[$ip1]=1;
> $no[$ip2]++;

This can't be done. Associative arrays use {} and
not [].

> print $no[$ip1];
> But it results in "2", cause perl only takes the first number
> of the IP address as index. How can I change that ?

Use {}!

Bye!

Gustavo Niemeyer
Niemeyer Network
Solutions in high tecnology
http://www.niemeyer.net


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 13 Jan 1999 17:21:43 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: BUG: getpwnam()? - Perl shipped with RedHat5.2
Message-Id: <77ikn7$j0h$1@pegasus.csx.cam.ac.uk>

Eugene Sotirescu  <eugene@snailgem.org> wrote:
>Hmmm. . .
>Here's my version:
>
>Characteristics of this binary (from libperl):
>  Locally applied patches:
>        MAINT_TRIAL_4 - 5.004_05 maintenance trial 4
               ^^^^^                          ^^^^^    not a public release!

That is the bad version which you should avoid using.    The most
important bug seems to be that it says "Substitution loop" in certain
circumstances.

>So I don't think it's Perl.

Other responses in this thread suggest that isn't the problem in this case.
But that version is still worth avoiding.


Mike Guy


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

Date: Wed, 13 Jan 1999 10:50:37 -0500
From: Ultima2K <Ultima2K@NOSPAMaol.com>
Subject: Re: CONCLUSIVE PROOF: Jesus *is* King of the Jews  !   !   !
Message-Id: <369CC0CA.8E28CC09@NOSPAMaol.com>

Please if you MUST reply to this topic.  Please do not cross post.  Just post
within your own newsgroup.  This has nothing to do with amateur astronomy.

My apologies for cross-post.
Tom

kd4zkw@amsat.org wrote:

> In rec.motorcycles.harley JAY JAY <jackiej@acay.com.au> wrote:
> : You can say anything you like about ELVIS  - But JESUS is a whole nuther
> : matter - May you and will you get yours
>
> :>"It sure seems fitting that your entire religion is based on worshiping a
> : dead jew on a stick"
>
> Heh, if you can't poke fun at Jesus, then who can you poke fun at ? Remember,
> he died for YOUR sins, which seems to me, that he wanted 'em pretty bad.
>
> Woe to you for the day you wake up sinless. You're gonna miss this,
> I guarantee it. Making off with all your good sins, that you worked so
> hard for. And the worst part is, everyone else will know it too, just
> by looking at you. Plus, the sucky part is that it can happen almost
> instantaneously. Like almost losing it in some gravel, and you blurt out
> "Jesus!" without even realizing you said it, and the next thing you know,
> your sins are all gone, and you gotta start all over.
>
> --
>            - Ears - 98 XL1200C
>
> Curtis D. Levin     kd4zkw.ampr.org [44.98.2.22]
>     kd4zkw@amsat.org          QRP-l #1488
>       http://dialisdn.net/user/cdlevin/


--
Clear Skies and Transparency to All
Tom

Remove "NOSPAM" from the reply address to reply directly.




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

Date: Thu, 14 Jan 1999 01:00:29 +0800
From: -BEN <lava333@hotmail.com>
Subject: Re: CONCLUSIVE PROOF: The Beatles are bigger than Jesus!
Message-Id: <369CD12D.565@hotmail.com>

JLenn wrote:
>No....MC will rot in HELL for what he did....and John Lennon will be 
>singing in Heaven for all of the good things he did for humanity. If 
>there even are such places (Heaven and Hell).

Which there aren't, so it's all pointless discussion anyway.

If you beileve the bible John would be rotting in hell right now.  He 
didn't worship God & Jesus like a monk so he wouldn't be let in to 
heaven.  Not that it exists, but theoretically speaking.


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

Date: 13 Jan 1999 17:38:17 +0100
From: Jonathan Feinberg <jdf@pobox.com>
To: info@gadnet.com
Subject: Re: Help needed with locking
Message-Id: <m3ww2r3z7p.fsf@joshua.panix.com>

info@gadnet.com writes:

> I'm fairly new to perl and would like some advice on file locking.

See perlfaq5.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: 13 Jan 1999 17:53:07 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How can I compare two arrays?
Message-Id: <77imi3$3uh$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Uri Guttman 
<uri@home.sysarch.com>],
who wrote in article <x7n23ngolv.fsf@home.sysarch.com>:
>   DG> _02 isn't bad (for some value of bad, I've had very few problems), _03
>   DG> should be better.
> 
> that phrase doesn't fill me with confidence.

Since you claim you use 5.004_04, I have no sympathy to you at all.

Even 5.005_54 is way ahead of 5.005_02 wrt bugs (but 5.005_03 should
fix this abnormality).  But you cannot even start to compare 5.005_02
to 5.004_04 - the latter is buggy as hell if you take 5.005_02 as a
reference point.

Ilya


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

Date: Wed, 13 Jan 1999 19:05:13 +0200
From: Tero Toivanen <tttoivan@cc.hut.fi>
Subject: Mysterious "Killed" response - help needed.
Message-Id: <369CD249.2BE8@cc.hut.fi>

Hello!

I have made a script of about 600 lines (splitted
to a couple of files) and thought it was ready and
working properly.

It works just fine if I run it only once. But if
I run it for example 100 times (with a for loop),
it does its work 80-90 times, then collapses and
gives me a mysterious response "Killed". The script
does not collapse in the same place and same
line every time..

Now I need your help to get this script working.

What causes this "Killed" message? I fear it has something
to do with the memory. I have a feeling it cannot be "out
of memory" because I have declared all the possible variables
locally.. Could it be some kind of "Stack Overflow" or
"Segmentation fault"? I have tried to search information about
this "Killed" message, but there does not seem to be too much
documentation of it.

Thanks for your time and spare in advance,

Tero


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

Date: Wed, 13 Jan 1999 17:26:21 GMT
From: rlopes@securitydynamics.com
Subject: need help with net::telnet...
Message-Id: <77ikvg$1fd$1@nnrp1.dejanews.com>

I am trying to interact with a telnet session.	The session is fairly simple
(I think).

  1) login as a user with password  2) then execute a program: example2  3)
this program then prompts for "enter login:" followed by "Enter PASSCODE:" 
4) then the program returns a string re. the success or failure.

But I can't get anything to work correctly.  Anybody have any ideas?

Thanks,
Bob

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 13 Jan 1999 16:24:22 GMT
From: cpierce1@mail.ford.com (Clinton Pierce)
Subject: Re: Newbie Question - Matt's wwwboard
Message-Id: <36a4c594.3194517462@news.ford.com>

On 10 Jan 1999 12:56:28 -0500, Uri Guttman <uri@home.sysarch.com> wrote:
>>>>>> "TS" == TRG Software <chatmaster@c-zone.net> writes:
>
>  TS> it yourself, because Matt's scripts are mainly meant for people to "get
>  TS> the job done and going". They leave a lot to be desires in many areas.
>  TS> However, to solve your immediate problem, again, I suggest you take a
>  TS> look through that site, through the FAQ's and help boards, because
>  TS> you're no going to get much help in a NG asking what's what with someone
>  TS> else's script that you're trying to "get to work". :-)
>
>especially with matt's crap. the NG hates his stuff because of all the
>bugs, halfassed designes etc. and for the fact that newbies keep using
>them, complain to this group to fix them and matt never improves them
>(as if he could). help me with matt is an FAQ with no answer!


$message->sheilds(1);

It can be argued that Matt's scripts filled a niche that the CPAN
libraries (at the time) could not:

	1. Easily installed.  
	     CPAN can be grueling under some circumstances.  
             i.e. Win32 without a compiler.
	2. Widespread
	     THATs why the newsgroup keeps hearing about it.
	     His stuff got out and spread around before CPAN
             really had its stuff together.
	3. Perl4/5 comptability.
	     Not so important now, but it was two years ago.
	4. Complete software "packages"
	     Matt sometimes supplied the whole program, instead
	     of just a toolkit.  This makes his things still 
	     attractive to the "Gimme Gimme" crowd.

The fact that they are buggy, and support/fixes for them is nonexistant
notwithstanding they made very nice stopgaps.

It's crap now, but at one time it was the crap most easy to spread
around...



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

Date: 13 Jan 1999 10:16:45 +0000
From: James Gillespie <jim.gillespie@usa.net>
Subject: Re: Perl and LDAP
Message-Id: <bii90f7fpf6.fsf@usa.net>

"Indy" <indy@NOSPAMdemobuilder.com> writes:

> Implementing an LDAP involves encoding and decoding ASN data
> structures and low level bit manipulation.  Writing such a thing in
> Perl is not practical.  It would be equivalent to writing the Perl
> interpreter in Perl - not impossible, but impractical.  For this
> reason I don't think you will find a pure Perl implementation of
> LDAP out there.

    Ahem.  You may want to check out
http://www.connect.net/gbarr/perl-ldap/.

    Thank you Graham.

                Jim
--
Jim.Gillespie@     ,'_                Now set on a course to devastation
   USA.net        / -.--.    ___      city with no U-turns
+44 171 721 2672 _\_x \__`--'_,-' 
                / /\\    \--'_-\\ 
'94 BYO         \__/ `---'  \__/                         -- Robin Maytum


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

Date: Wed, 13 Jan 1999 16:39:44 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: Perl Criticism
Message-Id: <k%3n2.493$il1.4607965@news3.voicenet.com>

topmind@technologist.com <topmind@technologist.com> wrote:
>
>                                The Perl expert inspects the
>code and realize that the system is composed of 30,000 lines
>of code that looks something like this:

It looks as though you've pasted the same comand line script togethre
4 times.  I've removed the duplicates (They produced syntax errors,
anyway), and added some whitespace.  Here's what we get:

#!/usr/local/bin/perl -l

$n=170;

for( $d=2; ($d*$d) <= $n; $d += (1+($d%2)) ) {
    for( $t=0; ($n%$d) == 0; $t++ ) {
	$n = int($n / $d);
    }
    
    while( $t-- > 0 ) {
	push(@r, $d);
    }
}

if ($n > 1) { 
    push(@r, $n);
}

$x = 0;

map
{
    $x +=
        (
	  ($_>0) ?
		   (1<<log($_-0.5)/log(2.0)+1)
		 :
		   1
        )
} @r;

print "$x"

__END__

>Can you spell B.A.N.K.R.U.P.T.C.Y  ?

With a programmer like that?  Sure!  This code doesn't look like Perl
to me.  In fact, what this looks like is C.  If you were to write this
using the features of Perl you so dislike, you would have a much easier
to understand script.

>Of course this is an extreme example

No.  This looks like a contrived example. You pasted together 4
command line scripts, and removed all the whitespace.  Any language
looks terrible when you do that.

>                                      but it happens on this and
>smaller scales all the time.

I don't think this happens all that much. At least none of the
production code I've *ever* seen.  I've approached poor code like the
above when I first started learning Perl, but quickly outgrew that
phase when I saw how much more expressive I could be with Perl
constructs.

>As for languages that are less abusable, consider Pascal, Java, or
>Visual Basic.

You could abuse those languages in the *exact* same manner as you have
done with the above Perl code (Forgetting the fact that none of these
languages will let you write one liners on the command line.).

The only language I would think you couldn't abuse like you've shown
would be Python, since it relies on magic whitespace.

>              One programmer confided in me, "I hate
>programming in Visual Basic, but when I see
>other's VB code, I can usually figure out
>what is going on."

Why did he say usually?  Is there something wrong with the language
that he couldn't make heads nor tails of the code?

All the production Perl code I've *ever* seen I've been able to figure
out in short order.  Why can't your programmer buddy figure out the
VB?

-- 
Matt Knecht <hex@voicenet.com>


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

Date: Wed, 13 Jan 1999 18:26:30 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Perl Criticism
Message-Id: <369CD746.F8A32B02@ngb.se>

Sam Holden wrote:

> Damn I posted to this thread... I blaim abigail... that post caused
> the thread to move up a bit (since I am one of the few that enjoys
> abigail's posts) so I actually read a little of it...

Hey, that makes two of us. There's nothing like observing a clean kill
from a safe distance... 

Staffan


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

Date: Wed, 13 Jan 1999 17:55:54 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Perl Criticism
Message-Id: <369CD01A.4751B699@ngb.se>

Topmind:

> It is my opinion that most of the academic types who write
> those papers do very little typical, real world work.
> (I used to dig around in image-processing research papers
> and saw a lot of side topics.)

I have refrained to comment much in this thread, but this is funny. You
have been bitching for a long time about the responses just expressing
personal opinions and not scientifically proven facts, as would be the
case with a survey observing many people and how they use the language,
and what they do appreciate and what they don't. 

One could argue that such a study would be proof of anything. But that's
not the point right now. Right now the point is -- so now the academic
types (who must be the same people conducting the studies) don't do a
good job - the scientific studies are not a supply of well reasoned
objective facts. 

On the other hand, the opinions of the people who work everyday with
perl isn't a good judgment of the strengths of the language either, so
the only good judgment of perl is you, who are neither academic nor
familiar with perl. I don't really get it. But that might be because I'm
an academic who's (modestly) familiar with perl...

Staffan


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

Date: Wed, 13 Jan 1999 18:22:00 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Perl Criticism
Message-Id: <369CD638.5E024853@ngb.se>

topmind@technologist.com wrote:

> This thread aint no objective review. It would be like
> an athiest walking into a synagog and asking for
> approval.

No, you're very correct. But since you dislike the academics who know
how to make objective reviews because they use a language you don't
understand (because they have a more detailed understanding of
'objective' and 'review'), you cannot really expect a review that you'd
like.

> It is funny how the OOP croud ridiculed me for factoring in
> the amount of typing needed in a language, and the Perl croud
> ridiculed me for not ranking it high enough.

And this is an interesting point. We all use the language we prefer. But
using both object oriented languages and perl (but hey, perl has (some)
object orientation, doesn't it), I can see many similarities. The
problems of writing good programs are similar in both cases. Hiding of
variables is considered a good idea, and in OOP it's done through using
hidden or protected instance variables, and in perl it's done by using
my() as often as possible. 

When programming in perl, I often use hashes (associative arrays) to
represent the objects in OOP, because some things lend themselves well
to this way of thinking, and then I construct sub's operating on these.
This is more verbose than the minimal construct, but it represent the
way I think about the problem, and perl lets me do this.

In OOP I make classes and create objects that belong to them.

When using OOP, I often find that a particular problem doesn't lend
itself well to the Object Oriented approach: For instance if a large
number of things has to be done consecutively, like backing up a
database system. In this case, I use a linear (structured) approach, and
most OOP languages let me do this without any problems. When doing this,
I usually only use variables (instances) from the object I'm in at the
moment, so I don't have to use the annoing and long names for variables
and methods, instead I can use self to do what I want, thus making this
part of the program less verbose than OOP usually is. 

In perl this is the standard thing to do. 

I don't think differently when using different languages, I just adapt
the output to the language at hand. Sometimes I also adapt the language
by adding functions that I use in some other language, and would like to
have...

Although, I must say that moving from CA-Visual Objects to perl, for
some reason, feels like a great relief (the same goes for clipper or
java). My personal preference is perl. Don't ask me why. It simply works
very well for the tasks I usually perform.

> What one is chewed out for depends on where they go.
> I used to take it personally until I saw all the
> contradictions in the yellers.

If you post something slightly aggressive you should never take things
seriously. Also remember that the people in this group speak out of
their personal opinions and experiences, and you cannot hold
contradictions between different posters as a proof that you're correct.
It only shows that there are different opinions.

I would also like to say that, somewhat surprisingly, something very
interesting has come out of this thread. I've had so much fun reading it
that I haven't visited www.dilbert.com in weeks. At the same time, I've
learnt a lot -- not only about perl, but about great many things...

Staffan


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

Date: Wed, 13 Jan 1999 18:53:15 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Perl Criticism
Message-Id: <369CDD8B.C84E155C@ngb.se>

topmind@technologist.com wrote:

> "There is a saying in the Unix community that one should not prevent
> idiots from abusing something because it may prevent someone else from
> making good use of it. [...]

Once I had finished a project in perl, creating 10 or so modules, and
afterwards, I wanted to remove the *~ autosaves that emacs makes, so I
typed 'rm *' at the command line, and removed everything. Thousand of
lines of good, working code. Fortunately, at the time, I backuped
everything every now and then, and I had a backup that was a couple of
days old, so I recreated the few days of work in three hours. 

This has nothing to do with perl. This has to do with any operating
system. I could do the same in Windows. Only I don't have to. If I try
to save a document in word at the same time as it's being autobackuped,
Word crashes, and I'm left with neither of the copies. I've never been
able to do that in Unix/Emacs. 

Besides, I have no clue where any of my windows programs save the
backups, and I think at only three or four times out of a couple of
hundred, the autobackups have contained anything interesting. 

This is about windows, that should be user friendly and safe. In Unix, a
smart SysMan aliases 'rm' and issues warnings about removing multiple
files. This is easy. The dangerous part is trusting the system to do
things for you. If you want your information to be safe, backup it
yourself. If you want your code to be safe, make sure the program
doesn't have the rights to do something stupid. And learn the
programming language. 

> YEOOOOOOOOOWWWWW!

Sigs should be compared with copying famous heavy metal guitarists solos
- they show you're fast, but they don't say anything about how many
notes you play during a normal performance.

Staffan


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

Date: Wed, 13 Jan 1999 17:00:00 GMT
From: Barry Margolin <barmar@bbnplanet.com>
Subject: Re: Regular Expression Question
Message-Id: <ki4n2.127$oD6.9945@burlma1-snr1.gtei.net>

In article <77hbp8$u10$1@nnrp1.dejanews.com>,
 <parab0la@my-dejanews.com> wrote:
>I'm try to match the pattern /helloworld/ or /byeworld/.  Is there any way
>that I can combine them in one regexp, something like /\(hello|bye\)world/ ?

Depending on the extended regular expression processor you're using, it
would be either /\(hello\|bye\)world/ or /(hello|bye)world/.  Either it
requires botht he parentheses and vertical bar to be escaped, or it doesn't
require either of them to be escaped.  Emacs and egrep use the first form,
Perl and awk the second.

-- 
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.


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

Date: Wed, 13 Jan 1999 16:53:36 GMT
From: matt_1@my-dejanews.com
Subject: substituting nth occurrence of character
Message-Id: <77ij2a$vfn$1@nnrp1.dejanews.com>

I need some help with a regex substitution. I am trying to substitute/replace
the fifth of occurrence of a : in a file similar to this:

text 10/10/10 12:12:12 text text 12:12:12 text:text text

Here is what I have tried so far:

$file = "$ARGV[0]";
open(FILE,$file) || die "Can't open $file: $?";
while($lines = <FILE>) {
        $color = ( $lines =~ /\b[:]\b/gi )[-4];
        print "$color\n";
}
close(FILE);

This seems to match the fifth occurrence of the specified character, but how
would i go about replacing/substituting it?

I tried the following but it didn't work.

while($lines = <FILE>) {
        $lines =~ s{/\b[:]\b/}{
                                        if (++$count == 4) {
                                                "^" . $2;
                                        } else {
                                                $1 . $2;
                                }
                        }gex;
        print "$lines\n";
}

Thanks for any help!

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 13 Jan 1999 17:30:12 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: substituting nth occurrence of character
Message-Id: <EK4n2.1968$Ge3.9272601@news.itd.umich.edu>

In article <77ij2a$vfn$1@nnrp1.dejanews.com>,  <matt_1@my-dejanews.com> wrote:
>I need some help with a regex substitution. I am trying to substitute/replace
>the fifth of occurrence of a : in a file similar to this:

>text 10/10/10 12:12:12 text text 12:12:12 text:text text

>Here is what I have tried so far:
[snip]
>This seems to match the fifth occurrence of the specified character, but how
>would i go about replacing/substituting it?

>I tried the following but it didn't work.

>while($lines = <FILE>) {
>        $lines =~ s{/\b[:]\b/}{
>                                        if (++$count == 4) {
>                                                "^" . $2;
>                                        } else {
>                                                $1 . $2;
>                                }
>                        }gex;
>        print "$lines\n";
>}

You're referring to $1 and $2, but there weren't any capturing parentheses
in the regex part of the substitution operator.  Also, you may as well say
":" instead of "[:]", since matching a character class with only one
character is equivalent to simply matching the character itself.

Try this instead:

my $count = 0;
$lines =~ s/\b:\b/++$count - 5 ? ":" : "^"/ge;

I also tried out another approach, thus:

my ($i, $n) = (0, -1);
while (($n = index($lines, ":", $n+1)) >= 0) {
	substr($lines, $n, 1) = "^", last if ++$i == 5
}

 ...but benchmarks showed wild variations in the relative performances of
the algorithms depending on how many colons are present in $lines and how
spaced apart they were.  If speed isn't a big concern, you may as well
stick with the shorter code.

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Thu, 14 Jan 1999 00:44:41 +0800
From: "Jamie Bekkers" <jtb@bekkers.com.au>
Subject: Re: Using a Form in HTML and a Perl Script.
Message-Id: <77ij9i$ll2$1@news.bekkers.com.au>

Thanks Ted,

That is not my problem, I wanted someone to help me create a html form to
pass variables to the script.

Thanks
Jamie.

Tad McClellan <tadmc@metronet.com> wrote in message
news:09ff77.oee.ln@magna.metronet.com...
>Jamie Bekkers (jtb@bekkers.com.au) wrote:
>
>: I can get this to run from the console, but I can not work out the code
to
>: put this in a web page.
>
>
>   Perl FAQ, part 9:
>
>      "My CGI script runs from the command line but not the browser.
>       (500 Server Error)"
>
>
>--
>    Tad McClellan                          SGML Consulting
>    tadmc@metronet.com                     Perl programming
>    Fort Worth, Texas




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

Date: 13 Jan 1999 11:52:44 -0500
From: jnielsen@chemistry.mps.ohio-state.edu (John Nielsen)
Subject: vim perl and makeprg
Message-Id: <77ij0s$2cs@chemistry.ohio-state.edu>

I would like to run perl's syntax checker inside vim and reformat the perl
errors so vim 5 can understand them.

I assume I need to use makeprg and errorformat.

Has anyone played with getting this setup?

Thanks,

john

Btw, I am using perl and vim for NT (latest releases) and have cygnus's bash.




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

Date: 13 Jan 1999 12:12:39 -0500
From: Matt Curtin <cmcurtin@interhack.net>
Subject: Re: Year 2038 problem
Message-Id: <xlxd84jxfjs.fsf@gold.cis.ohio-state.edu>

Billy Vitro <bvitro@cisco.com> writes:

> Well, that makes me feel soooo much better.  I just tried the code below
> on my "Y2K Compliant" Solaris 2.6 (Ultra 60).  Here's what I got:

Foo.

$ uname -a
IRIX gonzo 6.5 05190004 IP32

$ perl -v
This is perl, version 5.004_04 built for irix-n32

$ perl -e 'print scalar localtime 2**30, "\n"'
Sat Jan 10 08:37:04 2004

$ perl -e 'print scalar localtime 2**31, "\n"'
Fri Dec 13 15:45:52 1901

$ perl -e 'print scalar localtime 2**55, "\n"'
Wed Dec 31 19:00:00 1969


-- 
Matt Curtin cmcurtin@interhack.net http://www.interhack.net/people/cmcurtin/


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

Date: Wed, 13 Jan 1999 17:04:02 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Year 2038 problem
Message-Id: <36a0d125.33429332@news.skynet.be>

Johannes Poehlmann wrote:

>(When expanding
>0x80 00 00 01 to signed 64 bit, we get 0x 8f ff ff ff 00 00 00 01.
>When going unsigned, we fill up with zeroes.

No we don't. We'd get 0x ff ff ff ff 80 00 00 01. ;-)

	Bart.


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4642
**************************************

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