[16244] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3656 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 13 18:10:47 2000

Date: Thu, 13 Jul 2000 15:10:32 -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: <963526231-v9-i3656@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 13 Jul 2000     Volume: 9 Number: 3656

Today's topics:
    Re: Does fork() work on NT? (Clinton A. Pierce)
    Re: Email Attachments in Perl (no modules) <dwoods@ucalgary.ca>
        filehandle <nair@ee.tamu.edu>
    Re: filehandle (Tad McClellan)
    Re: filehandle <marc.schaefer@warwick.ac.uk>
    Re: FormMail.pl across mutiple pages (Malcolm Dew-Jones)
    Re: From Dropdown to Variable - How To? (Mads Orbesen Troest)
    Re: good free guestbook scripts needed... (NP)
    Re: Hash reverse lookups? <bcaligari@shipreg.com>
    Re: Hash reverse lookups? <juex@deja.com>
    Re: Hash reverse lookups? jdaves@gilanet.com
    Re: Help with file concatination my_deja_v@my-deja.com
    Re: Help, no cgi push! what else is there? (Malcolm Dew-Jones)
    Re: Help, no cgi push! what else is there? richardstands@my-deja.com
    Re: Help, no cgi push! what else is there? richardstands@my-deja.com
    Re: Help, no cgi push! what else is there? <bart.lateur@skynet.be>
    Re: HELP: Bizarre BEGIN block problem <ed@nospam.com>
    Re: HELP: Bizarre BEGIN block problem <sariq@texas.net>
        Is there a limit for form of the number of input fields <amy@wirespeed.com>
    Re: looking for ntp example please (Brandon Metcalf)
        Modules/scripts for EDI processing <rpwt@frexi.net-nospam>
        multiline reqexp question <vibrato@my-deja.com>
    Re: multiline reqexp question (Tad McClellan)
    Re: multiline reqexp question <marc.schaefer@warwick.ac.uk>
    Re: New to perl, need help <nospam@nospam.com>
    Re: New to perl, need help <uri@sysarch.com>
    Re: New to perl, need help (Andrew Johnson)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 13 Jul 2000 21:13:35 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Does fork() work on NT?
Message-Id: <3iqb5.35519$fR2.325812@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <396D7D28.23739FE2@ccf.auth.gr>,
	Vlasis Hatzistavrou <vhatz@ccf.auth.gr> writes:
> I even just tried
> 
> unless ($pid=fork){
> 
>   unless (fork)   {
>    print "\nProgram1 started<br>\n";
> exec ("perl Program1.pl $arg1 $arg2 $arg3 $arg4");
>    exit 0;
>     }
>   exit 0;
>  }
>  waitpid($pid,0);

Two forks?  Why?  (untested)

	$pid=fork();
	die "Fork failed!" if (! defined $pid);
	if ($pid) {   # parent
		waitpid($pid,0)
	} else {
		exec("perl program1.pl $arg");
		die "exec failed: $!";
	}

What's wrong with that?


> Does anyone know how to fork() on NT? I've been trying to do it for over
> 2 weeks now having tried different approaches and it's becoming really
> frustrating.

Yeah, it can be.  And you're doing this on a Windows platform which doesn't
make things easier.  I've had stuff like:

	open(F, "foo|") || die;
	while(<F>) {
		# process $_
	}

Hang sometimes under NT, and work sometimes under NT.  It depends on 
what the program foo is, and the mood that NT happens to be in that day.
And yet:

	@blah=`foo`;

Works perfectly, every time.  Multiprocessing and IPC are not fun on 
Windows systems.

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 13 Jul 2000 14:32:52 -0600
From: Dan Woods <dwoods@ucalgary.ca>
Subject: Re: Email Attachments in Perl (no modules)
Message-Id: <396E2774.9AD54F38@ucalgary.ca>

