[15490] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2900 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 28 21:10:20 2000

Date: Fri, 28 Apr 2000 18:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <956970614-v9-i2900@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 28 Apr 2000     Volume: 9 Number: 2900

Today's topics:
    Re: Replacing multiple occurences of newline chars with <uri@sysarch.com>
    Re: Replacing multiple occurences of newline chars with <lr@hpl.hp.com>
    Re: Replacing multiple occurences of newline chars with <lr@hpl.hp.com>
    Re: Replacing multiple occurences of newline chars with (Craig Berry)
    Re: Replacing multiple occurences of newline chars with <uri@sysarch.com>
    Re: Something isn't working, and I can't figure it out <makarand_kulkarni@My-Deja.com>
    Re: Telnet scripting in Perl? <mike@hulenbend.net>
    Re: Which book? msouth@fulcrum.org
    Re: why is thi not working? <flavell@mail.cern.ch>
    Re: why is thi not working? <mrsparkle@gamerzuniverse.com>
    Re: why is thi not working? <andrew.mcguire@walgreens.com>
    Re: why is thi not working? <mrsparkle@gamerzuniverse.com>
    Re: why is thi not working? <lauren_smith13@hotmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 28 Apr 2000 22:22:14 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Replacing multiple occurences of newline chars with a single newline char
Message-Id: <x7itx127e2.fsf@home.sysarch.com>

>>>>> "g" == glchy  <glchyNOglSPAM@cc21.com.sg.invalid> writes:

  g> I have a string which might contain multiple occurences of
  g> newlines ("\n") at different places and i want to replace all
  g> those newline occurences with only 1 single newline char. Hence
  g> $text should become $text_final:

look for the tr op in perlop and the /s modifier. does exactly what you
want.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 28 Apr 2000 15:26:19 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Replacing multiple occurences of newline chars with a single newline char
Message-Id: <MPG.1373afe4e887b81898a9b0@nntp.hpl.hp.com>

In article <08a723cc.8fa44cfb@usw-ex0101-007.remarq.com> on Fri, 28 Apr 
2000 14:56:42 -0700, glchy <glchyNOglSPAM@cc21.com.sg.invalid> says...
> i would like to make use of the power of Regular Expression
> matching/parsing in Perl.

ITYM the 'awesome' power ...  :-)

> I have a string which might contain multiple occurences of
> newlines ("\n") at different places and i want to replace all
> those newline occurences with only 1 single newline char. Hence
> $text should become $text_final:
> 
> $text = "a b   c d \n \n \n fgh \n i j kl \n \n";
> $text_final => "a b   c d \n fgh \n i j kl \n";
> 
> Ive implement a loop-counter mechanism whereby i count the no.
> of "\n"s and if $count > 1, then just substitute with 1
> single "\n" char. However, i would like to use the Reg Expr
> feature.
> 
> Any advice? Thanks!

The problem is slightly underspecified.  The following replaces a 
sequence of any number of spaces followed by a newline, repeated twice 
or more, with a single space and a newline, as in your example.  Flavor 
to taste.


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

my $text = "a b   c d \n \n \n fgh \n i j kl \n \n";
my $text_final = "a b   c d \n fgh \n i j kl \n";

$text =~ s/(?: *\n){2,}/ \n/g;

print $text unless $text eq $text_final;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Apr 2000 15:43:07 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Replacing multiple occurences of newline chars with a single newline char
Message-Id: <MPG.1373b3da4c2b013398a9b2@nntp.hpl.hp.com>

In article <x7itx127e2.fsf@home.sysarch.com> on Fri, 28 Apr 2000 
22:22:14 GMT, Uri Guttman <uri@sysarch.com> says...
> >>>>> "g" == glchy  <glchyNOglSPAM@cc21.com.sg.invalid> writes:
> 
>   g> I have a string which might contain multiple occurences of
>   g> newlines ("\n") at different places and i want to replace all
>   g> those newline occurences with only 1 single newline char. Hence
>   g> $text should become $text_final:
> 
> look for the tr op in perlop and the /s modifier. does exactly what you
> want.

In the sample input and output, each "\n" was preceded by a space.  I 
chose to deal with that using a regex substitution.  If the spaces were 
conceptual, not real, then your tr solution is best.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 29 Apr 2000 00:19:56 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Replacing multiple occurences of newline chars with a single newline char
Message-Id: <sgkalclr7qo16@corp.supernews.com>

glchy (glchyNOglSPAM@cc21.com.sg.invalid) wrote:
: i would like to make use of the power of Regular Expression
: matching/parsing in Perl.

You can do it that way, but sometimes that's not the best tool.

: I have a string which might contain multiple occurences of
: newlines ("\n") at different places and i want to replace all
: those newline occurences with only 1 single newline char. Hence
: $text should become $text_final:
: 
: $text = "a b   c d \n \n \n fgh \n i j kl \n \n";
: $text_final => "a b   c d \n fgh \n i j kl \n";

Are those spaces between the newlines real, or put in for clarity?

