[10294] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3887 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 4 13:07:58 1998

Date: Sun, 4 Oct 98 10:00:27 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 4 Oct 1998     Volume: 8 Number: 3887

Today's topics:
    Re: CGI.pm - forms within tables - How to? (Craig Berry)
    Re: CGI.pm - forms within tables - How to? (Craig Berry)
    Re: Custom HTML functions - I could use some direction, (Tad McClellan)
    Re: DEL in PERL (Ronald J Kimball)
    Re: FAQ: Daylightsavings problem <patrick@arch.ethz.ch>
    Re: FAQ: Daylightsavings problem (Larry Rosler)
    Re: grep syntax question (Larry Rosler)
    Re: help needed (Craig Berry)
        help with finding a regular expression <toby@hans.cs.man.ac.uk>
    Re: help with finding a regular expression <garry@america.net>
        HERE Documents and skipping indentation (advanced) (Jari Aalto+mail.perl)
    Re: HERE Documents and skipping indentation (advanced) <matt@whiterabbit.co.uk>
    Re: HERE Documents and skipping indentation (advanced) (Jari Aalto+mail.perl)
    Re: HERE Documents and skipping indentation (advanced) <garry@america.net>
    Re: HERE Documents and skipping indentation (advanced) <tchrist@mox.perl.com>
    Re: HERE Documents and skipping indentation (advanced) (Tad McClellan)
    Re: how can I build array of lists (Craig Berry)
        How do you setup Win98 to run perl CGI scripts (Abdul Ali)
        How to write a MS Excel file (Hans Xie)
        i need a simple email parser <xxx@xxx.xx>
    Re: i need a simple email parser (Mads Toftum)
    Re: Is perl the correct choice for this problem? <gellyfish@btinternet.com>
    Re: Multi-dimensional arrays (Joonas Timo Taavetti Kekoni)
        Please help with simple perl script priyo@expert.cc.purdue.edu
        read subdirectories <richarda@profil-cdi.qc.ca>
    Re: read subdirectories (Douglas SEAY)
        Removing a line from a file (Stephen Benjamin)
        Sending and receiving data to/from a weather server? <vincent@psnw.com>
        Survey Script <matt@whiterabbit.co.uk>
    Re: Survey Script (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 29 Sep 1998 17:03:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: CGI.pm - forms within tables - How to?
Message-Id: <6ur3sq$2fm$4@marina.cinenet.net>

Matt Knecht (hex@voicenet.com) wrote:
: Steven D Jones <Steve_D_Jones@hp.com> wrote:
: >I would like to create a form which is formated by placing the input fields 
: >inside of a table.  Here's an html example:
: 
: [ snip HTML ]
: 
: >How would I do this using CGI.pm?
: 
: You don't.  CGI.pm doesn't know anything about tables.  You need to
: build your own tables, and use CGI.pm to fill in the cells of the table.

I beg to differ.  CGI.pm is extremely useful for generating HTML
constructs.  See my preceding post on this thread.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: 29 Sep 1998 17:02:00 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: CGI.pm - forms within tables - How to?
Message-Id: <6ur3q8$2fm$3@marina.cinenet.net>

Steven D Jones (Steve_D_Jones@hp.com) wrote:
: I would like to create a form which is formated by placing the input fields 
: inside of a table.  Here's an html example:
: 
: <HTML><BODY>
: <TABLE BORDER=1>
: <FORM>
: 
: <TR>
: <TD><INPUT TYPE="radio" NAME="test" VALUE="Hello">Hello</TD>
: <TD><INPUT TYPE="radio" NAME="test" VALUE="Goodbye">Goodbye</TD>
: </TR>
: 
: </FORM>
: </TABLE>
: </HTML></BODY>
: 
: How would I do this using CGI.pm?

It's generally better to wrap the form around the table, rather than the
reverse...that is, swap <TABLE ...> and <FORM> above, and also </FORM> and
</TABLE>.  Applying this fix and translating to CGI.pm-ese, we get:

  print header,                   # Assuming this is a CGI app, of course.
        start_html('Example'),
        start_form,
        table({border => 1},
              Tr(td([ '<input type="radio" name="test" value="Hello">Hello',
                      '<input type="radio" name="test" value="Goodbye">Goodbye'
                    ]))),
        end_form,
        end_html;

Note that since you want the radio buttons in separate cells, you can't
use CGI.pm's radio_group function; hence the literal HTML for these.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: Sun, 4 Oct 1998 11:10:08 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Custom HTML functions - I could use some direction, hints, help!  :-)
Message-Id: <0l68v6.63c.ln@flash.net>

cnlsilva@3dgaming.com wrote:
: I am attempting to modify a script to allow a HTML page to be updated
: dynamically.  I want to use a custom tag <poll> and </poll> to allow
: new information to be updated to the page in a easy to use manner.
: I have Mastering Regular Expressions and Programming Perl and was not
: able to find a model in which a string\output was put inbetwent two
: tags located anywhere in a file - any help or direction???


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

$new_text = "I am the replacement text\n";

while (<DATA>) {
   print unless m#^<poll># .. m#^</poll>#;  # print line if not in "range"

   print $new_text if /^<poll>/;            # output the replacement text 
}

__DATA__
<HTML>
<P>stuff</P>

<poll>
replace me
</poll>

<P>more stuff</P>
</HTML>
-----------------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 4 Oct 1998 12:08:23 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: DEL in PERL
Message-Id: <1dgdijp.13sprl4bm4feoN@bay1-304.quincy.ziplink.net>

[posted and mailed]

Computer Guru <computerguru@mailexcite.com> wrote:

> When I copied the script you gave me..it looked kind of funny..I haven't
> been doing Perl long, but I just had this feeling, so I decided to run the
> script on my developmental machine. I changed the path to c:\perl\bin
> (which is my win95 path) and ran the script....it deleted the whole hard
> drive! A 2 G drive in 15 seconds! Good thing a lost 2 days work instead of
> months! Having a rogue script like that on a server can definitely decimate
> the sanity of the net admin! I don't think anyone should run that script
> unless they don't value their own data or couldnt care less about someone
> else's! As an aside....I doubt Virus scanners have the capability to scan
> Perl Scripts.
> 
> Ronald J Kimball <rjk@coos.dartmouth.edu> wrote in article
> <1dgarwu.16fbl3q5m81uhN@bay1-183.quincy.ziplink.net>...
> > Computer Guru <computerguru@mailexcite.com> wrote:
> > 
> > > find2perl? I have to look into that...I'm assuming it's a third party
> app?
> > 

You must be referring to someone else, because I did not give you a
script.  I simply directed you to the find2perl script, which is
included in the Perl distribution, and which would not delete any files
on your hard drive if you ran it.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sun, 04 Oct 1998 15:02:38 +0200
From: Patrick Sibenaler <patrick@arch.ethz.ch>
Subject: Re: FAQ: Daylightsavings problem
Message-Id: <361771EE.41C6@arch.ethz.ch>

> Use gmtime instead of localtime
  I tought about that too, but doesn't gmtime only ignore the 
  timezone-offset? That would give you GMT Time but including 
  the daylight-saving offset....

> or point at noon instead of midnight.
  True. very handy in case you don't have to track timepointers 
  around midnight. But assume you have a timetable-database that 
  uses seconds as pointers to slots (like 0.00-1.00, 1.00-2.00 
  etc..) and runs around the clock. In this case you still have
  the problem.

patrick./



droby@copyright.com wrote:
> 
> Two possibilities spring to mind as you seem to be interested in the date
> portion.
> 
> Use gmtime instead of localtime or point at noon instead of midnight.
> 
> --
> Don Roby
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own



-- 
---------------------------------------------------------------------------
The trick is to communicate bi-directional in real time and high
resolution
---------------------------------------------------------------------------


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

Date: Sun, 4 Oct 1998 09:11:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: FAQ: Daylightsavings problem
Message-Id: <MPG.10813e27cdcfdd3698989a@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <361771EE.41C6@arch.ethz.ch> on Sun, 04 Oct 1998 15:02:38 
+0200, Patrick Sibenaler <patrick@arch.ethz.ch> says...
> > Use gmtime instead of localtime
>   I tought about that too, but doesn't gmtime only ignore the 
>   timezone-offset? That would give you GMT Time but including 
>   the daylight-saving offset....

It has the advantage of increasing monotonically and uniformly, which 
localtime doesn't do.
 
> > or point at noon instead of midnight.
>   True. very handy in case you don't have to track timepointers 
>   around midnight. But assume you have a timetable-database that 
>   uses seconds as pointers to slots (like 0.00-1.00, 1.00-2.00 
>   etc..) and runs around the clock. In this case you still have
>   the problem.

In this case you cannot use localtime as an index, because once a year it 
skips an hour and once a year it duplicates an hour.

You can readily compute the timezone offset at any instant using the 
results of gmtime($time) and localtime($time) in list context, as I have 
posted in the past.  Only the needs of your application can determine how 
much trouble you want to go through.

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


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

Date: Sun, 4 Oct 1998 08:52:03 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: grep syntax question
Message-Id: <MPG.1081397d69089f27989899@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <36171A50.BF8F90FD@mit.edu> on Sun, 04 Oct 1998 02:48:48 -
0400, Alok Saldanha <camel@mit.edu> says...
> Stephen Totten wrote:
> > I know how do to a regular grep on a string, but how do I do a '-i' test?
> > grep {?i/.pdf$/} $file
> 
>   Okay, I think I see what you're getting at . You mean the -i filetest
> operator. What you need is the "and"
> shortcircuit operator. Also, grep acts on a list. Try something like the
> following:
> 
> grep {((/.pdf$/) and (-i $_))} @files
> 
> to find all the .pdf files which are -i (whatever -i means...). some of my
> parens might be redundant... you can experiment and see what works.

It is irresponsible to answer "-i (whatever -i means...)" without taking 
the trouble to find out.  (You might encounter some interesting file-test 
operators that you didn't know about, but '-i' wouldn't be one of them.)

It is especially irresponsible because this question was answered 
insightfully three times ten days ago.  
<URL:http://x9.dejanews.com/getdoc.xp?AN=394332523&CONTEXT=907515635.8925
34943&hitnum=1>

Please don't add further to the noise level of this group.  Invest a 
little effort, and test before you post, instead of just saying "you can 
experiment and see what works."  So can you.  Or you can read the group 
and learn for yourself, as most of us have.

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


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

Date: 29 Sep 1998 16:45:19 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: help needed
Message-Id: <6ur2qv$2fm$2@marina.cinenet.net>

bjjgann (bjjgann@liv.ac.uk) wrote:
: I have a small perl script which opens a file , searches for a string and 
: replaces the string then saves the outcome to another file. This works fine 
: unless the serach string is a + to which i get an error :-
: 
: /+/: ?+* follows nothing in regexp

You need to protect regex metacharacters in your input (or change the
input to be regex-cognizant, which is hard if you're not creating it, but
does give you a lot more flexibility in matching.  But let's assume you
want to take the easy way out.

: below is the code:-
[snip]
: 		s/$search/$replace/gie; 

Change to:      s/\Q$search/$replace/gie;

I suspect that 'e' modifier at the end is utterly unnecessary, btw.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: 04 Oct 1998 15:36:10 +0100
From: Toby Howard <toby@hans.cs.man.ac.uk>
Subject: help with finding a regular expression
Message-Id: <yf667e0z95x.fsf@hans.cs.man.ac.uk>

Hi, I'd be very grateful if anyone could help me to find a regular
expression that substitutes one string for another, but only if the string
to be replaced appears within two other known fixed delimiters. For
example, given:

   "Hello<delim>Here's my problem</delim>everyone."

The regexp would replace all "e"s by "*"s, but only if the "e"s lie within
<delim></delim>:

   Hello<delim>h*r*'s my probl*m</delim>everyone.

Cheers!
Toby

-- 
--------------------------------------------------------------
Toby Howard |   Lecturer  |  Science writer   |   ET Moderator
toby@cs.man.ac.uk      http://www.cs.man.ac.uk/aig/staff/toby/
Tel: +44(0)161-275-6274                Fax: +44(0)161-275-6236
Advanced  Interfaces  Group, Department  of  Computer  Science
University of Manchester, Oxford Road, Manchester, M13 9PL, UK
--------------------------------------------------------------



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

Date: Sun, 04 Oct 1998 15:24:14 GMT
From: "Garry T. Williams" <garry@america.net>
Subject: Re: help with finding a regular expression
Message-Id: <36179372.5F6B6181@america.net>

Toby Howard wrote:
> 
> Hi, I'd be very grateful if anyone could help me to find a regular
> expression that substitutes one string for another, but only if the string
> to be replaced appears within two other known fixed delimiters. For
> example, given:
> 
>    "Hello<delim>Here's my problem</delim>everyone."
> 
> The regexp would replace all "e"s by "*"s, but only if the "e"s lie within
> <delim></delim>:
> 
>    Hello<delim>h*r*'s my probl*m</delim>everyone.

	#!/opt/perl/bin/perl -w
	use strict;
	my ($s, $t);
	$s = "Hello<delim>Here's my problem</delim>everyone.\n";

	$s =~ s!<delim>(.*?)</delim>!
		$t = $1; 
		$t =~ s/e/\*/g; 
		"<delim>$t</delim>";
	!ge;

	print $s;
	__END__

	----- Result -----
	Hello<delim>H*r*'s my probl*m</delim>everyone.

I didn't try to get the thing to lowercase the "H" in "Here's" in your
example :-).  

-Garry Williams


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

Date: 04 Oct 1998 16:37:17 +0300
From: jari.aalto@poboxes.com (Jari Aalto+mail.perl)
Subject: HERE Documents and skipping indentation (advanced)
Message-Id: <ptru31kv46q.fsf@olkikukka.i-have-a-misconfigured-system-so-shoot-me>


	[CC is fine thank you]

	HERE docs require that you outdent all text, so I was hoping
	to use substitute operator to ignore the leading indentation.
	Would anyone know how to do that. 

	jari


print <<EOF =~ s/^\s+//;
                    this and that

                    this
                    and more on this
                    and more on this
                    and more on this
EOF

Can't modify scalar in substitution at /users/jaalto/t.pl line 21, near "s/^\s+//;"



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

Date: Sun, 04 Oct 1998 14:52:03 +0100
From: Matt Pryor <matt@whiterabbit.co.uk>
To: "Jari Aalto+mail.perl" <jari.aalto@poboxes.com>
Subject: Re: HERE Documents and skipping indentation (advanced)
Message-Id: <36177D83.7C965A03@whiterabbit.co.uk>

The only requirement of HERE documents is that the string terminator
must have no preceding or following characters, other than a newline.

print <<EOF;

hello
	hello
		hello

EOF

is fine.  The text inbetween makes no difference.

Cheers

Matt
--





Jari Aalto+mail.perl wrote:
> 
>         [CC is fine thank you]
> 
>         HERE docs require that you outdent all text, so I was hoping
>         to use substitute operator to ignore the leading indentation.
>         Would anyone know how to do that.
> 
>         jari
> 
> print <<EOF =~ s/^\s+//;
>                     this and that
> 
>                     this
>                     and more on this
>                     and more on this
>                     and more on this
> EOF
> 
> Can't modify scalar in substitution at /users/jaalto/t.pl line 21, near "s/^\s+//;"

-- 
Matt's daily comic strip
Porridge and Fartcakes
http://www.whiterabbit.co.uk/cartoons


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

Date: 04 Oct 1998 17:25:56 +0300
From: jari.aalto@poboxes.com (Jari Aalto+mail.perl)
Subject: Re: HERE Documents and skipping indentation (advanced)
Message-Id: <ptrr9wov1xn.fsf@olkikukka.i-have-a-misconfigured-system-so-shoot-me>

Matt Pryor <matt@whiterabbit.co.uk> writes:

> 
> The only requirement of HERE documents is that the string terminator
> must have no preceding or following characters, other than a newline.
> 
> print <<EOF;
> 
> hello
> 	hello
> 		hello
> 
> EOF


I meant that the printing should skip the leading indenation and not
include it; so that you can place it nicely indented inside sub

    sub Function
    {
	print << ..
		text.
		text.

    EOF
    }

Instead of having to write

    sub Function
    {
	print << ..
    text.
    text.

    EOF
    }

I know it is possible to write


    @data = <<END =~ /(\S.*)/g;
	12
      34
     56
    END

But I don]t know how to include the newline in the regexp.
I could possibly do join, "\n",<<END  But I was wondering if
regexp would be enough.


