[16469] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3881 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 2 06:15:36 2000

Date: Wed, 2 Aug 2000 03:15:25 -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: <965211324-v9-i3881@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 2 Aug 2000     Volume: 9 Number: 3881

Today's topics:
    Re: Remove a blank line <elephant@squirrelgroup.com>
    Re: Remove a blank line <rashid1218@hotmail.com>
    Re: Remove a blank line <rashid1218@hotmail.com>
    Re: Remove a blank line (Bernard El-Hagin)
        Remove comments <rashid1218@hotmail.com>
    Re: Removing all HTML tags from a String <webmaster@mendonet.com>
    Re: Removing newline chars <lr@hpl.hp.com>
    Re: Reserved word (Marcel Grunauer)
    Re: Same data accesed twice? (cleaned up code) <debjit@oyeindia.com>
    Re: Syntax Question <lr@hpl.hp.com>
    Re: Syntax Question <bart.lateur@skynet.be>
    Re: Syntax Question <bart.lateur@skynet.be>
    Re: Syntax Question (Anno Siegel)
    Re: system($commandline) fails <elephant@squirrelgroup.com>
        U.S.P.S.  API:  Exporter vs. XML module?  Comments? <webmaster@mendonet.com>
    Re: Variable Interpolation Woes <elephant@squirrelgroup.com>
        Whats wrong with this???? <psychoNOpsSPAM@pcpatches.com.invalid>
    Re: why open("fifo") hangs? <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 02 Aug 2000 07:39:36 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Remove a blank line
Message-Id: <MPG.13f26d938b0f90509896a4@news>

  [ posted to comp.lang.perl.misc and CCed to rashid1218@hotmail.com ]

Rashid Saharudin writes ..
> I would like to remove blank lines/ unwanted sentence from my
>textfile. The file look something like this:
>
>This is my  first perl
>
>script. Just testing...It does
>
>not work. 'command lines using
>
>visual basic.' I will try it
>
>later.
>
>And I want it to look like this after removing the blank lines and
>unwanted sentence.
>
>This is my  first perl
>script. Just testing...It does
>not work. I will try it
>later.
>
>Could anyone help me, please.

you've already been helped in a thread started by you a day or two ago 
with the same subject .. go and read that thread

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Wed, 02 Aug 2000 08:14:12 GMT
From: Rashid Saharudin <rashid1218@hotmail.com>
Subject: Re: Remove a blank line
Message-Id: <8m8l8h$bna$1@nnrp1.deja.com>

I've tried to insert the code as you told me, but it still could not
work.

This is my code.
$text="c:/scripts/text.txt";
open TEXT, $text or die "Cannot open $text for read :$!";

while (<TEXT>) {
 $line =~ s/\'.*//;
	next if /^\s*$/;
 chomp;
 print;
}

And the script is :

This is my first

perl script. Just

testing!!! It does

not work??? 'command

lines using visual basic '


And I want it to look like this:

This is my first
perl script. Just
testing!!! It does
not work???

Could you help me please.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 02 Aug 2000 08:24:03 GMT
From: Rashid Saharudin <rashid1218@hotmail.com>
Subject: Re: Remove a blank line
Message-Id: <8m8lr0$c3s$1@nnrp1.deja.com>

This is how I tried:

$text="c:/scripts/text.txt";
open TEXT, $text or die "Cannot open $text for read :$!";

while (<TEXT>) {
 $text =~ s/\'.*//;
 next if s/\r\n//g;

	next if /^\s*$/;
 chomp;
 print;
}

*** And this is my text file:

This is my first

perl script. Just

testing!!! It does

not work??? 'command

lines using visual basic '

**&& And I want it to look like this:

This is my first
perl script. Just
testing!!! It does
not work???

&&& Also I would like when I open the text file afterwards, it looks
exactly as above after the removal of blank lines and comments.

Could anyone help me please.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 02 Aug 2000 09:57:13 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Remove a blank line
Message-Id: <slrn8ofrqq.61h.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 02 Aug 2000 08:14:12 GMT, Rashid Saharudin
<rashid1218@hotmail.com> wrote:
>I've tried to insert the code as you told me, but it still could not
>work.
>
>This is my code.
>$text="c:/scripts/text.txt";
>open TEXT, $text or die "Cannot open $text for read :$!";
>
>while (<TEXT>) {
> $line =~ s/\'.*//;
>	next if /^\s*$/;
> chomp;
> print;
>}
>
>And the script is :
>
>This is my first
>
>perl script. Just
>
>testing!!! It does
>
>not work??? 'command
>
>lines using visual basic '
>
>
>And I want it to look like this:
>
>This is my first
>perl script. Just
>testing!!! It does
>not work???
>
>Could you help me please.

