[17758] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5178 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 22 06:05:31 2000

Date: Fri, 22 Dec 2000 03:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977483110-v9-i5178@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 22 Dec 2000     Volume: 9 Number: 5178

Today's topics:
    Re: assign to array of references <johnlin@chttl.com.tw>
    Re: automatic FAQ answerer idea <nospam.newton@gmx.li>
    Re: automatic FAQ answerer idea (Abigail)
    Re: bug in open() <joe+usenet@sunstarsys.com>
    Re: h4x0r vNought <ubl@schaffhausen.de>
        Help with SSI Parser for html pages. <Jodyman@usa.net>
    Re: heredoc within heredoc <johnlin@chttl.com.tw>
    Re: heredoc within heredoc (Rafael Garcia-Suarez)
    Re: IDE for development in perl (Helgi Briem)
    Re: If I don't want to 'goto' <johnlin@chttl.com.tw>
        Newbie but serious - Problems reading file from multipa <pholthuizen@celwood.com>
    Re: perl DBI <nospam@nospam.com>
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <jbuff1856@my-deja.com>
        Prototype problem when using 'do' deja8501@my-deja.com
    Re: Prototype problem when using 'do' <Michael.Schlueter@philips.com>
    Re: PWS - perl (ATTN: cwrites) <snefsite@hotmail.com>
    Re: regexp question <robert@no-spam.basil.com>
    Re: regexp question <robert@no-spam.basil.com>
    Re: regexp question <robert@no-spam.basil.com>
    Re: regexp question <Jerome.Abela@free.fr>
        regular expr. <snefsite@hotmail.com>
    Re: regular expr. <Michael.Schlueter@philips.com>
        Reverse "append to file" <cyner.mail@sweden.com>
    Re: Searching for a Value in an Array to remove (Ben Okopnik)
    Re: Understanding interpolation <nospam@nospam.com>
    Re: Understanding interpolation <nospam@nospam.com>
    Re: Use of uninitialized question? <damian@qimr.edu.au>
    Re: Use of uninitialized question? <jhelman@wsb.com>
    Re: using vi from within perl hedley_s@my-deja.com
    Re: Why are multiple zeroes true? (Abigail)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 22 Dec 2000 11:00:59 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: assign to array of references
Message-Id: <91uhk5$4nd@netnews.hinet.net>

"trwww" wrote
> sure if all you want is a reference... do:
>
> $a = \@a
> @$a[7 .. 10] = ('h' .. 'k');
> print @$a;

Sorry, I should give a better example.

my ($w,$x,$y,$z) = ('a'..'d');  # original values
@refs = (\$w, \$x, \$y, \$z);
??@refs = ('W'..'Z');    # Can we do it in one assignment?
print "$w $x $y $z\n";

__END__
W X Y Z

Dereference array of references to apply assignment in one statement.

John Lin





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

Date: Fri, 22 Dec 2000 09:05:23 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: automatic FAQ answerer idea
Message-Id: <43i44tchcuajl2kub2a3cukv55g2a8r7ql@4ax.com>

On 21 Dec 2000 01:34:00 -0600, logan@cs.utexas.edu (Logan Shaw) wrote:

> In article <x766kedznc.fsf@home.sysarch.com>,
> Uri Guttman  <uri@sysarch.com> wrote:
> >
> > it would generate too much new volume,
> 
> Once a question is posted, it is likely to generate volume whether or
> not an autoresponder is in place.  *If* the system could be made to
> work as intended, then I'd argue it would actually decrease volume
> since it would reply very quickly, and since it could potentially
> prevent flamewars.

And you think people would listen to your robot more often or more closely than
they listen to real live people with varying degrees of Perl proficiency and
politeness?

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.


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

Date: 22 Dec 2000 10:15:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: automatic FAQ answerer idea
Message-Id: <slrn946aeo.95k.abigail@tsathoggua.rlyeh.net>

Chris Stith (mischief@velma.motion.net) wrote on MMDCLXIX September
MCMXCIII in <URL:news:t4532nfeg8o1c4@corp.supernews.com>:
__ Logan Shaw <logan@cs.utexas.edu> wrote:
__ > In article <x766kedznc.fsf@home.sysarch.com>,
__ > Uri Guttman  <uri@sysarch.com> wrote:
__ >>it has been shot down for a variety of reasons.
__ 
__ I think it would be nice to have a test group for it,
__ so interested parties could see how it works and get in
__ on the development. It's obviously not a good idea to
__ test something in production on this scale anyway.
__ 
__ I propose the group alt.lang.perl.askthebot be created by
__ someone interested in the idea. Humans interested in the
__ idea could post there, as well as anyone who thinks that
__ their question may not be ready for posting to the
__ comp.lang.perl.* hierarchy. 


I've said it in previous rounds of this discussion before. The day 
bots replying to posting appear in this group is the day I unsubscribe.

This is a forum for humans. 



Abigail
-- 
perl -we'$;=$";$;{Just=>another=>Perl=>Hacker=>}=$/;print%;'


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

Date: 22 Dec 2000 00:09:07 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: bug in open()
Message-Id: <m3n1dpghzg.fsf@mumonkan.sunstarsys.com>

ilya@math.ohio-state.edu (Ilya Zakharevich) writes:

> [A complimentary Cc of this posting was NOT sent to Joe Schaefer 
> <joe+usenet@sunstarsys.com>],
> who wrote in article <m3r931hcjb.fsf@mumonkan.sunstarsys.com>:
> > IMHO, it's because the 5.6 behavior is unpredictable.
> 
> ?!  If start-process fails, it is reported to the caller.
> 
> >  The documentation I posted earlier says that open should succeed on
> > a successful fork, and fail if the fork fails.
> 
> Then this is a buggy piece of documentation (quite typical, sigh).
> This cannot be true, since start-a-process uses fork() on legacy
> systems only.

OK. Is there better documentation available that describes how 
5.6 works on legacy systems? (A pointer is fine, I just would 
like to know where I can learn the new stuff.)  Here's a few 
similar bad open calls:

5.6 FAILS on linux-
    (e.g. Can't exec "lls": No such file or directory at ...)

        open (DD, "lls|") || die "bad something: $!";
        open (DD, "lls 2>&1 |") || die "bad something: $!";

5.6 SUCCEEDS on linux-
    (e.g. sh: lls: command not found)

        open (DD, "lls 2>&- |") || die "bad something: $!";
        open (DD, "lls 2>/dev/null |") || die "bad something: $!";
        open (DD, "ps lls|") || die "bad something: $!";

> 
> > In 5.6, something funny is happening that passes the exec failure
> > back to open.
> 
> Yes, I managed to implement sane error-reporting on legacy systems too.
> 

Cool. Is there a simple reason that your sanity checks couldn't 
be extended to the other successful open calls listed above?

-- 
Joe Schaefer


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

Date: Fri, 22 Dec 2000 11:23:25 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: h4x0r vNought
Message-Id: <3A432B9D.8B1A08FB@schaffhausen.de>

Steven Smolinski schrieb:
> 
> Tom Christiansen <tchrist@perl.com> wrote:
> > #!/usr/bin/perl -p
> [... snip program that turns perfectly good english into some dialect
> of script kiddie ...]
> 
> Tom, if your post was an answer on Jeopardy, I'd have to guess that
> the reply, properly phrased in the form of a question, is:
> 
> "What output would prove that a man had altogether too much spare
> time?"

I wouldnt be suprised if he did it in 5 minutes. Too bad it doesn't run
in my beloved MacPerl.

->malte


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

Date: Fri, 22 Dec 2000 04:40:48 -0500
From: "Jody Fedor" <Jodyman@usa.net>
Subject: Help with SSI Parser for html pages.
Message-Id: <91v7gh$pam$1@plonk.apk.net>

#######  The question  ##########

#I have this script I've been working on but don't know
#how to evaluate or execute the command I've parsed.  Can
#anyone help?  This is the program:

#test1.htm contains the following for testing:
#<TR>
#<TD WIDTH=100><CENTER><A HREF="tcanon.htm"><IMG SRC="/gif/canon_100.jpg" >
#</A></CENTER></TD>
#<!--#if (-e '/home/usr61/specials/tspec.htm')
#{ &prochtm; $specials = "<TD WIDTH=100
ROWSPAN=9><CENTER>$htmlin</CENTER></TD>\n" } //-->
#</TR>

#####  The Program  ########

#!c:\perl\bin -w

$pageid = "c:/www/supplies/temp/test1.htm";
&Template;
print "\$HTML = $HTML\n";

exit;


sub Template {
 open (FILE,"$pageid")  || die "Cannot open template file $pageid: $!\n";
 while (<FILE>){
  $HTML .=$_; #print "$_\n";
 }
 close(FILE) || die "Cannot close template file $pageid: $!\n";
 &procssi; #Process SSI type information and insert html
 $HTML =~s/\$([a-zA-Z]+)/${$1}/g;
# If there is a $ with a word after it, it's a variable - Insert value here
${cartid} etc.
}

sub procssi {
$HTML =~ s/\<!--#(.+)\/\/--\>/\$specials/;
print "\$HTML = $HTML\n\n";
$ssicommand = $1;
#print "\$ssicommand = $ssicommand\n";
$ssicommand =~ s/(-e ')(.+)('\))/$1$2$3/;
$htmfile = $2;
print "\$htmfile = $htmfile\n";
print "\$ssicommand = $ssicommand\n\n\n";
}

sub prochtm {
 open (INFILE,"$htmfile")  || die "Cannot open template file $htmfile:
$!\n";
 while (<INFILE>){
  $htmlin .=$_; #print "$_\n";
 }
 close(FILE) || die "Cannot close template file $htmfile: $!\n";
 $htmlin =~s/\$([a-zA-Z]+)/${$1}/g;
# If there is a $ with a word after it, it's a variable - Insert value here
${cartid} etc.
}


#$ssicommand now contains: if (-e '/home/usr61/specials/tspec.htm')
#{ &prochtm; $specials = "<TD WIDTH=100
ROWSPAN=9><CENTER>$htmlin</CENTER></TD>\n" }
#$htmfile now contains: /home/usr61/specials/tspec.htm

#I know you can eval a variable but it's not the same as
#executing a variable is it?

#I would like to execute the perl command contained in the
#$ssicommand variable.  Can any one help here?

#PS - If there is a more perlish way to accomplish this, please let me know.

#Jody




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

Date: Fri, 22 Dec 2000 11:49:53 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: heredoc within heredoc
Message-Id: <91uj57$70s@netnews.hinet.net>