jari



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

Date: Sun, 04 Oct 1998 14:48:13 GMT
From: "Garry T. Williams" <garry@america.net>
Subject: Re: HERE Documents and skipping indentation (advanced)
Message-Id: <36178B01.13220E@america.net>

Jari Aalto+mail.perl wrote:
[snip]
> 
> I know it is possible to write
> 
>     @data = <<END =~ /(\S.*)/g;
>         12
>       34
>      56
>     END
> 
> But I don]t know how to include the newline in the regexp.
> I could possibly do join, "\n",<<END  But I was wondering if
> regexp would be enough.

	#!/opt/perl/bin/perl -w
	print <<END =~ /(\S.*\n)/g;
	        12
	              34
	           56
	END
	__END__

	----- Result -----
	12
	34
	56

-Garry Williams


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

Date: 4 Oct 1998 14:47:20 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: HERE Documents and skipping indentation (advanced)
Message-Id: <6v81po$8n9$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    jari.aalto@poboxes.com (Jari Aalto+mail.perl) writes:
:	HERE docs require that you outdent all text, so I was hoping
:	to use substitute operator to ignore the leading indentation.
:	Would anyone know how to do that. 


>From the Perl Cookbook, chapter 1:

=head1 Indenting Here Documents

=head2 Problem

When using the multiline quoting mechanism called a ``here document'',
the text must be flush against the margin, which looks out of place in
the code.  You would like to indent the here document text in the code,
but not have the indentation appear in the final string value.