eryq@zeegee.com wrote:
> 
> In article <F4A464A67567D311AAF400C04F2A2CC6020F4E5B@grp-nt4.segin.com>,
>   Dubreu Mathieu <mdubreu@atos-group.com> wrote:
> > Is there any way to attach a file to a mail only with the SMTP package
> ?
> > I have encoded a file in Base64, but the SMTP package put the file in
> > the body of my mail.
> 
> You're just making life hard for yourself that way.
> Use MIME::Lite to prepare the message; that's what it does well.
> Then use Net::SMTP to send the message; that's what *it* does well.
> :-)
> 
> MIME::Lite already has a hook in it to send_by_smtp(), using
> Net::SMTP, by the way.  You can look at the code to see how I
> do it and then implement something similar, or (if your
> email addresses fit the description in the documentation)
> you can use send_by_smtp() directly.
> 
> See documentation at: http://www.zeegee.com/code/perl/MIME-Lite
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.

But what is the best way to attach files (text or binary) if you are
not allowed to install Perl modules ?  There are lots of people using
hosting companies that either don't allow, or don't want to install
modules.
Where's a good example of attaching files to an email using the
standard sendmail ?  I know that sendmail has no 'Attach:' like
blat and windmail on NT (I hate NT), so I am sure that you need to
create a Content-type: multi-part/xxx and do it that way. I would
like to see a good howto or examples on how to do this right.

Thanks...Dan.


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

Date: Thu, 13 Jul 2000 13:31:40 -0500
From: Umesh <nair@ee.tamu.edu>
Subject: filehandle
Message-Id: <Pine.GSO.4.21.0007131329420.13659-100000@eesun1.tamu.edu>


hi,

Is it possible to get the filename by knowing only the filehandle ?
i.e the filehandle is passed to a subroutine (as a typeglob or object from
FileHandle), and i need to say print the name of file from within
subroutine?


thanks,
-umesh




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

Date: Thu, 13 Jul 2000 14:29:08 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: filehandle
Message-Id: <slrn8ms2jk.bhi.tadmc@magna.metronet.com>

On Thu, 13 Jul 2000 13:31:40 -0500, Umesh <nair@ee.tamu.edu> wrote:


>Is it possible to get the filename by knowing only the filehandle ?


Not in general. Because there may not _be_ a filename associated
with a filehandle:

   open(LS, 'ls |') or die...

What filename should go with LS?


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


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

Date: 13 Jul 2000 20:57:15 +0200
From: Marc Schaefer <marc.schaefer@warwick.ac.uk>
Subject: Re: filehandle
Message-Id: <m3r98xkgdw.fsf@mapgw.csv.warwick.ac.uk>

Hi Umesh,

Umesh <nair@ee.tamu.edu> writes:

> Is it possible to get the filename by knowing only the filehandle ?

How do you know that there actually is a filename? Your filehandle
could be a pipe, or a socket. If you open a file under Unix and then
unlink it, the file still is readable/writable, but it has no name any
more (this is often used for temporary files). Or there could be hard
links to it, i.e. the file has many names.

So you will have to keep track of the filenames yourself.

Best,

Marc



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

Date: 13 Jul 2000 11:09:34 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: FormMail.pl across mutiple pages
Message-Id: <396e05de@news.victoria.tc.ca>

Andy Barlow (andybarlow70NOanSPAM@hotmail.com.invalid) wrote:
: We are using FormMail.pl

Please be careful.

For example Joe hacker could use your installed copy of FormMail to send
hate mail to someone. That someone will see that the mail come from you,
(not the hacker). 

It can also send various bits of data back to Mr. joe Hacker that may
assist them in breaking into your server.



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

Date: Thu, 13 Jul 2000 19:44:42 GMT
From: mads@troest.NEVERMORE.dk (Mads Orbesen Troest)
Subject: Re: From Dropdown to Variable - How To?
Message-Id: <k6fk2tedC4v7-pn2-pQFGqDfLv063@mads.lokal.net>

On Thu, 13 Jul 2000 17:04:35, mandbinc@rocketmail.com wrote:

> On this SAME page there is a dropdown box where users can select
> different text options.  I want to take the value they select and move
> it to some TEXT on a different part of the SAME HTML page (take it to
> the place where $help is).

Unless it is acceptable that the page reloads when you select an 
option, this is not really the best situation to use Perl, IMO. In 
fact, you can't even call the perl script automatically without 
javascript (would require clicking a submit-button), so perhaps you 
should consider using pure javascript.

> How do I then return that value (now assigned to $help) to the $help
> variable in the TEXT on the SAME HTML page (with the SAME HTML file
> name)?

Assuming you get your script called with the value from the select 
pass in as a CGI parameter, you "merely" process the original HTML 
file, interpolating the variables you want replaced, outputting the 
altered page to stdout. I say "merely" because whereas it's relatively
easy to do (I've written a module performing such interpolations, as 
they are indeed often used in larger, comlex CGI applications), it 
seems a lot of work for a simple application like this, which would, 
at any rate, be more user friendly if the page doesn't have to exit to
a perl-script and reload a new version of the page. Hence:

> Or if someone has a suggestion on an easier way to do this, please let
> me know.

Well, the most obvious way if you want to avoid reloading and is OK 
with javascript is the totally dynamic version (requiring no Perl, so 
I hope ppl will bear with 10 lines off topic):

<form name=3DMyForm>
<select name=3DMyList onChange=3D"javascript:
 document.MyForm.MyField.value =3D document.MyForm.MyList.options[ 
document.MyForm.MyList.selectedIndex ].text;
">
<option>First option</option>
<option>Second option</option>
<option>Third option</option>
</select><P>
<input type=3Dtext name=3DMyField>
</form>

This should do what you want. Hope this helps. :-)

      ... /\/\\ads Orbesen Troest <mads@troest.NEVERMORE.dk>


(Please remove NEVERMORE from address when replying via email...)


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

Date: Thu, 13 Jul 2000 18:06:04 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: good free guestbook scripts needed...
Message-Id: <gynb5.309791$MB.5181742@news6.giganews.com>

On Thu, 13 Jul 2000 18:07:14 +0200, Bart Lateur <bart.lateur@skynet.be> wrote:
: kie wrote:
: 
: >both must look like they have not been given for free
: 
: But it must be free, nevertheless? Gee...

ROTFL.  "Ganesha" seems to like Matt's Scripts but I wouldn't advise
using them.  Let me rephrase that: no sane person would advise using
them.  Not to make anybody feel bad but his scripts just aren't that
good.  :-)

Anyways, this really isn't a Perl question (meaning: it's not specific
to the Perl language since you can write a guestbook in ANY language)
but I'd start out by searching Google (www.google.com) for "guestbook"
and "Perl".

-- 
Nate II



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

Date: Thu, 13 Jul 2000 20:14:09 +0200
From: "Brendon Caligari" <bcaligari@shipreg.com>
Subject: Re: Hash reverse lookups?
Message-Id: <8kl0a3$bod$1@news.news-service.com>


<jdaves@gilanet.com> wrote in message news:8kksme$mlc$1@nnrp1.deja.com...
> Hi, all. Is there an easy & elegent way to do reverse hash lookups, ie,
> I want to know the key associated to a given value? What I'm doing now
> is something like this:
>
> %zips = ('87110','city1','87131','city2','88123','city3');
>
> # Give the city with a given zip code
> $zip_code = 87131;
> $this_city = $zips{$zip_code};
>
> # Give the zip code for a given city
> foreach (keys %zips) {
>   if ($this_city = $zips{$_} ) {
>      $zip_code = $_;
>      last;
>   }
> }
>
> I'm sure there's gotta be a better way, but I've not found it in any of
> the faqs or docs that I have.
>
> Thanks. . .
try something like:

while (($key, $value) = each (%zips)) {
 if ($thiscity eq $value) {
  $thiscode = $key;
  last();
 }
}

remember that in perl the comparison operators for strings are
different than those for integers.
 ....like == becomes eq, > becomes gt...etc