"Martien Verbruggen" wrote
> John Lin wrote:
> > Could you help me find out what's wrong with my code here?
> > print <<OUTSIDE;
> > This heredoc within heredoc @{[<<INSIDE;]} needs
> > OUTSIDE
> > some correction to make it work.
> > INSIDE
>
> Incorrect nesting.

OK.  What about this:

my @a = (
    <<A,  # for some reason, I need
    <<B,  # to separate these arguments
    <<C   # in 3 lines
good
A
better
B
best
C
);
print @a;

Doesn't work either (neither does nesting of CBA or BCA or ...)
I mean, is there a general rule for heredoc nesting?

Thank you.

John Lin





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

Date: Fri, 22 Dec 2000 09:57:03 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: heredoc within heredoc
Message-Id: <slrn9469nj.1ao.rgarciasuarez@rafael.kazibao.net>

John Lin wrote in comp.lang.perl.misc:
> 
> my @a = (
>     <<A,  # for some reason, I need
>     <<B,  # to separate these arguments
>     <<C   # in 3 lines
> good
> A
> better
> B
> best
> C
> );
> print @a;
> 
> Doesn't work either (neither does nesting of CBA or BCA or ...)
> I mean, is there a general rule for heredoc nesting?

Don't nest heredocs. Nested heredocs make your code hard to read.
I suggest :

my @a = (

    <<A,  # for some reason, I need
good
A

    <<B,  # to separate these arguments
better
B

    <<C   # in 3 lines
best
C

);

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
package another; sub AUTOLOAD { $AUTOLOAD =~ /::(.*)/;"$1 @_"; }
package hacker;  sub AUTOLOAD { $AUTOLOAD =~ /::(.*)/;"$1 @_,\n"; }
print Just another Perl hacker;


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

Date: Fri, 22 Dec 2000 09:30:20 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: IDE for development in perl
Message-Id: <3a431cf6.1289589842@news.itn.is>

On Thu, 21 Dec 2000 13:34:11 +0200, Juha Manninen
<juha.manninen@datex-ohmeda.com> wrote:

>
>Otto Wyss wrote:
>
>> Is there any useful IDE for development in perl (platform WindowsNT) or
>> does everyone just use a simple text editor?
>
I use PerlBuilder from solutionsoft.com.
Very good and cheap.  You can download
a free evaluation copy.  I recommend it.

Regards,
Helgi Briem


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

Date: Fri, 22 Dec 2000 10:11:33 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: If I don't want to 'goto'
Message-Id: <91udcr$rg9@netnews.hinet.net>

"Ilmari Karonen" wrote
> Malte Ubl wrote:
> >I guess you have to give a better reason to why not use subs.
> Well, he does have a point.

Thank you.  Your explanation was what I tried to say.

> However, a solution that does work, as Abigail pointed out, is to use
> a closure defined in the same scope.

Great!!!  I learned a lot here.

> while (condition) {
>       my ($lots, $of, $internal, $lexical, $state, $variables);
> #   . . .
>       my $fail = sub {
>           warn "I can see the lexicals here! (state = $state)\n";
>       };
> #   . . .
>       $fail->(), next if errorA;

I did some experiments and found out that we can put 'last', 'next' inside
the $fail.
It's quite convenient.  Although -w will warn:

    Exiting subroutine via last at line 5.

I think this kind of 'last', 'next' is harmless because
for "my" $fail, the scope is clear.
There would have no confusion for 'last', 'next'.

John Lin





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

Date: Fri, 22 Dec 2000 11:10:26 +0100
From: Patrick Holthuizen <pholthuizen@celwood.com>
Subject: Newbie but serious - Problems reading file from multipart forms (no  binmode!)
Message-Id: <3A432892.41ECA543@celwood.com>

Hi all,

As you all have I'm writing a script to upload files from a web browser
to a web site. Yes, I've stumble across all the common problems
(binmode) but I'm still having corrupt binary file uploads. The problem
seems to be in the file reading system, when I read the file supplied by
the user the script seems to read more bytes than the number actually
available in the file. These bytes seem to be occuring at random places
within the file. Seems like a binmode problem, but it isn't.

The script:
# Upload files
$onnum = 1;
while ($onnum != 11) {
 my $file = $req->param("FILE$onnum");
 if ($file ne "") {
  my $fileName = $file;
  $fileName =~ s!^.*(\\|\/)!!;
  open (OUTFILE, ">F:/www/mysite/$user/$fileName") || print "<br><b>$0
ERROR: $!</b><br>";
  binmode ($file);
  binmode (OUTFILE);
  $teller =0;
  while (read ($file, $buffer, 10000)) {
   $teller = $teller + length($buffer);
   print OUTFILE $buffer;
  }
 close (OUTFILE);
 print "File no. $onnum ($fileName) has been transfered. ($teller
bytes)<p>\n";
 }
 $onnum++;
};

I have also used sysread and syswrite but the same problem occurs. The
file I try to read is 9277 bytes long but the variable $teller contains
the value 9314 after reading the file???

Please inform me how to adjust my script (literally) so that my upload
works??

Any help is appreciated. Mail me if you want the binaries involved, I'm
unable to attach them to this newsgroup.

Sincerely,
Patrick Holthuizen



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

Date: 22 Dec 2000 06:41:50 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: perl DBI
Message-Id: <91ut3e$d73$0@216.155.32.177>