=head2 Solution

Use a C<s///> operator to strip out leading white space.

    # all in one
    ($VAR = <<HERE_TARGET) =~ s/^\s+//gm;
	your text
	goes here
    HERE_TARGET

    # or with two steps
    $VAR = <<HERE_TARGET;
	your text
	goes here
    HERE_TARGET
    $VAR =~ s/^\s+//gm;

=head2 Discussion

The substitution is straightforward.  It removes leading white space
from the text of the here document.  The C</m> modifier lets the C<^>
character match at the start of each line in the string, while the C</g>
modifier makes the pattern matching engine repeat the substitution as
often as it can (i.e., for every line in the here document).

    ($definition = <<'FINIS') =~ s/^\s+//gm;
	The five varieties of camelids
	are the familiar camel, his friends
	the llama and the alpaca, and the
	rather less well-known guanaco
	and vicuqa.
    FINIS

Be warned: all the patterns in this recipe use C<\s>, which will also
match newlines.  This means they will remove any blank lines in your
here document.  If you don't want this, replace C<\s> with C<[^\S\n]>
in the patterns.

The substitution makes use of the property that the result of an
assignment can be used as the left-hand side of ``C<=~>''.  This lets us
do it all in one line, but only works when you're assigning to a variable.
When you're using the here document directly, it would be considered
a ``constant value'' and you wouldn't be able to modify it.  In fact,
you can't change a here document's value I<unless> you first put it into
a variable.