B




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

Date: Thu, 13 Jul 2000 11:18:50 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Hash reverse lookups?
Message-Id: <396e080a$1@news.microsoft.com>

"Cameron Kennedy" <kenned57@pilot.msu.edu> wrote in message
news:kenned57-1307001033100001@alexthinkpad.salk.edu...
> In article <8kksme$mlc$1@nnrp1.deja.com>, jdaves@gilanet.com wrote:
>
> > Hi, all. Is there an easy & elegent way to do reverse hash lookups, ie,
> > I want to know the key associated to a given value?
> %b=reverse %a;
> keys for %a are now values for %b.

However keep in mind that if %a contained multiple entries with the same
value, then only one of them will be present in %b.

jue




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

Date: Thu, 13 Jul 2000 18:20:54 GMT
From: jdaves@gilanet.com
Subject: Re: Hash reverse lookups?
Message-Id: <8kl19g$qh1$1@nnrp1.deja.com>

In article <kenned57-1307001033100001@alexthinkpad.salk.edu>,
  kenned57@pilot.msu.edu (Cameron Kennedy) wrote:
> In article <8kksme$mlc$1@nnrp1.deja.com>, jdaves@gilanet.com wrote:
>
> > Hi, all. Is there an easy & elegent way to do reverse hash lookups,
ie,
> > I want to know the key associated to a given value?
>
> %b=reverse %a;
> keys for %a are now values for %b.
>
> Cameron
>

Dam', right there in the man page! Thanks. . .


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


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

Date: Thu, 13 Jul 2000 21:10:44 GMT
From: my_deja_v@my-deja.com
Subject: Re: Help with file concatination
Message-Id: <8klb84$2p6$1@nnrp1.deja.com>

Using print OTHERFILE $_ does not work correctly.
If I use cat then the files remain with the same
formating (or lack of) while print in Perl
formats them and when we send them to the mainframe
they appear as formatted files..

Any other ideas?

Thanks

In article <3969EACD.E2801EC9@attglobal.net>,
  Drew Simonis <care227@attglobal.net> wrote:
> my_deja_v@my-deja.com wrote:
> >
> > I have a flat file which I read into an array and then using some
logic
> > I want to concatinate some files.
> >
> > I can't find anything comparable in Perl to the unix cat command.
> > These files are father big and I don't want to read them and then
write
> > them...
> >
>
> Father big?  heh.
>
> open SOMEFILE, "</path/to/file" or die "Can't read file: $!";
> open OTHERFILE, ">>/path/to/file" or die "Can't append to file: $!";
>
> while (<SOMEFILE>)
> {
> 	print OTHERFILE $_;
> }
>
> Just like shell redirection... > writes, >> appends.
>
> Joining two strings uses either the join() function or the dot (.)
> operator.  Or some ohter fancy ways, but for now, "." is the easiest.
>
> Read the perlop documentation for ways of using . and = (assignment)
> to concat strings.
>


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


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

Date: 13 Jul 2000 11:17:57 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Help, no cgi push! what else is there?
Message-Id: <396e07d5@news.victoria.tc.ca>

richardstands@my-deja.com wrote:
: Thanks for your post! :o)

: I guess I need to explain myself a little further. I am already using
: the "meta" tag with the refresh option but I am not able to return that
: page to the user as the script won't return at all until it has
: completed which, as I mentioned, could be up to an hour(waiting for the
: sub that creates all the output). The browser will surely timeout
: before this. What I need is for the main script call to spawn a

Can't your script send the page first and then do the long work?

First time, send a page then do long work.

Next time(s), re-send refresh page, somehow detect the first process is
still running so quit. 

Eventually the script gets a request for the refresh page and detects that
the original script has finished, so send the data instead of the
refreshing page.



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

Date: Thu, 13 Jul 2000 20:11:42 GMT
From: richardstands@my-deja.com
Subject: Re: Help, no cgi push! what else is there?
Message-Id: <8kl7pd$vvb$1@nnrp1.deja.com>