In article <3A4200A7.6BF29116@home.nl>, AvA <a.v.a@home.nl> wrote:

 | Bart Lateur wrote:
 | 
 | > The WebDragon wrote:
 | >
 | > > |  print table( map { Tr( map { td(escape_HTML($_)) } @$_ ) } 
 | > > |  @$two_d );
 | > >
 | > >is it possible to embed formatting subroutines into a line such as 
 | > >this
 | > >to ensure that for some td()'s I can set the bgcolor of the table 
 | > >cell
 | > >depending on the value of the variable to be inserted in the cell?
 | >
 | > Of course it is. There's nothing in there but code. The cell contents 
 | > is
 | > in $_ between the "{" and the "}" (where the "td(escape_HTML($_))" is)
 | > for the second map(). All you have to do is let the parameters for the
 | > sub td() depend on the value of $_. You may even put more than one
 | > statement, separated by semicolons, in a map block.
 | >
 | > If, however, you'd like do certain things differently per column, for
 | > example align the first column to the right, you'll have to manually
 | > keep track on the column number. There's no implicit loop counter
 | > (yet?). Put "my $i = 0;" before the "Tr", and be sure to do a $i++
 | > somewhere in the inner map block, but not as the final statement in 
 | > that
 | > block. That should remain the td call.
 | >
 | > --
 | >         Bart.
 | 
 | pff that makes an easy readible language like perl very hard to 
 | understand.
 | i prefer to use as little as modules as possible for learning purposes.
 | have to get it to work raw first.
 | 
 | thanks for the help all.
 
pff, I'm already there.. have it working, but it's all embedded html. A 
true perlish solution like this appeals to me greatly as it would 
enormously shorten my loop structure within all of this. 

I've been wanting to migrate my script to CGI.pm-style formatting since 
I started it, but the primary focus being "get it working" I didn't do 
that from the beginning. 

(considering the fact that I was teaching myself the first rudiments of 
perl this past may, while 'filling in the blanks in my perl knowledge' 
(starting from Ground 0 mind you) in order to complete my 'vision' of 
what I wanted, I didn't do too badly.. When the pages I was sucking the 
data changed from a Javascript format to a Database format, the re-write 
of the import script and cgi to use HTML::Parser instead of some 
complicated regexes took me only a day or so. (including figuring out 
how to use HTML::Parser) 

I still don't quite grok 'map' yet, but an example like that above takes 
me much closer to how I'd use it in MY OWN experience, and I can 
immediately see the benefits of using same within my script... making 
the 'figuring it out' part much much easier. :) 

This is, after all, how I learned HoHoL's so quickly. (Again kudos to 
this group for MAKING me go read perldsc, perllol, etc, instead of 
showing me.. now I KNOW IT) :)

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Fri, 22 Dec 2000 06:04:33 GMT
From: jbuff <jbuff1856@my-deja.com>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 0.3 $)
Message-Id: <91uqtg$j0i$1@nnrp1.deja.com>

In article <slrn945fem.6is.tadmc@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> Glad it helped.
>

Hope that it helps others. I've done enough lurking here to have
absorbed most of the guidelines by osmosis, but having a document I can
review quickly before hitting send, I'm much less likely to forget
something.

> P.S. If you ever do need to post a question, you might consider
>      switching to some other way of accessing news. The domain
>      you are using will restrict the readership of your articles...
>

I picked that up from the recent thread on closures. Although I'll
probably get flamed for this, I actually like Deja for my newsreader
(although I liked Remarq better when it was still there). Your point is
taken, if I need to reach folks who score down Deja posts, I'll post
from my ISP (where incoming news is slow and missing many articles). A
real news account would be the best answer, maybe when I can write perl
well enough to get paid for it...

-- jbuff


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 09:51:35 GMT
From: deja8501@my-deja.com
Subject: Prototype problem when using 'do'
Message-Id: <91v875$t5c$1@nnrp1.deja.com>

Hello,

I'm trying to write a library and I'd like to forbid incorrect function
calls (e.g. mandatory parameter is not specified). As far as I know I
can ensure this by writing the checks in the subroutines manually or by
using function prototyping.

I want to use prototyping like this:

- begin proto.pl ------------------

    #!/usr/bin/perl -w

    sub proto($);

    proto(3);      # correct
    proto();       # error
    proto(@_);     # error
    proto(4, 5);   # error

    sub proto($)
    {
	my $param = shift;
	print "$param\n";
    }

- end proto.pl --------------------


So far so good.

My library is supposed to be a testing framework. I'd like the users to
write small perl scripts which are to be executed by the framework:

- begin proto.pl ------------------

    #!/usr/bin/perl -w

    sub proto($);

    proto(3);
    do "do.pl";

    sub proto($)
    {
	my $param = shift;
	print "$param\n";
    }

- end proto.pl --------------------

- begin do.pl ---------------------

    proto();

- end do.pl -----------------------


proto() is seen by do.pl (it is called properly if I supply a
parameter), but nothing is printed and no compilation error occurs
because of the missing parameter.

Do you know why the  prototype requiring one parameter is not seen (or
not taken into account) in do.pl?

Thanks in advance,

Tom

P.S. If you can recommend me a more efficient way to check the function
parameters formally (preferably at compile time), please let me know.


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 11:35:41 +0100
From: "Michael Schlueter" <Michael.Schlueter@philips.com>
Subject: Re: Prototype problem when using 'do'
Message-Id: <3a432e80$0$8792$4dbef881@businessnews.de.uu.net>

Hi Tom,