Not to worry, though, because there's an easy way around this,
particularly if you're going to do this a lot in the program.  
Just write a subroutine to do it:

    sub fix {
	my $string = shift;
	$string =~ s/^\s+//gm;
	return $string;
    }

    print fix(<<"END");
	My stuff goes here
    END

    # With function predeclaration, you can omit the parens:
    print fix <<"END";
	My stuff goes here
    END

As with all here documents, you have to place the here document's target
(the token that marks its end, C<END> in this case) flush against the
left hand margin.  If you want to have the target indented also, you'll
have to put the same amount of whitespace in the quoted string as you
use to indent the token.

    ($quote = <<'    FINIS') =~ s/^\s+//gm;
	    ...we will have peace, when you and all your works have
	    perished--and the works of your dark master to whom you would
	    deliver us. You are a liar, Saruman, and a corrupter of men's
	    hearts.  --Theoden in /usr/src/perl/taint.c
        FINIS
    $quote =~ s/\s*--/\n--/;

If you're doing this to strings that contain code you're building up for
an C<eval>, or just text print out, you might not want to blindly strip
off all leading whitespace, because that would destroy your indentation.
Although C<eval> wouldn't care, your reader might.

Another embellishment is to use a special leading string for code that
isn't ``real'' yet so that it stands out.  For example, here we'll
prepend each line with C<@@@>, properly indented.

    if ($REMEMBER_THE_MAIN) {
	$perl_main_C = dequote<<'    MAIN_INTERPRETER_LOOP';
	    @@@ int
	    @@@ runops() {
	    @@@     SAVEI32(runlevel);
	    @@@     runlevel++;
	    @@@     while ( op = (*op->op_ppaddr)() ) ;
	    @@@     TAINT_NOT;
	    @@@     return 0;
	    @@@ }
	MAIN_INTERPRETER_LOOP
	# add more code here if you wnat
    }