In article <396e07d5@news.victoria.tc.ca>,
  yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote:
> richardstands@my-deja.com wrote:
> : Thanks for your post! :o)
>
> : I guess I need to explain myself a little further. I am already
using
> : the "meta" tag with the refresh option but I am not able to return
that
> : page to the user as the script won't return at all until it has
> : completed which, as I mentioned, could be up to an hour(waiting for
the
> : sub that creates all the output). The browser will surely timeout
> : before this. What I need is for the main script call to spawn a
>
> Can't your script send the page first and then do the long work?
>
Well, no as the browser won't display the page(and stop the hourgalss
cursor) until the script exits.

> First time, send a page then do long work.
>
> Next time(s), re-send refresh page, somehow detect the first process
is
> still running so quit.
>
What you seem to be suggesting is multiple processes which is exactly
what was needed. I just had forgotten about the system() function and
whether is would work the way I needed under IIS(it does and my problem
has been solved!).

> Eventually the script gets a request for the refresh page and detects
that
> the original script has finished, so send the data instead of the
> refreshing page.
>
>
Yes, I did finally do something like this and it seems to work great.
Thanks for your post to my problem. Cheers.

-Rich


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


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

Date: Thu, 13 Jul 2000 20:47:19 GMT
From: richardstands@my-deja.com
Subject: Re: Help, no cgi push! what else is there?
Message-Id: <8kl9sh$1o0$1@nnrp1.deja.com>

In article <slrn8mrmh0.cam.will@mylanders.com>,
  will@mylanders.com (Will England) wrote:
> On Wed, 12 Jul 2000 23:54:38 GMT, richardstands@my-deja.com
> <richardstands@my-deja.com> wrote:
>
> <snip wants to progressively display information as
> a process runs>
>
> You could look at NPH (non-parsed headers) CGI.
>
> http://stein.cshl.org/WWW/CGI/#nph
>
> I'm not familair with IE not accepting server push,
> but if the browser works at say, spamcop.net then this
> will work.
>
> You may want to create an account at spamcop.net and
> see how their system works using NPH.  The lookup
> processes can take quite a few seconds to complete.
>
> HTH
>
> Will
>
Will,

Thanks for pointing this site/example out to me. I went there and tried
their test page with a spam I had gotten. Then I peered into their
code. As I suspected they are using javascript as a way to do a
countdown until they are ready to show you the results of the parsing
of your spam. It isn't quite what I was hoping but here is how I think
they are doing it.

The first submit/call to the script(with my spam) forks into:

1. a process that returns the html document with the javascript
countdown(this number might be determined by, at least, the lenght of
the spam - in other words, it's a guess as to how long it might take to
finish the parsing, no more);

2. a process that does the actual parsing and, likely, puts the results
into a temporary file named using the temporary ID value that is
embedded as hidden data within the page returned by #1.

When the initial page itself is "submitted" to the server, it uses this
ID to find the correct results file, returns the contents to you, and
then likely deletes same. Very elegant solution, but it still uses some
type of forking as opposed to true client push(which, I'm pretty
certain after all my searching, is something only supported by
Netscape - please correct me if I am still wrong :o).

Thankfully, another user reminded me about the Perl system() function
which, with some more tweaking and testing and IIS, I was able to get
working the way I wanted - problem solved. Thanks again.

-Rich


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


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

Date: Thu, 13 Jul 2000 23:01:15 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help, no cgi push! what else is there?
Message-Id: <sebsms0liknlis8to091uqm2626td9mhkq@4ax.com>

richardstands@my-deja.com wrote:

>it turns out that Apache server makes the first
>script call wait until the "child" script returns before returning
>itself which has been my problem all along. However, Microsoft IIS
>*will* return immediately after spawning the "child" script using sytem
>() so my problem is solved! Yay!!! and thanks.

You could try exec() instead. It should behave better. Note that you
must have finished printing the first page before calling it.