Here is a way I do it on occasions:

#!/usr/bin/perl -w
use strict;    # just to know about my own stupid mistakes
use Carp;    # provides warn and confess

your_sub(3,4);


sub your_sub {

    if(scalar @_ !=2) {    # or n+1 if you use perl-objects; check with
debugger
        confess "wrong number of parameters passed to your_sub";
        # program dies with a valuable stack backtrace
    }

    my @list=@_;
    # things you want to do

}


If you need to check types passed, use the ref command and check, e.g. , for
SCALAR, ARRAY etc.

Michael




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

Date: Fri, 22 Dec 2000 11:36:18 +0100
From: "Sven Franke" <snefsite@hotmail.com>
Subject: Re: PWS - perl (ATTN: cwrites)
Message-Id: <91vako$g2m$1@enterprise.cistron.net>

<CUT>

How does your windows sytem bat file look then?
Is it just a line to be added???


Sven




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

Date: Fri, 22 Dec 2000 06:02:50 GMT
From: "Robert Basil" <robert@no-spam.basil.com>
Subject: Re: regexp question
Message-Id: <e8C06.86878$15.18361212@news1.rdc1.az.home.com>


"Jeff Helman" <jhelman@wsb.com> wrote in message
news:3A4288B7.14CE8C82@wsb.com...
> Robert Basil wrote:
>
> > So when I try and remove them, my regexp also removes the middle part of
the
> > message that I want to keep. I have triend about 20 different regexp's
with
> > no luck so far. Any hints?
>
> Why not show us some code?  This is a very trivial thing to do, so the
> chances are that your code would work with a minor tweak.  So post your
> latest regex and we'll see what we find.
>
> JH
>

I want to remove Block A and C (which are exactly the same) and leave B
intact.

<MULTILINE BLOCK OF TEXT A>
<MULTILINE BLOCK OF TEXT B>
<MULTILINE BLOCK OF TEXT C>

Here is a copy of what is in the A and C blocks that I want to remove: (Yes,
the 4 lines of 53 periods need to be removed also)

####Begin Example Before Message####
 .....................................................

SUBSCRIBE

If this newsletter has been forwarded to you, and
you wish to subscribe, simply send a blank e-mail to:
mailto:subscribe-listname@domain.com

UNSUBSCRIBE

You are currently subscribed to mailing-list-name:
listname@domain.com
To unsubscribe send a blank email to
mailto:leave-listname@domain.com
 .....................................................

The text that is here needs to be kept.

 .....................................................

SUBSCRIBE

If this newsletter has been forwarded to you, and
you wish to subscribe, simply send a blank e-mail to:
mailto:listname@domain.com

UNSUBSCRIBE

You are currently subscribed to mailing-list-name:
listname@domain.com
To unsubscribe send a blank email to
mailto:leave-listname@domain.com
 .....................................................
####End Example Before Message####



####Begin Example After Message####

The text that is here needs to be kept.

####End Example After Message####



Here are a few of my ideas that are not working (and thanks for helping!)

Try #1
's/\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
 .\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.+\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.//g'

Try #2
's/SUBSCRIBE\s++leave-listname\@domain\.com//g'
(I though this would at least remove the words, but not the periods. Which
is not what I am really shooting for but was better than nothing if it would
have worked)





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

Date: Fri, 22 Dec 2000 06:04:55 GMT
From: "Robert Basil" <robert@no-spam.basil.com>
Subject: Re: regexp question
Message-Id: <baC06.86879$15.18362053@news1.rdc1.az.home.com>

I almost forgot in my last post, the <MULTILINE BLOCK OF TEXT A> is at the
very beginning of the text message, and the <MULTILINE BLOCK OF TEXT C> is
at the very end.




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

Date: Fri, 22 Dec 2000 06:07:03 GMT
From: "Robert Basil" <robert@no-spam.basil.com>
Subject: Re: regexp question
Message-Id: <bcC06.86881$15.18363121@news1.rdc1.az.home.com>


"Tad McClellan" <tadmc@metronet.com> wrote in message
news:slrn9453s2.6dd.tadmc@magna.metronet.com...
> s/SUBSCRIBE
>
> If this newsletter has been forwarded to you, and
>
> you wish to subscribe, simply send a blank e-mail to:
>
> mailto:listname\@domain.com
>
> UNSUBSCRIBE
>
> You are currently subscribed to mailing-line-name:
>
> myname\@domain.com
>
> To unsubscribe send a blank email to
>
> mailto:leave-listname\@domain.com
> //g;
>
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas

Tad,

Thanks but no cigar.

P.S. Wouldn't I also need to escape the periods in your example above (I
tried that also just in case and it still failed)





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

Date: Fri, 22 Dec 2000 10:00:44 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: regexp question
Message-Id: <3A432585.99D63DAC@free.fr>

Robert Basil a écrit :
> Here is a copy of what is in the A and C blocks that I want to remove: (Yes,
> the 4 lines of 53 periods need to be removed also)
> 
> ####Begin Example Before Message####
> .....................................................
> [some text]
> .....................................................
> 
> The text that is here needs to be kept.
> 
> .....................................................
> [some text]
> .....................................................
> ####End Example Before Message####
> 
> ####Begin Example After Message####
> 
> The text that is here needs to be kept.
> 
> ####End Example After Message####

Let's restate the problem this way (tell me if i'm wrong): you want to
remove 2 blocks delimited with 53-period lines. Here is regexp which
does it:

    s/\.{53}.*?\.{53}//sg;