Destroying indentation also tends to get you in trouble with poets.

    $poem = dequote<<EVER_ON_AND_ON;
	   Now far ahead the Road has gone,
	      And I must follow, if I can,
	   Pursuing it with eager feet,
	      Until it joins some larger way
	   Where many paths and errands meet.
	      And whither then? I cannot say.
		    --Bilbo in /usr/src/perl/pp_ctl.c
    EVER_ON_AND_ON
    print "Here's your poem:\n\n$poem\n";

The following C<dequote> function handles all these cases.  It expects to
be called with a here document as its argument.  It looks to see whether
each line begins with a common substring, and if so, strips that off.
Otherwise, it takes the amount of leading white space found on the first
line and removes that much off each subsequent line.

    sub dequote {
	local $_ = shift;
	my ($white, $leader);  # common white space and common leading string
	if (/^\s*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) {
	    ($white, $leader) = ($2, quotemeta($1));
	} else {
	    ($white, $leader) = (/^(\s+)/, '');
	}
	s/^\s*?$leader(?:$white)?//gm;
	return $_;
    }

If that pattern makes your eyes glaze over, you can always break it up
and add comments by adding C</x>:

	if (m{
		^			# start of line
		\s *			# 0 or more whitespace chars
		(?:			# begin first non-remembered grouping
		     (  		#   begin save buffer $1
			[^\w\s] 	#     one byte neither space nor word
			+ 		#     1 or more of such
		     )			#   end save buffer $1
		     ( \s* ) 		#   put 0 or more white in buffer $2
		     .* \n		# match through the end of first line
		 )			# end of first grouping
		 (?:			# begin second non-remembered grouping
		    \s *		#   0 or more whitespace chars
		    \1			#   whatever string is destined for $1
		    \2 ?		#   what'll be in $2, but optionally
		    .* \n 		#   match through the end of the line
		 ) +			# now repeat that group idea 1 or more
		 $			# until the end of the line
	      }x
	   )
	}
	    ($white, $leader) = ($2, quotemeta($1));
	} else {
	    ($white, $leader) = (/^(\s+)/, '');
	}
	s{
	     ^				# start of each line (due to /m)
	     \s *  			# any amount of leading white space
	        ?			#   but minimally matched
	     $leader			# our quoted, saved per-line leader
	     (?: 			# begin unremembered grouping
		$white			#    the same amount
	     ) ?			# optionalize in case EOL after leader
	}{}xgm;