-- 
	Bart.


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

Date: Thu, 13 Jul 2000 18:15:07 GMT
From: "Ed Foy" <ed@nospam.com>
Subject: Re: HELP: Bizarre BEGIN block problem
Message-Id: <LGnb5.63032$_b3.1836561@newsread1.prod.itd.earthlink.net>


Francis Litterio wrote in message ...
>> For some reason the "Content-type: text/html\n\n" is a problem.
>
>Well, the above script runs fine for me in Perl 5.005_03.  But if I
>purposely insert a syntax error at the very bottom of the script (i.e.,
I
>change "exit;" to ",exit;"), I get:
>
> syntax error at ./zzz line 11, near ","
> Execution of ./zzz aborted due to compilation errors.
> Content-type: text/html
>
>The "Content-type: text/html" appears because BEGIN blocks execute at
>compile-time not at run time, so the code in them runs even if your
>script has syntax errors that prevent the script from starting.


Thank you. You have confirmed what I was suspecting which is that this
is a bug in 5.004. When I compile on 5.004 I get the syntax error
warning but it is not fatal and my code executes as would be expected
from the code - that is, STDERR is redirected and anything sent to
STDERR can be viewed in an HTML browser.

I guess the task is to find some list of Perl 5.004 bugs to find out
what the implications and extent of this bug are.

Thanks again!

Ed




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

Date: Thu, 13 Jul 2000 13:22:00 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: HELP: Bizarre BEGIN block problem
Message-Id: <396E08C8.B1DE4817@texas.net>

[ comp.lang.perl was officially removed from Usenet *years* ago. ]

Ed Foy wrote:
> 
> First, my environment is Perl 5.004 under UNIX. I cannot compile my
> scripts locally, but my ISP provides a remotely accessible compiler and
> Perl debugger.

That's where the error message is coming from, and that's where the bug
is.

> I've reduced the code to the following (verbatim) to demonstrate the
> problem:
> 
> #!/usr/local/bin/perl5
> 
> require 5.004;
> 
> BEGIN {
>     print "Content-type: text/html\n\n";
>     open (STDERR, ">&STDOUT") or die "Cannot Redirect STDERR: $!";
> }
> 
> my $Dummy = "";
> exit;
> 
> The above code results in the following error message on compilation:
> 
> TEST.PL contains syntax errors.

That didn't come from Perl (see perldiag for all of Perl's diagnostic
messages).

Your example runs just fine under real Perl 5.004_04 on Linux.

- Tom


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

Date: Thu, 13 Jul 2000 16:13:44 -0500
From: "Amy" <amy@wirespeed.com>
Subject: Is there a limit for form of the number of input fields?
Message-Id: <smsc3dp7nd6128@corp.supernews.com>

I am using Perl to write a webpage and let the user to enter information for
many topics, each topic has 8 input fields.  I gradually increased the
number of topics all the way to 7, they all works fine after I submitted and
the data were saved.  but when I used 8 or larger number, the next page
after the submitted button totally blank.

I wonder, is there a limit for form of the # of input fields? Can somebody
tell me about this?  If there isn't one, I guess I have to find out why this
happens to me.

Thanks!

Amy!






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

Date: 13 Jul 2000 19:50:09 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: looking for ntp example please
Message-Id: <8kl6hh$i6p$1@bcrkh13.ca.nortel.com>

will@mylanders.com writes:

 > On Thu, 13 Jul 2000 13:32:59 +1000, Robert Chalmers 
 > <robert@chalmers.com.au> wrote:
 > >I'm looking for examples of using ntp to fetch the time from servers. Or
 > >indeed is this possible?
 > 
 > 1) yes.
 > 
 > 2) comp.protocols.ntp is --> that-a-way.

[snip]

 > Once you get things figured out, post back with samples.  I
 > bet more that just you have wondered about this.

Interesting.  You tell Robert to go to another newsgroup, but then turn
around and tell him to post examples in c.l.p.m once he has it figured
out.