Note that without the /s modifier, '.+' does not match through newline
characters.


Jerome.


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

Date: Fri, 22 Dec 2000 11:30:35 +0100
From: "Sven Franke" <snefsite@hotmail.com>
Subject: regular expr.
Message-Id: <91va9v$flc$1@enterprise.cistron.net>

Hi,

I have a string that contains a lot of text. In the text there is a line
like:

[BLA=qwert-foo]

I want to extract this line and use the text behind the =sign. How can this
be done. I've wrestled with m/xx/, but I can't get it right.

Can someone help me out?
(I already tried the help on matchingpatterns, but I can't seem to get it
work.....)






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

Date: Fri, 22 Dec 2000 11:53:07 +0100
From: "Michael Schlueter" <Michael.Schlueter@philips.com>
Subject: Re: regular expr.
Message-Id: <3a433295$0$8781$4dbef881@businessnews.de.uu.net>

Sven,

A way to do it 'without' regexes may be:

    $string="some text here [BLA=qwert-foo] and something else here";
    @list=split/BLA=/, $string;

$list[0] has all code before this token ('some text here ['), $list[2] has
everything past that ('] and something else here'). You can use this wihtin
a loop that checks each line of your text.

You must be sure that this pattern is unique. Expect unexpected results,
depending on the contents of $string.


When using regexes the best way to do it is to say what you mean. Yor regex
will probably look like this:

    $string="some text here [BLA=qwert-foo] and something else here";
    $string=~m/BLA=(.*)/;    # match 'BLA=' first and then everything else
(.*)

    $what_I_want=$1;

 .* means: match anything (the dot) 0 or more times (the asterix). Putting
the paranthesis () around this pattern will pass all matches found (if any)
to perls variable $1 (the first pair of paranthesis).

Hope this helps you,
Michael




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

Date: Fri, 22 Dec 2000 09:26:59 GMT
From: chr1st1an <cyner.mail@sweden.com>
Subject: Reverse "append to file"
Message-Id: <3A431DBC.1000505@sweden.com>

Hello,

I'm all new to Perl and want to write a guestbook. (Heard that before? 
;) What my problem is is how to write to the beginning of a file, and 
letting the previous contents "move down" in the file. I suppose I could 
read the file into a variable and first write my new data into the file 
and then append this variable. But, since I'm new to Perl and don't have 
a book on the subject, I don't know what function calls to make.

Suggestions? Please?

(I did check your and other's FAQs before submitting this question. 
Couldn't find it, but that may be due to my lack of Perl knowledge.)

-- 
|
|      chr1st1an
|      cyner.mail@sweden.com
|



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

Date: 22 Dec 2000 07:50:48 GMT
From: fuzzybear@pocketmail.com (Ben Okopnik)
Subject: Re: Searching for a Value in an Array to remove
Message-Id: <slrn94622k.42n.fuzzybear@Odin.Thor>

The ancient archives of Thu, 21 Dec 2000 17:57:41 -0500 showed
Some_Indiana_Guy of comp.lang.perl.misc speaking thus:
>This is the code (borrowed from someone else) that creates the array.
>As you can see it puts a directory listing into the array. I want to
>use this array as a list of files to email to an internet email address.
>I am not wanting to email the files "." and ".." Is there maybe a way
>i can filter this out before it even gets into the array?? That might be
>a better way to approach it.
>
>
>my ($path,@filelist);
> $path="/some/unix/path";
> opendir(PATH,$path) or die "Can't open dir: $!\n";
> @filelist=readdir(PATH);
> closedir PATH;


How about -

@filelist=`ls -A1`;

This will give you all the filenames in the directory, except the '.' and 
the '..' entries.


Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Don't be ashamed to say what you are not ashamed to think.
 -- Montaigne


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

Date: 22 Dec 2000 06:46:49 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Understanding interpolation
Message-Id: <91utcp$d73$1@216.155.32.177>

In article <ifn34tks6p2suu3dk1fvbnh2p2rcatsf6l@4ax.com>, Abe Timmerman 
<abe@ztreet.demon.nl> wrote:

 | On 21 Dec 2000 04:52:00 GMT, The WebDragon <nospam@nospam.com> wrote:
 | 
 | ...
 | > How would one re-write this to alternate every n lines.. so that 
 | > instead 
 | > of every other line being different, it could be 2 and 2 or 3 and 3 
 | > and 
 | > 3 etc. ?
 | > 
 | > it's a nice trick, but what if you want more? :) embed the bgcolor in 
 | > a 
 | > subroutine?
 | 
 | 	my @colors = qw( orange red white blue );
 | 
 | 	printf "Alternate every %u lines\n", scalar @colors;
 | 	for my $cnt ( 0 .. (@colors * 2) - 1 ) {
 | 		print "line $cnt -> $colors[ $cnt % @colors ]\n";
 | 	}
 | 
 | 	# or did you want:
 | 	
 | 	printf "\nHighlight every %u-th line\n", scalar @colors;
 | 	for my $cnt ( 0 .. (@colors * 2) - 1 ) {
 | 		print "line $cnt -> $colors[ $cnt % @colors?1:0 ]\n"
 | 	}

sorta but not quite.. what if I wanted something like this:

line 0 -> orange
line 1 -> orange
line 2 -> red
line 3 -> red
line 4 -> orange
line 5 -> orange
line 6 -> red
line 7 -> red

or 

line 0 -> orange
line 1 -> orange
line 2 -> orange
line 3 -> none
line 4 -> none
line 5 -> none
line 6 -> green
line 7 -> green
line 8 -> green
line 9 -> none
"   10    none
"   11    none

 ...repeat

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: 22 Dec 2000 09:52:45 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Understanding interpolation
Message-Id: <91v89d$7ni$0@216.155.32.112>

In article <3A41BDD0.4FE85440@qimr.edu.au>, Damian James 
<damian@qimr.edu.au> wrote:

 | On 21 Dec 2000 04:52:00 GMT The WebDragon <nospam@nospam.com> wrote:
 | >How would one re-write this to alternate every n lines.. so that 
 | >instead 
 | >of every other line being different, it could be 2 and 2 or 3 and 3 and 
 | >3 etc. ?
 | >
 | >it's a nice trick, but what if you want more? :) embed the bgcolor in a 
 | >subroutine?
 | 
 | Would this do the trick? You could modify it to take a list of colours
 | as an argument, 
 | then use the length of the list as n.
 | 
 | Cheers,
 | Damian
 | 
[snip]

this is closer, as it does 'what I want' but not 'how I want to do it' 
by forcing the values rather than computing them.

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

use strict;
#use warnings; # 5.004 here :)

use CGI;

my $cgi=CGI->new();
my @rows = qw(First Second Third Fourth Fifth Sixth Seventh Eighth Ninth
Tenth Eleventh Twelfth);
my $n = 9;

print $cgi->header,
      $cgi->start_html("Test for alternating colours"),
      &alternating_colours($n, \@rows),
      $cgi->end_html;

exit();

sub alternating_colours {

   ### need longer list of colours for n>6
    my $colours = 
       [ qw(red red red yellow yellow yellow orange orange orange) ];

    my $n = shift;
    my $rows = shift;
    my $count = 0;
    my $table = "<table>\n";

    foreach (@{$rows}) {
        $table .= 
          qq!<tr><td bgcolor="$colours->[($count++)%$n]">$_</td></tr>\n!;
    }

    $table .= "</table>\n";
    return $table;
}
__END__

as you can see I've 'forced' the color values to DWIM, but it's not 
being computed on the fly based on length of list or anything else. 

I'd like to be able to arbitrarily determine how many of the colors will 
be shown, and how long before it switches to the next color. 

Anyone want to take a swat at this? :)

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Fri, 22 Dec 2000 15:14:01 +1000
From: Damian James <damian@qimr.edu.au>
Subject: Re: Use of uninitialized question?
Message-Id: <3A42E319.B22BEF5F@qimr.edu.au>