There, wasn't that much easier to read?  Well, maybe not; sometimes it
doesn't help all to pepper your code with insipid comments that just
mirror the code.  This may be one of those cases.
-- 
Emacs is a fine programming language, but I still prefer perl. -me


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

Date: Sun, 4 Oct 1998 10:01:40 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: HERE Documents and skipping indentation (advanced)
Message-Id: <kk28v6.spb.ln@flash.net>

Jari Aalto+mail.perl (jari.aalto@poboxes.com) wrote:

: 	[CC is fine thank you]

: 	HERE docs require that you outdent all text, 
                  ^^^^^^^          ^^^^^^^^^^^^^^^^

   No they don't.

   You may _want_ to outdent (for readability perhaps?), but you 
   are not required to:

print <<EOF;   # works fine, screws up code indenting w/ indented print()...
this and that

this
and more on this
EOF


:       so I was hoping
: 	to use substitute operator to ignore the leading indentation.
: 	Would anyone know how to do that. 


$str =<<EOF;
         this and that

         this
         and more on this
EOF

$str =~ s/^[ \t]+//gm;   # using \s will delete "blank" lines...
print $str;





: print <<EOF =~ s/^\s+//;
:                     this and that

:                     this
:                     and more on this
:                     and more on this
:                     and more on this
: EOF

: Can't modify scalar in substitution at /users/jaalto/t.pl line 21, near "s/^\s+//;"


   Consider what you are asking perl to do here.

   What is the left side of the binding operator (=~) ?

   (That is, what string is to be tested against the pattern?)


   The return value from print().



   What is the return value from print()?

   'perlfunc' says it will return some TRUE value if it succeeds.


   So perl sees (assuming 1 for TRUE):

      1 =~ s/^\s+//;

   So even if perl could do a substitute on a _constant_, the
   s/// wouldn't be doing what you want it to do.



   But, you can use here-docs with assignment as well as with
   function calls, as above.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 30 Sep 1998 17:58:55 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: how can I build array of lists
Message-Id: <6utrgv$agl$1@marina.cinenet.net>

nfigaro@rocketmail.com wrote:
: I'd like to make an array of lists.
: ( or an array of arrays )

See the 'perllol' documentation for a whole bunch o' info on this.

: my $list1 = (a b c d);
: my $list2 = (1 2 3 4);