Even though the solution I quote below works, it seems an ugly way of
doing this and I'd be very interested to see how this kind of text
manipulation can be done easier since it's a problem that often occurs.

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

my @stuff;
while (<DATA>){
	s/^\s*$//;
	push @stuff, $_;
}

{
	$_ = join '', @stuff;
	s/'[^']*'//g;
	print;
}

__DATA__
This is my first

perl script. Just

testing!!! It does

not work??? 'command

lines using visual basic '
__________________

Bernard
--
perl -le 'open(JustAnotherPerlHacker,"")or$_="B$!e$!r$!n$!a$!r$!d$!";
print split/No such file or directory/;'


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

Date: Wed, 02 Aug 2000 07:48:48 GMT
From: Rashid Saharudin <rashid1218@hotmail.com>
Subject: Remove comments
Message-Id: <8m8jov$al1$1@nnrp1.deja.com>

I would like to remove comments in a asp/ VB script file like this.


'Retrieve Country List

Could anyone give me the right coding for me please.

--
RASHID SAHARUDIN


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 01 Aug 2000 23:26:25 -0700
From: Jon Hollcraft <webmaster@mendonet.com>
To: aaron@preation.com
Subject: Re: Removing all HTML tags from a String
Message-Id: <3987BF11.A48@mendonet.com>

aaron@preation.com wrote:
> 
> I am attempting to remove every HTML tag from a large string which is
> made up of all the lines of an HTML page. My goal is to create plain
> text which I can put into a sort of search engine page as a
> representation of the content of that page for a PERL site search
> engine.
> 
> I have been trying to use Regex code to deal with this problem by
> something like this:
> 
> $desc =~ s/(<?*>)//g;
> 
> Yet I don't have a good understanding of regex and I understand that the
> code I am using above is not valid. It was my understanding that the ?
> would take any character, and the * would allow for as many of them as
> needed until it finds the > to end the match. But this doesn't work. Can
> anyone advise what I should do, where can I find this code. I tryed the
> PERLFAQ many times but can't find it anywhere.