Hi,

On Fri, 22 Dec 2000 04:06:36 GMT, Pasquale <pdmos23@geocities.com>
wrote:
>The code being used is:
>my $age = param('age');
 ...
>if (($age eq "") || ($age eq undef)) {
>$age = "Not entered";
>}
 ...
>Secondly, how else can this be done?  Aren't the variables defined 
>after the conditional stmt?

You can replace all of it with this:

my $age = param('age') || "Not entered";
my $adr = param('adr') || "Not entered";

The problem was that the variables were undefined DURING the conditional
statement, and this was producing your warning message. While it's not a
syntax error to use an undefined value in an 'eq', it will still produce
a warning.

I do suggest you use a text editor that tells you the line numbers -- it
can be a big help, and this would have shown you exactly where the error
was occurring. 

Cheers,
Damian


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

Date: Fri, 22 Dec 2000 05:25:11 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Use of uninitialized question?
Message-Id: <3A42E5D0.E326E0FE@wsb.com>

Pasquale wrote:

> if (($age eq "") || ($age eq undef)) {
>  $age = "Not entered";
> }
> if (($adr eq "") || ($adr eq undef)) {
>  $adr = "Not entered";
> }
> and so on.....
> 
> My first question, I'm not sure about the "($variablename eq undef)"?
> Is this OK?