Lame.

Brandon


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

Date: Thu, 13 Jul 2000 14:34:31 -0400
From: "Roger Tubby" <rpwt@frexi.net-nospam>
Subject: Modules/scripts for EDI processing
Message-Id: <0Znb5.168$gv6.116484@news.abs.net>

It seems unbelievable that I cannot locate any modules or scripts that
handle EDI messages.  I am specifically looking for the capability to read
ANSI X12 headers (ISA's), catalogs (832), and other message formats.

I am aware of the XML/EDI work ongoing (XML-Edifact) and plan to convert to
XML over time.






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

Date: Thu, 13 Jul 2000 18:03:56 GMT
From: Lance Hoffmeyer <vibrato@my-deja.com>
Subject: multiline reqexp question
Message-Id: <8kl09u$pjm$1@nnrp1.deja.com>

I wish to remove some multiline text from a file.

MACRO
text
text
text
ENDMACRO

Basically, I want to remove MACRO, ENDMACRO, and everything in between.

s/MACRO.*ENDMACRO//s

does not work. The /s should allow . to handle newline characters.  What
am I missing here?  What would make this work?

Thanks,

Lance


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


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

Date: Thu, 13 Jul 2000 14:36:35 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: multiline reqexp question
Message-Id: <slrn8ms31j.bhi.tadmc@magna.metronet.com>

On Thu, 13 Jul 2000 18:03:56 GMT, Lance Hoffmeyer <vibrato@my-deja.com> wrote:
>I wish to remove some multiline text from a file.
>
>MACRO
>text
>text
>text
>ENDMACRO
>
>Basically, I want to remove MACRO, ENDMACRO, and everything in between.
>
>s/MACRO.*ENDMACRO//s
>
>does not work. 
 ^^^^^^^^^^^^^

What indicated it's "doesn't workness"?




>The /s should allow . to handle newline characters.  What
>am I missing here?  


Do you _have_ multiple lines in $_ ?



> What would make this work?


It works for me:

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

$_ = 'stuff before
MACRO
text
text
text
ENDMACRO
stuff after
';

s/MACRO.*ENDMACRO//s;

print;
---------------------------------


You probably want .*? instead of .* too.

You might also want to remove the newline following the ENDMACRO.


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


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

Date: 13 Jul 2000 20:46:03 +0200
From: Marc Schaefer <marc.schaefer@warwick.ac.uk>
Subject: Re: multiline reqexp question
Message-Id: <m3u2dtkgwk.fsf@mapgw.csv.warwick.ac.uk>

Hi Lance,

Lance Hoffmeyer <vibrato@my-deja.com> writes:

> s/MACRO.*ENDMACRO//s
> 
> does not work. 

Well, this works for me:

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

	# Slurp _entire file_ into one scalar
	$_ = do {local $/; <DATA>};

	# Delete _first_ occurance of MACRO ... ENDMACRO
	s/MACRO.*ENDMACRO//s;

	# Output is
	#	blabla
	#
	#	blabla
	print;

	__DATA__
	blabla
	MACRO
	text
	text
	text
	ENDMACRO
	blabla

> What am I missing here?  What would make this work?

The problem is probably in the part of your program that you don't
show us. If you read your file line by line, like in

	while (<DATA>) {
	    s/MACRO.*ENDMACRO//s;
	    print;
	}

you apply the substitution to every line individually - but there is
no line which contains both 'MACRO' and 'ENDMACRO'.

You could apply the substitution to the whole file in one go as I did
in the example above, but then you probably want to use the /g
modifier on your regexp to kill _all_ occurrences of your pattern. The
other solution is processing the file line by line, but using the '..'
operator from perlop:

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

	while (<DATA>) {
	    print unless /^MACRO/../^ENDMACRO/;
	}

	__DATA__
	blabla
	MACRO
	text
	text
	text
	ENDMACRO
	blabla
 
or shorter

	perl -ne 'print unless /^MACRO/../^ENDMACRO/'

HTH

Best,

Marc



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

Date: 13 Jul 2000 19:17:56 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: New to perl, need help
Message-Id: <8kl4l4$5j8$0@216.155.33.87>

In article <8kkpl3$m27$1@junior.statsci.com>, snow@statsci.com (Greg 
Snow) wrote:

 | If your going for speed, then the following probably deserves

You know enough to do the below, but put "your" instead of "you're" ? 
<grin> <duck>

 | consideration:
 |

altered slightly:
 
 | #!/usr/bin/perl -w 
 | use strict;
 | # see http://ulcar.uml.edu/~iag/CS/Fibonacci.html 
 | use constant PHI  => (1+sqrt(5))/2;
 | use constant PHIH => 1-(PHI);
 | use constant MULT => 1/sqrt(5);
 | 
 | sub fib {
 |   sprintf "%.0f", MULT * ( PHI**$_[0] - PHIH**$_[0]);
 | }
 | 
 | for (0..140) {
 |   print fib($_),"\n";
 |   print "\n" if !($_%4);
 | }

verrrrrrrry interesting (as was the web article mentioned) -- it's quite 
fast, appears to use little memory, and retains precision without going 
into the 1.0e+x notation (I forget, is that called 'exponential 
notation'?)

well, there's definitely MTOWTDI here <hee hee>, and it's interesting to 
note there's more than one way to SOLVE it too. 

I do however remain impressed with the precision and speed of this 
puppy. nice job. Guess it really DOES pay to study math. :>

-- 
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: Thu, 13 Jul 2000 20:18:05 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: New to perl, need help
Message-Id: <x7bt01kcn8.fsf@home.sysarch.com>

>>>>> "TW" == The WebDragon <nospam@nospam.com> writes:

  TW> In article <8kkpl3$m27$1@junior.statsci.com>, snow@statsci.com (Greg 
  TW> Snow) wrote:

  TW>  | If your going for speed, then the following probably deserves
  TW>  | consideration:

  TW>  | sub fib {
  TW>  |   sprintf "%.0f", MULT * ( PHI**$_[0] - PHIH**$_[0]);
  TW>  | }

  TW> I do however remain impressed with the precision and speed of this 
  TW> puppy. nice job. Guess it really DOES pay to study math. :>

it is well known that the ratios of adjacent pairs of fib numbers,
approaches the golden ratio. so that algorithm just does the opposite
and generates the ratios and converts it back to integers. no looping or
ram is needed as all the work is in floating point.

uri

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


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

Date: Thu, 13 Jul 2000 21:02:08 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: New to perl, need help
Message-Id: <k7qb5.7916$k5.97700@news1.rdc1.mb.home.com>

In article <8kkpl3$m27$1@junior.statsci.com>,
 Greg Snow <snow@statsci.com> wrote:
[snip] 
> If your going for speed, then the following probably deserves
> consideration:

Of course, if you are really going for speed it seems you can gain a
little by using lexicals rather than constants -- and of course,
using sprintf() takes a little more time as well.

If we are talking about printing out all the series up to the Nth
number then the following closure based stream is a bit faster (or
about the same if you use printf() instead of print()) -- but if you
just want to calculate the Nth number then obviously any method which
has to calculate them all is going to suffer in comparison to
Greg's more direct method.

#!/usr/bin/perl -w
use strict;
sub new_fib_stream {
    my ($current, $next) = (0, 1);
    return sub{
                  my $fib = $current;
                  ($current, $next) = ($next, $current + $next);
                  return $fib;
               };
}

my $fib_stream = new_fib_stream();
my $fibo;
foreach (1..100) {
    print $fib_stream->(),"\n";
}
__END__

Just another variation on the theme.

andrew

-- 
Andrew L. Johnson   http://members.home.net/perl-epwp/
      Doing linear scans over an associative array is like 
      trying to club someone to death with a loaded Uzi.
          -- Larry Wall
      


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

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


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