s/\$/\@/; s/\(/qw(/;

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: Sun, 04 Oct 1998 13:12:21 GMT
From: aali@ix.netcom.com (Abdul Ali)
Subject: How do you setup Win98 to run perl CGI scripts
Message-Id: <36177347.2831090@nntp.ix.netcom.com>

Hi everyone,

I am using Perl for Win32 on my Win98 PC at home. My PC is not a
server. Is it possible to set up my machine so that I could bring up
Netscape and have it recognize and run Perl CGI scripts?

Thanks,
Abdul


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

Date: Fri, 02 Oct 98 01:46:36 GMT
From: hans.xie@its.csiro.au (Hans Xie)
Subject: How to write a MS Excel file
Message-Id: <6v1b9s$p6_001@its.csiro.au>

Hi there,

Are there tools/packages can help me to output a file into MS Excel format?

Thanks a lot.
HB XIE


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

Date: Sun, 04 Oct 1998 16:36:35 GMT
From: sapper <xxx@xxx.xx>
Subject: i need a simple email parser
Message-Id: <36117FE3.6ECB94AF@linkline.be>

Hi there,

i always leave for several months all the emails on my pop3 account
but my provider as a bug in his pop3 server that causes the headers
of the emails to change slightly and then i receive several samples
of the same email ! (i log on my email server for 3 months normally
then i log in and i get 300 messages... that i already have !)

This problem happens either with Netscape under Linux or MSExplorer
under Windows and i know 100 % it is a bug from my provider.

Some headers change but the Message-ID: stays exactly the same so i
want to use perl to parse my 'Inbox' file (1700 emails, 6 Mb !) and
save each email to another file 'New_inbox' if they are not already
in this new file. Each nem message starts with a "From " header and
ends at the next "From " header or... at the end of the file.

I don't care if the process takes a long time (one day, i had to do
a kernel compilation on a 486 with 8 Mb of ram) i just want to know
the easiest way to do it !

It's trully sad but i don't know anything about perl, except that i
think that perl is the adequate tool... could anyone take 5 minutes
to write the little script i need to solve my problem ?

Thanks a lot !

 an happy Linuxer


P.S : excuse my 'french'




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

Date: Sun, 04 Oct 1998 16:41:10 GMT
From: mt@dev.null (Mads Toftum)
Subject: Re: i need a simple email parser
Message-Id: <361ba4ca.27063415@news.inet.tele.dk>

Check out the Mail::POP3Client module from CPAN - it works quite well
for connecting to POP3 servers.


vh.

Mads Toftum, (QDPH/JAPH)
---
A computer lets you make more mistakes faster than any other 
invention, with the possible exceptions of handguns and Tequilla.
        -- Mitch Ratcliffe


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

Date: 4 Oct 1998 13:34:26 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Is perl the correct choice for this problem?
Message-Id: <6v7q0i$3hg$1@gellyfish.btinternet.com>

On Sun, 04 Oct 1998 04:55:44 -0600 bholmes <bholmes@ipopros.com> wrote:
> Here is a sample of some data that I am faced with:

<snip>

> This data comes in plain txt files. I need to perform the following
> operations:

> Parse the data using the first column/string, saving only those lines
> where that string is one of a predetermind set of values, deleting all
> the other lines.

> Append a string to the beginning of the fourth column/string. This
> string is a constant, and is of the "http://somedomain/path/ flavor and
> will create a URL out of each string in the fourth column.

> I'm new to perl and would like some idea as to it's capabilities.

Infinite :-P

For example:

#!/usr/bin/perl

while(<DATA>)
{
   chomp;

   my ($field1,$field2,$field3,$field4) = split / +/;
   
   next unless($field1 eq '10-Q/A');

   $field4 = "http://somserver.com/files/" . $field4;
   
   printf("%-12s%-12s%-12s%-s\n",$field1,$field2,$field3,$field4);
}
__END__
10-Q        1059573     19981001    edgar/data/1059573/0000950152-98-007996.txt    
10-Q        1059575     19981001    edgar/data/1059575/0000950152-98-007996.txt    
10-Q        756767      19981001    edgar/data/756767/0000756767-98-000018.txt     
10-Q        804191      19981001    edgar/data/804191/0000804191-98-000011.txt     
10-Q/A      1027430     19981001    edgar/data/1027430/0000916641-98-001081.txt    
10-Q/A      315374      19981001    edgar/data/315374/0000315374-98-000008.txt     
10-Q/A      857855      19981001    edgar/data/857855/0000910195-98-000503.txt     
I have assumed here that you data is actually all on one line and the first
three columns are a width of 12.

In real life of course you would need to open external files for reading
and writing.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: 4 Oct 1998 19:13:13 GMT
From: jkekoni@cc.hut.fi (Joonas Timo Taavetti Kekoni)
Subject: Re: Multi-dimensional arrays
Message-Id: <6v8hc9$ds0$1@news.cs.hut.fi>

: I'm relatively new to perl and I'd like to know if it's possible to
: create multi-dimensional arrays......

#!/usr/bin/perl

use strict;
my @foo;

	for(my $t=0;$t<10;$t++)
	{	my @tmp;
		$foo[$t]=\@tmp;	
		for( my $r=0;$r<12;$r++) 
		{	${foo[$t]}->[$r]=$t."X".$r;
		}
	}

or easier, but less descriptive way:

use strict;
my @foo;

        for(my $t=0;$t<10;$t++)
        {      
                for( my $r=0;$r<12;$r++)
                {       $foo[$t][$r]=$t."X".$r;
                }
        }

man perldcs
 	
-- 
	_-  Joonas Kekoni       OH2MTF	    I                           -_
	_-internet:	jkekoni@cc.hut.fi   I       DO NOT EAT.         -_
	_-slowmail:	j{mer{ntaival 7a176 I                           -_
	_-		02150Espoo          I      It is a monitor      -_
	_-		Finland/Europe      I                           -_


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

Date: Sun, 04 Oct 1998 15:55:55 GMT
From: priyo@expert.cc.purdue.edu
Subject: Please help with simple perl script
Message-Id: <6v85qb$c33$1@nnrp1.dejanews.com>

Hi,

I've customized one of Matt's scripts which allows me to have an email
feedback form so that I can use it to do surveys. Of course, ideally, I
should be able to have the responses entered into a database. Unfortunately,
I still haven't been able to get that going. At this point, what I do is take
the email responses and process them using a Visual Basic script into an
Access database. The problem I have is this:

If a respondent doesn't answer a particular question (say question 4), the
(emailed) response file fails to leave a gap to indicate the missing response.
Instead, the reponses look like this:

Q1: 3

Q2: 4

Q3: 6

Q5: 4


The form can be found here: http://expert.cc.purdue.edu/~priyo/test.htm
The text of the perlscript is here:
http://expert.cc.purdue.edu/~priyo/kdsasurveyCGI.htm


I'd appreciate any help in this regard.

Thanks,

Priyo


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


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

Date: Sun, 04 Oct 1998 15:00:30 GMT
From: "Richard Ahier" <richarda@profil-cdi.qc.ca>
Subject: read subdirectories
Message-Id: <01bdefa7$ac6ddd20$231e67d1@richard>

Hi,

I try since a week to make a recursive script who read a directory and all
his subdirectories.
I just need directories not files.
Does somebody have a script to suggest.

Thanks in advance.






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

Date: 4 Oct 1998 16:00:59 GMT
From: doug@kittycat.france.seay (Douglas SEAY)
Subject: Re: read subdirectories
Message-Id: <slrn71f6ti.duc.doug@kittycat.france.seay>

[posted and CC'd]

On Sun, 04 Oct 1998 15:00:30 GMT, Richard Ahier
	 <richarda@profil-cdi.qc.ca> wrote:
>
>I try since a week to make a recursive script who read a directory and all
>his subdirectories.
>I just need directories not files.

If you are using Unix (you don't say) then the easiest way is
	`find $dir -type d -print`

For a bit more control, try running
	 "perldoc File::Find"

from the command line.

- doug


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

Date: Sun, 4 Oct 1998 10:16:29 -0400
From: steve.benjamin@juno.com (Stephen Benjamin)
Subject: Removing a line from a file
Message-Id: <19981004.101630.-956423.2.Steve.Benjamin@juno.com>

Hola!

I have an index file, $HOME/www/unrev/index.dat, which contains
a list of file names. Example:

589839786.dat
687348589.dat
482958293.dat
295893484.dat
385739933.dat

Let's say I'm done working with "295893484.dat". How would I remove
that line from the file so the file would now read:

589839786.dat
687348589.dat
482958293.dat
385739933.dat

Can someone help me? Please reply via e-mail.

Thanks in advance!

Stephen Benjamin
Steve.Benjamin@juno.com


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

Date: Wed, 30 Sep 1998 13:54:48 -0700
From: "V. M. Padua" <vincent@psnw.com>
Subject: Sending and receiving data to/from a weather server?
Message-Id: <36129A97.B346D3EB@csufresno.edu>

Disclaimer: Newbie

I'm working on a tcl/tk script that calculates the lunar phases of the
moon by calling a Perl script that will returns those answers.

I'd like to include in the interface of the program an option where the
user can select from about ten different airports/cities and when they
hit the calculate button to find the lunar phases it will return the
solutions as provided by the Perl script but will also find the current
temperature in the city the user had selected.

Now what I'm looking for are some pointers on how to query a weather
server with a selected city and return the current temperature in that
airport/city using Perl.  Now I'm not a Perl programmer (I didn't even
write the Perl script the program calls) and I've checked some of the
FAQ's and figured that I'd probably have to do something with CGI, but
I'm looking for an example or discussion regarding a similar problem.

I'm willing to submit the tcl/tk script and perl script if anyone would
like to take a look at those.

Thanks for any help and time,

 .mitch



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

Date: Sun, 04 Oct 1998 14:28:39 +0100
From: Matt Pryor <matt@whiterabbit.co.uk>
Subject: Survey Script
Message-Id: <36177807.4A98BC5E@whiterabbit.co.uk>

Firstly, in order to keep this message remotely on-topic, the script
discussed below is available for download after it has executed.

We're forming a new company (hooray!), and are a bit stuck for a name. 
I've come up with a few suggestions and am now conducting an online
survey for people's opinions and suggestions.

The intial form is displayed via a SSI which reads from the names
already suggested and gives the opportunity to vote for them.

The CGI program then does a simple tally for each vote, and displays the
results in a pleasing way.  A cookie is then stored to prevent duplicate
votes from the same user.

The form is here: http://www.whiterabbit.co.uk/survey.shtml

Please give it a whirl.

Thanks,

Matt
--


-- 
Matt's daily comic strip
Porridge and Fartcakes
http://www.whiterabbit.co.uk/cartoons


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

Date: Sun, 4 Oct 1998 09:17:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Survey Script
Message-Id: <MPG.10813f7dd34bc73d98989b@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <36177807.4A98BC5E@whiterabbit.co.uk> on Sun, 04 Oct 1998 
14:28:39 +0100, Matt Pryor <matt@whiterabbit.co.uk> says...
 ...
> The CGI program then does a simple tally for each vote, and displays the
> results in a pleasing way.  A cookie is then stored to prevent duplicate
> votes from the same user.
> 
> The form is here: http://www.whiterabbit.co.uk/survey.shtml

How about also posting the URL of the CGI program, or put the URL on the 
HTML page, so anyone interested can learn from it?

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


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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