There is a better way.  Use the defined() function.  And, if you are
familiar with the ?: syntax borrowed from C (or even if you aren't --
it's a one-line version of an if-else loop), you can do your assignments
in one line:

my $age = (defined(param('age')) && param('age') ne '') ? param('age') :
"Not entered";
my $adr = (defined(param('adr')) && param('adr') ne '') ? param('adr') :
"Not entered";

defined() checkes whether or not your requested variable is defined.  In
the code above, if the variable is not defined, or if the variable
contains the null string, "Not entered" will be used.  Otherwise, your
CGI input (I'm guessing, but that's it, right?) will be used.  Using the
above code should eliminate the warnings you are receiving.

Hope this helps,
JH


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

Date: Fri, 22 Dec 2000 10:45:49 GMT
From: hedley_s@my-deja.com
Subject: Re: using vi from within perl
Message-Id: <91vbcs$v6t$1@nnrp1.deja.com>

thanks for your help guys.

H

In article <3A423BC6.B9881D71@alcatel.be>,
  David Hiskiyahu <David.Hiskiyahu@alcatel.be> wrote:
> Thanks a lot, now it is clear to me how these I/O
> pipes are plugged into each other in the two cases.
>
> Carl Wu wrote:
> >
> > There are fundamental differences between these two commands:
> > 1. $status = `vi $filename`;
> > 2. $status = system("vi $filename");
> >
> > In the first command, the $status will get the standard output of
the
> > command "vi $filename". And the vi process will get the standard
input (your
> > keyboard) from its parent process ("perl"), but its standard output
has been
> > redirected to some system area to be assigned to $status variable
of your
> > program. So you can type any command to the vi process but you
won't see
> > anything from vi until you quit vi, after that if you print $status
from
> > perl program you will see what you should have seen with a normal
vi.
> >
> > In the second command, the $status will get the exit status of the
command
> > "vi $filename". And the vi process will inherite both standard
input (your
> > keyboard) and standart output (your monitor) from its parent process
> > ("perl"), the vi works fine. And the $status will be an integer
which is the
> > exit status of vi, completely different with the first case.
> >
> > Hope this helps.
> >
> > Carl Wu
> >
> > David Hiskiyahu wrote in message <3A40F8F2.D57D2DCD@alcatel.be>...
> > >...
> > >> > I know that this is not good practice but though that I would
be able
> > >> > to do the following:
> > >> >
> > >> >    $status = `vi $filename`  ;
> > >> >
> > >> > However, this seems to put me in vi mode, but the screen stays
as it
> > >> > is until I exit vi, I cannot see the file contents.
> > >...
> > >
> > >mike_solomon@lineone.net wrote:
> > >>
> > >> try:
> > >>
> > >> system("vi filename");
> > >>
> > >> this will open the file to edit
> > >>
> > >> when you exit vi it will return you to the script
> > >>
> > >...
> > >
> > >Mike, any clue why 'system' works ok here while the backticks
fails?
> > >
> > >I wonder if there is some written info on the difference between
the two,
> > >which most of time behave just the same.
> > >
> > >I can guess that 'system' causes the perl parent process to fork a
child
> > >process and wait for it to exit, while backticks probably runs the
system
> > >command under the same process, which must mess up the i/o, which
must be
> > >the reason for backticks failing to show the vi window.
> > >
> > >'%man perlfunc' in the section of 'system' does clearly say
that 'system'
> > >forks a child and waits, but I couldn't find a clear description
of how
> > >backticks work ...
>
> --
> ***   David Hiskiyahu, Alcatel SRD, 1 Fr.Wellesplein,  Antwerp  ***
> ***    Phone/Fax: +32 3 240 7965/9820, private +32 3 290 0912   ***
>
> Quote of the day:
>
> "He doesn't know the meaning of the word 'fear'.
>  Of course, there are lots of other words he
>  doesn't know either."
>
> - San Diego Chargers coach Sid Gilman on one of his first year
players.
>


Sent via Deja.com
http://www.deja.com/


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

Date: 22 Dec 2000 09:59:22 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Why are multiple zeroes true?
Message-Id: <slrn9469fq.95k.abigail@tsathoggua.rlyeh.net>

Uri Guttman (uri@sysarch.com) wrote on MMDCLXX September MCMXCIII in
<URL:news:x7y9x9cask.fsf@home.sysarch.com>:
:} >>>>> "m" == miko  <miko@idocs.com> writes:
:} 
:}   m> In article <3a3a3cc9@cs.colorado.edu>,
:}   m>   tchrist@perl.com (Tom Christiansen) wrote:
:} 
:}   >> It's cleanest to thing of there being just two false values in Perl:
:}   >> zero and the null string--thus, anything that reduces to one of
:}   >> these is itself false.  I like thinking of it like this because
:}   >> it's easier to remember just 2 rules than the 4, 5, or even 6 that
:}   >> you often see people cite.
:} 
:}   m> Well, that's exactly the reason that led to me expect "000" to be false:
:}   m> it fits into the first rule of reducing to zero (as it does in a numeric
:}   m> context).  To make "0" false but "000" true you have use more
:}   m> complicated rules.
:} 
:} you are going backwards. starting with undef you can get to '', 0 and
:} then to '0'. you cannot generate '00' from those with just context.

You can't generate 0.0 from context either, yet that's false too.

:} so those 4 false values are consistant with each other and with no
:} others being false. boolean contexts do not convert strings to numbers
:} and vice versa. they will convert an undef to '' or 0. so '00' in a
:} boolean context is just another string that is not '0' so it is true.
:} 
:} and one other point, it is much faster to check a string is '0' then for
:} any multiple zero string. since boolean tests are so common, it is a
:} good thing that false is limited to only those 4 values. 


Well, I'm not at all sure it's much faster this way. Here's the macro
for that tests for trueness (if compiled with gcc):

#  define SvTRUE(sv) (                                          \
    !sv                                                         \
    ? 0                                                         \
    :    SvPOK(sv)                                              \
        ?   (({XPV *nxpv = (XPV*)SvANY(sv);                     \
             nxpv &&                                            \
             (nxpv->xpv_cur > 1 ||                              \
              (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); })      \
             ? 1                                                \
             : 0)                                               \
        :                                                       \
            SvIOK(sv)                                           \
            ? SvIVX(sv) != 0                                    \
            :   SvNOK(sv)                                       \
                ? SvNVX(sv) != 0.0                              \
                : sv_2bool(sv) )


As you can see, to check for trueness, Perl prefers to check the
string value of a scalar, then the integer value and then the double.
It has to, to handle "0" vs "00" correctly.

But if multiple 0's would result in false, Perl can go for the (fast)
integer check first, and only check the string if the scalar has 
neither a valid integer nor a valid double value.



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

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


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