I found this on the FAQ at www.cpan.org

		s/<(?:[^>'"]*|(['"]).*?\1)*>//gs

Don't know if it works yet ... I gonna try to strip all that XML garbage
that USPS sends back.  eg. xml snippit <Zone>8</Zone>


	$ret[7] =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
	$Zone = $ret[7];
	$ret[8] =~s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
	$Postage = $ret[8];


Hopefully, I'll end up with a zone number and a postage amount when the
packaging is stripped away.  Worth a shot.

Have Fun!

Jon

43% of all statistics are made up on the spot.


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

Date: Tue, 1 Aug 2000 23:51:36 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Removing newline chars
Message-Id: <MPG.13f164cdfc1b8fe198ac23@nntp.hpl.hp.com>

In article <39876FA4.28055EDD@stomp.stomp.tokyo>, 
godzilla@stomp.stomp.tokyo says...

 ...

> Your code, =~ s/[\r\n]+/ /g; would seem best choice
> on taking care of this carriage return / newline thing.
> There is no problem with doubling up spaces using your
> character set as compared to \r|\n type regex. Tested
> your code, works very well indeed. I couldn't break it.
> 
> This is a good learning experience. Thank you.

Excellent.  Here's another good learning experience, assuming an order-
of-magnitude performance improvement matters in the particular 
application:

    tr/\r\n/ /s 

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


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

Date: Wed, 02 Aug 2000 08:42:00 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: Reserved word
Message-Id: <slrn8ofo19.3lc.marcel@gandalf.local>

On Tue, 01 Aug 2000 14:35:02 -0700, chuckw
<chuckwNOchSPAM@silverlink.net.invalid> wrote:

>>>package scrubber;
>>>
>>>sub new {
>>>   my $self;
>>>   bless ($self, scrubber);
>>
>>This is line 6.
>>
>>>Unquoted string "scrubber" may clash with future reserved word
>>>at scrubber.pm line 6.
>
>Well, you got me there. I am completely confused about your
>point. What do you mean by "This is line 6"? After that comes
>the error message that I saw a zillion times. Don't be so
>pedantic as to assume that line number formatting is going to
>match up correctly in a usenet post. Please be more specific.
>What was your point?

Well, let's look again at that line that I believe to be line 6, as
stated in the error message:

    bless ($self, scrubber);

Now, can you see the bareword the error message refers to? 'Unquoted
string "scrubber"...' Can you see the unquoted string "scrubber" in
that line?

It's got nothing to do with your using a lowercase module name; this
isn't what the error message refers to.

-- 
Marcel
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


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

Date: Wed, 2 Aug 2000 10:52:39 +0530
From: "Debjit" <debjit@oyeindia.com>
Subject: Re: Same data accesed twice? (cleaned up code)
Message-Id: <8m9g0u$h6o$1@news.vsnl.net.in>

Did u try printing the sql and try it from sql prompt?





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

Date: Tue, 1 Aug 2000 23:48:32 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Syntax Question
Message-Id: <MPG.13f1641b9992347a98ac22@nntp.hpl.hp.com>

In article <39898532.2366292@news.newsguy.com>, kcivey@cpcug.org says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> 
> >If you 
> >are paranoid about such a failure, you can do this:
> >
> >          my $size = -s FILE;
> >          $size == read FILE, $contents, $size or die ...
> >
> >But note carefully that whatever might cause the read() to return 
> >prematurely would also cause the <FILE> operator to fail prematurely.
> >
> >          my $contents = do { local $/; <FILE> };
> >          $contents == -s FILE or die ...
> 
> I'm surprised you didn't point out that neither comparison will
> work on Windows without binmode().

That is just another reason why those tests are futile.

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


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

Date: Wed, 02 Aug 2000 08:18:14 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Syntax Question
Message-Id: <mulfosonc2q9534ja1c1otpd1l3gmoa1qi@4ax.com>

Larry Rosler wrote:

>          my $size = -s FILE;
>          $size == read FILE, $contents, $size or die ...

Uh-oh. Bad advice with regards to a text file on a PC (the ones with the
CR+LF line endings).

	#!perl -w
	open ME, $0 or die "Cannot open myself: $!";
	$\ = "\n";
	print "Size: ", -s ME;
	$length = read ME, $_, -s ME;
	print "Read: ", $length;
	print "String length: ", length;
-->
	Size: 186
	Read: 178
	String length: 178

The difference between the two is the effect of the "\r"'s gone fishing;
i.e. effectively a line count. What is a bit bizarre is that read()
returns the length of the reduced string, NOT the number of bytes read.
Maybe this is a bug? If you're used to both numbers being the same, it's
hard to appreciate the difference, let alone say which is correct.

-- 
	Bart.


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

Date: Wed, 02 Aug 2000 08:22:35 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Syntax Question
Message-Id: <8dmfosc0jg3d0s0e1bjculugsbnnpcere8@4ax.com>

Greg Bacon wrote:

>: But note carefully that whatever might cause the read() to return 
>: prematurely would also cause the <FILE> operator to fail prematurely.
>
>Can you please cite a reference in the documentation (or even the
>source) that supports your claim?

I think Larry is referring to a discussion we had here a while ago,
namely that a signal coming in, probably ANY signal, would interrupt the
read.

Unless care has been taken to loop internally, in case of line-by-line
reading, it seems like a fair assumption that this would affect <FILE>
style reading as well.

-- 
	Bart.


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

Date: 2 Aug 2000 09:51:08 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Syntax Question
Message-Id: <8m8quc$i1p$1@lublin.zrz.tu-berlin.de>

Bart Lateur  <bart.lateur@skynet.be> wrote in comp.lang.perl.misc:
>Larry Rosler wrote:
>
>>          my $size = -s FILE;
>>          $size == read FILE, $contents, $size or die ...
>
>Uh-oh. Bad advice with regards to a text file on a PC (the ones with the
>CR+LF line endings).
>
>	#!perl -w
>	open ME, $0 or die "Cannot open myself: $!";
>	$\ = "\n";
>	print "Size: ", -s ME;
>	$length = read ME, $_, -s ME;
>	print "Read: ", $length;
>	print "String length: ", length;
>-->
>	Size: 186
>	Read: 178
>	String length: 178
>
>The difference between the two is the effect of the "\r"'s gone fishing;
>i.e. effectively a line count. What is a bit bizarre is that read()
>returns the length of the reduced string, NOT the number of bytes read.
>Maybe this is a bug? If you're used to both numbers being the same, it's
>hard to appreciate the difference, let alone say which is correct.

There's "correct", and there's "useful".

At first glance, the more useful behavior appears to be for read() to
return the number of bytes consumed from the file, not the length of
the string returned, because you have the latter anyway. (Even with
four-argument read you do, indirectly.)

Then again, for correctness, the count returned ought to agree with the
length parameter given to read().  So how does read() behave in cases
where there's a difference?  In other words, if a file begins with
"a\r\nb", what does read( FILE, $buf, 2) read?  What should it read?
If we count bytes in the file, we must face a situation where certain
numbers of bytes *cannot* be read from a file (and the semantics of
end-of-line adjustment remain valid).

Looking at it this way, it's understandable for a programmer to
go out of harms way and decide to count what comes out of read(),
not what goes into it.

Anno


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

Date: Wed, 02 Aug 2000 07:27:36 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: system($commandline) fails
Message-Id: <MPG.13f26ac3546e2a939896a3@news>

DeeJay writes ..
>I try to execute a mapisend.exe from pearl. I redirect the output to a
>html-file and get the following response:
>---------------------------------------------------
>$commandline = c:\mailsend\mapisend.exe -u Mail -p xxxxxx -r
>"Administrator" -s "Testing 123" -m "This is a testmessage."
>
>ERROR: MAPI Logon Failed: 3
>
>Mapisend has been executed.
>---------------------------------------------------
>When I cut & paste the same line from the DOS-promt, no problem.
>
>It looks like the system($commandline) has a problem with the -u and -p
>options, 'though DOS hasn't.
>Background Info: I'm trying to send a HTML-form on Intranet through mail
>from IIS4 to Exchange 5.5, without using SMTP. The Intranet-server has an
>Exchange 5.0 client (MAPI). I've seen this script working with BLAT, made by
>Greg Elin and try to adapt it to MAPISEND.
>
>Does anyone has a clue what the problem is? If not, is there an alternative
>to send HTML-forms to Exchange Server without SMTP?

blah .. actual code .. blah

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 01 Aug 2000 23:53:32 -0700
From: Jon Hollcraft <webmaster@mendonet.com>
Subject: U.S.P.S.  API:  Exporter vs. XML module?  Comments?
Message-Id: <3987C56C.2EA3@mendonet.com>

Well, here we go again.  Gained a little confidence by getting the UPS
servers to properly service my stores, and I thought, USPS outta be a
slam-dunk.  Not so.  Anyone else hacked this XML thing. 

Nothing on CPAN for USPS yet.  Yes, I do have the PDF.  Just thought I'd
ask if someone is using Exporter, like I use for the UPS servers,
instead of yet another module (XML) to load up.

The quote requests are Not generated by a web page directly, but by my
cgi (Perl!) burried behind it.
Its's late ... works at http://www.mendonet.com/steppers/gdiorder.htm

This is on a unix box, of course.  I invite your comments and/or
solutions.

Thanks

Jon


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

Date: Wed, 02 Aug 2000 07:15:39 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Variable Interpolation Woes
Message-Id: <MPG.13f267fb4765a3859896a0@news>

abliss@mindspring.com writes ..
>I'm sure this question has been asked before, but I can't seem to 
>find the answer in any of the FAQs or DOCs.

I put a document together a while ago after some discussions on this 
topic in this group .. perhaps you would benefit from it

  http://www.squirrelgroup.com/perl/interpolation.html

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 01 Aug 2000 21:42:37 -0700
From: psycho <psychoNOpsSPAM@pcpatches.com.invalid>
Subject: Whats wrong with this????
Message-Id: <0c1afb50.fdeb1818@usw-ex0101-007.remarq.com>

im haveing a problem with this trying to print to a file, can
anyone help?

Code Below:

#!/usr/bin/perl -w

$zonedir = "Base dir/cgi-bin/cgimania/banner/";

print "content-type: text/html\n\n";
$lookfor = "6343914";

@put = ();

open(FILE,"$zonedir/test.txt");
@stuff = <FILE>;
close(FILE);

foreach $i (@stuff) {
chomp($i);
($crap, $found) = split(/\|/,$i);
if($crap eq "$lookfor"){
push(@put, $i);
}
}

$get = $put[0];
($crap, $found) = split(/\|/,$get);

open(INF,"+<$zonedir/test.txt");
flock(INF,2);
seek(INF,0,0);
foreach $i (@stuff) {
chomp($i);
if ($i eq $get) {
$found = $found + 1;
print INF "$crap|$found|\n";
print "Found !";
}
}
close(INF);


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

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com



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

Date: 2 Aug 2000 09:16:20 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: why open("fifo") hangs?
Message-Id: <8m8lck$vhp$1@orpheus.gellyfish.com>

On Tue, 01 Aug 2000 17:17:20 GMT Sergey Lukashevich wrote:
> perl 5.6.0 undef RedHat Linux 6.2
> 
> I am qurious why opening a named pipe makes my perl HANG?
> 

I explained this in an earlier thread entitled :

         How to open a FIFO created with C in perl?

which you should be able to find via Deja News.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

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


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