If they're real, which seems weird:

  $text =~ s/\n(?:\s*?\n)+/\n/g;

If they're not:

  $text =~ tr/\n//s;

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Sat, 29 Apr 2000 00:37:06 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Replacing multiple occurences of newline chars with a single newline char
Message-Id: <x7aeid215b.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <x7itx127e2.fsf@home.sysarch.com> on Fri, 28 Apr 2000 
  LR> 22:22:14 GMT, Uri Guttman <uri@sysarch.com> says...
  >> >>>>> "g" == glchy  <glchyNOglSPAM@cc21.com.sg.invalid> writes:
  >> 
  g> I have a string which might contain multiple occurences of
  g> newlines ("\n") at different places and i want to replace all
  g> those newline occurences with only 1 single newline char. Hence
  g> $text should become $text_final:
  >> 
  >> look for the tr op in perlop and the /s modifier. does exactly what you
  >> want.

  LR> In the sample input and output, each "\n" was preceded by a space.  I 
  LR> chose to deal with that using a regex substitution.  If the spaces were 
  LR> conceptual, not real, then your tr solution is best.

as you said, the problem wasn't defined well. my take was the spaces wee
for clarity and not real as that would be a wierd set of data. also you
can squeeze multiple spaces and newlines to a single newline as well
as i am sure you know. maybe the OP could respond and clarify?

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 28 Apr 2000 15:33:03 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Something isn't working, and I can't figure it out
Message-Id: <390A119F.9E3B7CAD@My-Deja.com>

> print   start_form(-action=>'/cgi-bin/addpage.cgi', -method=>POST),
>         hidden(-name=>'acct_id', -value=>'$acct'),

here the hidden acct_id value gets set to the string "$acct" and NOT the value of
$acct.




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

Date: Fri, 28 Apr 2000 18:26:46 -0500
From: Michael Hill <mike@hulenbend.net>
Subject: Re: Telnet scripting in Perl?
Message-Id: <390A1E35.E1CE237D@hulenbend.net>

Why don't you just use cron?

Mike

WhilBone wrote:

> A friend of mine have set up a mail router/firewall on Linux. When I asked
> him today about adding a small script to send some telnet commands to the
> mail server to get it to release my mail he said that it could probably be
> done in perl.
>
> Unfortunately neither him or I know enough about perl to decide if this is
> possible or not.
>
> Does anyone know if this is possible or not? Maybe you have done something
> similar and have an example to get us started.
>
> What I need to do exactly is to telnet to a server on port 25 and send a few
> commands in order to get the mail server to start sending all mail destined
> for my domain to my server. I think the protocol is called ESMTP (extended
> smtp) and uses a command called ETRN (extended turn) which allows the server
> to queue up smtp messages waiting for my to dial and ask for them to be
> released.
>
> Regards
>
> Peter



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

Date: 29 Apr 2000 00:53:20 GMT
From: msouth@fulcrum.org
Subject: Re: Which book?
Message-Id: <8edbq0$5h9$2@inxs.ncren.net>

Elaine Ashton <elaine@chaos.wustl.edu> wrote:
> in article x7em7y5a6g.fsf@home.sysarch.com, Uri Guttman at uri@sysarch.com
> quoth:
>> its way. i am going to write to him and see if we can work together. my
>> goal is just to have a very good perl books list on the net with lots of
>> books and info.

> Do! I like his presentation more than yours as its organisation is easier to
> navigate. Perhaps you two can work together and create a canonical booklist.

> e.

No, no, no.  You _obviously_ haven't been paying attention.  Uri, you
were supposed to way "thank you for being hateful" in response to 
Elaine, and then subsequently attack everything she says to anyone.
Then you can argue about cabals and such.  Listening to criticism,
and, even worse, figuring out how to use it to improve things
is doing _nothing_ for thread length and comic value around here.
Racists.

mike (who probably just got into a bunch of killfiles for using
the word "hateful" )

ps :)

-- 
Michael South                   |   http://fulcrum.org
Head Mathophile,                |   101 Canyon Run
fulcrum.org                     |   Cary NC  27513 USA
(msouth@fulcrum.org)            |   (919) 465-9074


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

Date: Fri, 28 Apr 2000 23:46:00 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: why is thi not working?
Message-Id: <Pine.GHP.4.21.0004282340070.14495-100000@hpplus01.cern.ch>

On Fri, 28 Apr 2000, Brian Smith wrote:

> ok, it worked on my real server that's being hosted by a host..

You didn't have a Perl problem anyway.  And your posting style still
makes people want to look the other way.

> but when i
> try to use that on MY linux box it still is not working.. i think i'm just
> not setting up the server right or something..

By Jove, I think he's got it.

You don't have a Perl language problem, you likely have a web server
problem. 

Which certainly doesn't call for re-posting the previous several
discussions on this thread, about which you evidently had nothing
productive to say.  I went for many years without a killfile.  No
longer feasible.

-- 

Partake of the distilled wisdom of Usenet by reading its FAQs.
Before you ask.




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

Date: Fri, 28 Apr 2000 18:27:29 -0400
From: "Brian Smith" <mrsparkle@gamerzuniverse.com>
Subject: Re: why is thi not working?
Message-Id: <sgk43l6k7qo89@corp.supernews.com>

what?
Alan J. Flavell <flavell@mail.cern.ch> wrote in message
news:Pine.GHP.4.21.0004282340070.14495-100000@hpplus01.cern.ch...
> On Fri, 28 Apr 2000, Brian Smith wrote:
>
> > ok, it worked on my real server that's being hosted by a host..
>
> You didn't have a Perl problem anyway.  And your posting style still
> makes people want to look the other way.
>
> > but when i
> > try to use that on MY linux box it still is not working.. i think i'm
just
> > not setting up the server right or something..
>
> By Jove, I think he's got it.
>
> You don't have a Perl language problem, you likely have a web server
> problem.
>
> Which certainly doesn't call for re-posting the previous several
> discussions on this thread, about which you evidently had nothing
> productive to say.  I went for many years without a killfile.  No
> longer feasible.
>
> --
>
> Partake of the distilled wisdom of Usenet by reading its FAQs.
> Before you ask.
>
>




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

Date: Fri, 28 Apr 2000 18:05:04 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: why is thi not working?
Message-Id: <390A1920.44A659FE@walgreens.com>

Brian Smith wrote:
> 
> what?

[ another successful jeopardectomy ]

He means that there are certain guidelines to posting
to Usenet.  Here are a few that will help you.

1.  Read the content of news.announce.newusers.
2.  Read RFC 1855.
3.  Make sure you post the correct material to the correct
    group.
4.  Do not post jeopardy style, this means you should reply
    __after__ what you are replying to.  This follows the
    natural course of human conversation.
5.  Do not quote more than you need to ( i.e. entire message ).

You should also "haunt" or "lurk" in a newsgroup for a while
before posting.  By killfile Alan meant that he would ignore
any further posts by you.

I am sure you mean well and only want your problem resolved,
but there is a right way and a wrong way.  Follow those steps
that I have outlined above and your Usenet experience will
be much more enjoyable. :-)

Best of Luck,

anm
-- 
Andrew N. McGuire
andrew.mcguire@walgreens.com


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

Date: Fri, 28 Apr 2000 19:23:26 -0400
From: "Brian Smith" <mrsparkle@gamerzuniverse.com>
Subject: Re: why is thi not working?
Message-Id: <sgk7dute7qo61@corp.supernews.com>

The thing is, the second message I posted was not ment to be a quetion. But
a statment.
Andrew N. McGuire <andrew.mcguire@walgreens.com> wrote in message
news:390A1920.44A659FE@walgreens.com...
> Brian Smith wrote:
> >
> > what?
>
> [ another successful jeopardectomy ]
>
> He means that there are certain guidelines to posting
> to Usenet.  Here are a few that will help you.
>
> 1.  Read the content of news.announce.newusers.
> 2.  Read RFC 1855.
> 3.  Make sure you post the correct material to the correct
>     group.
> 4.  Do not post jeopardy style, this means you should reply
>     __after__ what you are replying to.  This follows the
>     natural course of human conversation.
> 5.  Do not quote more than you need to ( i.e. entire message ).
>
> You should also "haunt" or "lurk" in a newsgroup for a while
> before posting.  By killfile Alan meant that he would ignore
> any further posts by you.
>
> I am sure you mean well and only want your problem resolved,
> but there is a right way and a wrong way.  Follow those steps
> that I have outlined above and your Usenet experience will
> be much more enjoyable. :-)
>
> Best of Luck,
>
> anm
> --
> Andrew N. McGuire
> andrew.mcguire@walgreens.com




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

Date: Fri, 28 Apr 2000 16:21:16 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: why is thi not working?
Message-Id: <8ed6cn$qje$1@brokaw.wa.com>


Brian Smith <mrsparkle@gamerzuniverse.com> wrote in Jeopardy style
> what?

:-D

That was funny...

Anyway, what Alan was saying was that you are breaking several community
rules here.

1) Jeopardy quoting.  This is where you write your answer at the top of the
message and just leave the previous message in a solid chunk after it.  This
makes everyone guess what it is exactly that you are responding to.  Check
out www.deja.com and do a search for 'Quoting Strategies and the Jeopardy
Game', it will have much more information about this topic.

2) Repeated posting about a server issue.  This is the Perl newsgroup and
Perl is discussed here.  There are other groups that discuss servers, their
names usually have 'servers' somewhere in them.
comp.infosystems.www.servers is one of them.  CLPM gets a server question
about once every 2 hours or so and in each case the poster is told where to
go.  Most leave quietly, a few take their agression out on the peaceful
denizens of CLPM, and others continue posting off-topicly here.  You are the
third kind.  Now that you know about other groups, you have a larger pool of
resources to get correct information from.

Read the messages in news.announce.newusers

Go, and post badly no more.

Lauren




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 2900
**************************************


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