[16391] in Perl-Users-Digest
Perl-Users Digest, Issue: 3803 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 25 21:05:21 2000
Date: Tue, 25 Jul 2000 18:05:10 -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: <964573509-v9-i3803@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 25 Jul 2000 Volume: 9 Number: 3803
Today's topics:
Re: <newbie> Html Tag generation <wmonk@documentsolutions.com>
Re: <newbie> Html Tag generation <Jeremiah.Megie@emich.edu>
Re: <newbie> Html Tag generation <sumus@aut.dk>
Re: <newbie> Html Tag generation <Jeremiah.Megie@emich.edu>
CGI->new(*FORM) Problem... <zampino@squidco.com>
Re: cookie and redirect trouble... <flavell@mail.cern.ch>
Custom mail headers with perl <jason@mybowie.com>
DB File Question <scrampton71NOscSPAM@hotmail.com.invalid>
Re: DB File Question (Logan Shaw)
Gtk-Perl on Win32? <memmett@fraser.sfu.ca>
Re: how do you ? question (Logan Shaw)
Re: how do you ? question <flavell@mail.cern.ch>
No Data from Database <mwatters@cobaltgroup.com>
Re: perl as part of unix distribution (Gwyn Judd)
Re: perl v. tcl <pmtutko@worldnet.att.net>
Re: perl-5.6.0: Bug with "not" operator? ()
Re: READING hashes eats memory!? (Abigail)
Record length my_deja_v@my-deja.com
trapping INT signal on system call michaelgartlan@my-deja.com
Re: USEing a perl module (Tad McClellan)
Re: Was Why won't "use strict;" work? <whataman@home.com>
Re: Was Why won't "use strict;" work? (Abigail)
Re: Was Why won't "use strict;" work? <lr@hpl.hp.com>
Re: When to use for and foreach? (Reini Urban)
Re: When to use for and foreach? (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Jul 2000 15:39:53 -0700
From: "Monk" <wmonk@documentsolutions.com>
Subject: Re: <newbie> Html Tag generation
Message-Id: <sns5ntuc3j146@corp.supernews.com>
"Jeremiah Megie" <jeremiah@klondyke.net> wrote in message
news:397E0908.3ED825B7@emich.edu...
> I have written a script that will allow a user to post announcements to
> a webpage. They fill out the form, hit submit, and it puts the contents
> into the page. It works perfect, except one thing. When you type your
> announcement in the textarea box, it doesn't let you use html tags, so
> when you type and submit the form, everything is on one line and nothing
> can be seperated out. I want to be able to have the users type in their
> announcement and have it automatically put in <p> tags, and <a href>
> tags, upon them putting in a link or a new paragraph. Is there a way
> that I can do this? I can't seem to figure it out.
>
>
> Jeremiah
>
Can you provide the script that is doing this for you? Is a database
involved? Text file? Need more specifics.
wes
------------------------------
Date: Tue, 25 Jul 2000 18:53:44 -0400
From: Jeremiah Megie <Jeremiah.Megie@emich.edu>
Subject: Re: <newbie> Html Tag generation
Message-Id: <397E1A78.9B03AB4D@emich.edu>
Remember, I am kinda a newbie...I can edit perl files and such, but this is
really the first program I have sat down and written, so it is probably more
bulky than it needs to be. There are no databases, the script just writes to
the html directory:
#!/usr/bin/perl
# Define some common variables
$path = "/home/httpd/html/resnet/announce.shtml";
$usename = 1;
$useemail = 1;
# Set Date
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime
(time);
$year = 1900 + $year;
$monthday = $mday + 0;
@Days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday");
@month = ("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
$DayOfWeek = $Days[$wday];
$Month = $month[$mon];
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<([^>]|\n)*>//g;
$value =~ s/<//g;
$value =~ s/>//g;
$FORM{$name} = $value;
}
print "Content-type: text/html\n\n";
# Print error page if a field is empty
if ($usename) {
unless ($FORM{'name'}) {
print "<html><head><title>Please enter your
name.</title></head>\n";
print "<body><h1>Name required</h1>Please click back and
enter\n";
print "your name.\n";
}
}
unless ($FORM{'announce'}) {
print "<html><head><title>You forgot something.</title></head>\n";
print "<body><h1>Please Type your announcement</h1>You're trying
to\n";
print "Post an announcement. You can't do that unless you write\n";
print "something.\n";
}
# Link the name and email
if ($FORM{'email'} && $FORM{'name'}) { $poster = "<a
href=\"mailto:$FORM{'email'}\">$FORM{'name'}</a>"; }
elsif ($FORM{'name'}) { $poster = "$FORM{'name'}"; }
elsif ($FORM{'email'}) { $poster = "<a
href=\"mailto:$FORM{'email'}\">$FORM{'email'}</a>"; }
else { $poster = "anonymous"; }
# Write the announcement to the announcement page
open(FILE,"$path");
@lines = <FILE>;
close(FILE);
open(FILE,">$path");
foreach $line(@lines) {
if (substr($line,0,10) eq "<!--add-->") {
print FILE "<br>\n";
print FILE "<table width='85%' border='0' cellspacing='0'
cellpadding='0' align='center'>\n";
print FILE "<tr><td width='19%'>Posted By:</td>\n";
print FILE "<td width='81%'>$poster</td></tr>\n";
print FILE "<tr><td width='19%'> </td>\n";
print FILE "<td width='81%'> </td></tr>\n";
print FILE "<tr><td width='19%'>Posted On:</td>\n";
print FILE "<td width='81%'>$DayOfWeek $Month $monthday,
$year</td></tr>\n";
print FILE "<tr><td width='19%'> </td>\n";
print FILE "<td width='81%'> </td></tr>\n";
print FILE "<tr><td width='19%'>Subject:</td>\n";
print FILE "<td width='81%'>$FORM{'subject'}</td></tr>\n";
print FILE "<tr><td width='19%'> </td>\n";
print FILE "<td width='81%'> </td></tr>\n";
print FILE "<tr><td width='19%'>Announcement:</td>\n";
print FILE "<td width='81%'>$FORM{'announce'}</td></tr>\n";
print FILE "</table><br>\n";
print FILE "<table border='0' width='100%' cellspacing='0'
cellpadding='0'>\n";
print FILE "<tr><td height='1' background='/images/h-line.gif'
colspan='2'>\n";
print FILE "<img src='/images/empty.gif' width='1'
height='1'></td></tr>\n";
print FILE "</table><br>\n";
print FILE "<!--add-->\n";
}
else { print FILE "$line"; }
}
# Print the Thank You page
print "<html><head>\n";
print "<title>Thank You</title>\n";
print "<META HTTP-EQUIV='Refresh' content='3;
url=http://honk.dts.emich.edu/resnet/announce.shtml'>\n";
print "</head><body>\n";
print "Your announcement has been posted! You will be automatically
re-directed to the story page in 3 seconds.\n";
print "If you are not re-directed, please, <a
href='http://honk.dts.emich.edu/resnet/announce.shtml'>click here</a>\n";
print "</body></html>\n";
exit;
Monk wrote:
> "Jeremiah Megie" <jeremiah@klondyke.net> wrote in message
> news:397E0908.3ED825B7@emich.edu...
> > I have written a script that will allow a user to post announcements to
> > a webpage. They fill out the form, hit submit, and it puts the contents
> > into the page. It works perfect, except one thing. When you type your
> > announcement in the textarea box, it doesn't let you use html tags, so
> > when you type and submit the form, everything is on one line and nothing
> > can be seperated out. I want to be able to have the users type in their
> > announcement and have it automatically put in <p> tags, and <a href>
> > tags, upon them putting in a link or a new paragraph. Is there a way
> > that I can do this? I can't seem to figure it out.
> >
> >
> > Jeremiah
> >
> Can you provide the script that is doing this for you? Is a database
> involved? Text file? Need more specifics.
>
> wes
------------------------------
Date: 26 Jul 2000 01:08:31 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: <newbie> Html Tag generation
Message-Id: <u2ddg64w.fsf@macforce.sumus.dk>
Jeremiah Megie <jeremiah@klondyke.net> writes:
> I want to be able to have the users type in their
> announcement and have it automatically put in <p> tags, and <a href>
> tags, upon them putting in a link or a new paragraph.
So you want to replace newlines with <BR> or <P> (perhaps one newline
with <BR> and two with <P>) and http://dom.com with
<A href="http:://dom.com">http://dom.com</A>?
read up on regular expression and substitutions in eg. perlop - the section on
Regexp Quote-Like Operators.
I'd do something like
$text =~ s#$#<BR>#gm;
$text =~ s#(<BR>\n){2,}#\n\n<P>#g;
$text =~ s#(http://\S*[\w/])#<A href="$1">$1</A>#g;
but then that's just me. I bet there are better ways.
--
Jakob
------------------------------
Date: Tue, 25 Jul 2000 20:15:01 -0400
From: Jeremiah Megie <Jeremiah.Megie@emich.edu>
Subject: Re: <newbie> Html Tag generation
Message-Id: <397E2D85.765B0E93@emich.edu>
Yes, I would like to replace 1 cariage return with <br>, 2 cariage returns with
<p>, and http://www.dot.com with <a
href="http://www.dot.com">http://www.dot.com</a>
I'm not sure how to incorporate the example you gave. Do I just place them near
the top of my script with the variables, or do I need to do something different?
Jeremiah
Jakob Schmidt wrote:
> Jeremiah Megie <jeremiah@klondyke.net> writes:
>
> > I want to be able to have the users type in their
> > announcement and have it automatically put in <p> tags, and <a href>
> > tags, upon them putting in a link or a new paragraph.
>
> So you want to replace newlines with <BR> or <P> (perhaps one newline
> with <BR> and two with <P>) and http://dom.com with
> <A href="http:://dom.com">http://dom.com</A>?
>
> read up on regular expression and substitutions in eg. perlop - the section on
> Regexp Quote-Like Operators.
>
> I'd do something like
>
> $text =~ s#$#<BR>#gm;
> $text =~ s#(<BR>\n){2,}#\n\n<P>#g;
> $text =~ s#(http://\S*[\w/])#<A href="$1">$1</A>#g;
>
> but then that's just me. I bet there are better ways.
>
> --
> Jakob
------------------------------
Date: Tue, 25 Jul 2000 18:54:40 -0400
From: Phil Zampino <zampino@squidco.com>
Subject: CGI->new(*FORM) Problem...
Message-Id: <zampino-911607.18544025072000@enews.newsguy.com>
(apologies if this comes through more than once, my news server is
apparently misbehaving...)
I'm trying to write better Perl by switching a routine I have handled
manually to Perl/CGI.
The routine stores off the current form passed to a CGI program then
calls an authorization routine, which eventually re-calls the original
CGI program. When the program is re-called it looks for the presence of
the stored form file, and if it exists and the user is now authorized it
reloads the form data.
This has worked well for me manually storing and loading the form data,
but I decided that the CGI code $query->save(*FH) would work more
efficiently (and in general I much prefer the CGI method of handling
parameters) so I changed the code to perform the CGI save call (see
below). I've found a lot of examples of how to store off the data, and
I can see that my /tmp/$lockfile contains the passed form data after the
save and both before and after the authorization call.
The problem is that on returning to the CGI program, my restore doesn't
seem to bring back the form data, but instead some kind of HASH value- I
can't figure out how to properly read it back in using Perl/CGI
techniques. I've tried 23 permutations of loading the data back in
(FORMS, *FORMS, \*FORMS) and I've looked at umpteen sites on the web on
how to do this. While I've seen specific techniques for pulling back
the form data and manually parsing the stored data, I've seen no generic
method for restoring the stored data back into a CGI form available to
my program.
Can anyone tell me what I'm doing wrong, or what the trick is to
restoring this data?
Thanks,
philz
if (!(-e "/tmp/$lockfile")) {
open(FH,">/tmp/$lockfile") or die "can't write to forms log: $!";
flock(FH,2) or die "can't flock formlog: $!";
$query = CGI->new();
$query->save(*FH);
close(FH) or die "can't close formlog: $!";
}
($user_id, $last_visit) = &auth_check(1);
open(FORMS, "< /tmp/$lockfile") or die "can't read forms log: $!";
flock(FORMS, 2) or die "can't lock forms log: $!";
$query = new CGI(\*FORMS);
print "the query is now $query";
#
# I would think the above would restore the form data but instead I get
# some sort of hash value in $query
#
system "rm /tmp/$lockfile";
return ($user_id, $last_visit);
------------------------------
Date: Tue, 25 Jul 2000 23:58:48 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: cookie and redirect trouble...
Message-Id: <Pine.GHP.4.21.0007252348370.26198-100000@hpplus03.cern.ch>
On Tue, 25 Jul 2000, Anders Hansson wrote:
> I have been trying hard for a couple of days (sad but true!) to set a cookie
> and redirect a user from my cgi.
> I have tried to do this both by perl and c++. I use an IIS server on win2k
> for testing. This is my code in c++ and in perl:
1. Use CGI.pm, it takes care of the details
2. Apparently, you have to treat all scripts for IIS as
no-parsed-headers scripts. Again, CGI.pm can take care of the
details.
Why not upgrade to Apache? It's a transferrable skill.
3. You are setting a cookie on one server and then redirecting
presumably to another server. Check the cookie rules to see if
this is going to do anything useful cookie-wise. (I think the answer
is 'no', but I'm not clear enough on what you're trying to achieve).
Like all programming projects, progress is best made step-by-step.
Looking at your posting, but I could be wrong, I get the impression
you are already out of your depth, with too many details that are
beyond your grasp. Gosh, if you don't even know how to express a
newline, you really _do_ have problems. But CGI.pm can take care of
that too. (OK, for nph scripts I would open in binmode, and use
\012\015 see [1], but I wouldn't really do that - I'd use CGI.pm).
comp.infosystems.www.authoring.cgi is the place where your posting
would be most on-topic, modulo server details which evidently belong
on comp.infosystems.www.servers.ms-windows in your case.
[1] perldoc perlport , where it talks about "socket i/o", which is
the nearest relevant paradigm.
------------------------------
Date: Tue, 25 Jul 2000 23:29:57 GMT
From: Jason Dixon <jason@mybowie.com>
Subject: Custom mail headers with perl
Message-Id: <964572049.563630838@newsreader.digex.net>
Hi all-
I've written a script to email a list of people with updates on my site. The
script works great, except I'm having difficulty customizing the "From" section
of the header (no problems at all with the "Subject"). Instead of changing the
From header to my variable, it uses the "real" header (from a machine that is
NOT in my domain), but inserts the new header into the body of the email (???).
As always, TIA!
-Jason
<snippet>
foreach $name (<INPUT>) {
chomp;
$from = "Jason <jason\@domain.com>";
$subject = "shtuff goes here";
$mailer = Mail::Mailer->new("sendmail");
$mailer->open({ From => $from,
To => $name,
Subject => $subject,
}) || die "can't open: $!";
print $mailer $body;
$mailer->close();
}
</snippet>
------------------------------
Date: Tue, 25 Jul 2000 15:42:08 -0700
From: steve cramton <scrampton71NOscSPAM@hotmail.com.invalid>
Subject: DB File Question
Message-Id: <0c70f3d4.bdcb7c8d@usw-ex0105-036.remarq.com>
This is a general question regarding DB File
I have a script which reads 10000's of records from a text file
in to a Database. It appears the the database is only updated
when the database is untied at the end of the script. I would
like the capability to commit the records to disk as they are
read in.
Is this possible? or do I need to untie the database after so
many records are read in? and re-tie the data base again?
Im using the standard
tie %h, 'DB_File', "$database", O_CREAT|O_RDWR, 0666, $DB_HASH
or die "Cannot open database file: $!\n" ;
Thanks.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: 25 Jul 2000 17:51:02 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: DB File Question
Message-Id: <8ll5km$iqq$1@provolone.cs.utexas.edu>
In article <0c70f3d4.bdcb7c8d@usw-ex0105-036.remarq.com>,
steve cramton <scrampton71NOscSPAM@hotmail.com.invalid> wrote:
>
>This is a general question regarding DB File
>
>I have a script which reads 10000's of records from a text file
>in to a Database. It appears the the database is only updated
>when the database is untied at the end of the script. I would
>like the capability to commit the records to disk as they are
>read in.
>
>Is this possible? or do I need to untie the database after so
>many records are read in? and re-tie the data base again?
>
>Im using the standard
>
>tie %h, 'DB_File', "$database", O_CREAT|O_RDWR, 0666, $DB_HASH
> or die "Cannot open database file: $!\n" ;
"perldoc DB_File", which I just looked at, leads me to believe
you want the sync() method, as in
$db = tie %h, . . .
$counter = 0;
while (<>)
{
# ...modify %h in some way...
$db->sync() if $counter++ % 100 == 0;
}
untie %h;
$db = ''; # IMPORTANT to include so untie really succeeds!
Hope that helps.
- Logan
------------------------------
Date: 25 Jul 2000 16:13:57 -0700
From: Matthew Emmett <memmett@fraser.sfu.ca>
Subject: Gtk-Perl on Win32?
Message-Id: <yvw91z0hu7ka.fsf@fraser.sfu.ca>
Hi all,
I know one can get Gtk running on Windows. And I also know that one
can get perl running on Windows. So, can one get Gtk-Perl running on
Windows? If it can't be done right now, where might I start hacking?
The Makefile.PL of Gtk-Perl smells like unix, so I wonder how
difficult it would be to get it going on Windows.
Thanks for any suggestions or comments,
Matt
------------------------------
Date: 25 Jul 2000 17:41:30 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: how do you ? question
Message-Id: <8ll52q$iq5$1@provolone.cs.utexas.edu>
In article <8g2snscjl8veppgaguo6iumdiksnpgla9m@4ax.com>,
Chris <exit72@excite.com> wrote:
>they know the answer but aren't willing to share
>it , but oh here is a link to the manual that will explain. Morons
>like that miss the point , we've already been through the doc pages
>with no luck if you see a post here.
The problem is that while that is sometimes true, it isn't always
true. Some people regard Usenet as their personal technical support
service that is there to answer their every question so as to save them
the trouble of having to do their own work. Sometimes it's hard to
tell whether someone has tried the documentation is still confused
or has simply not tried the documentation.
- Logan
------------------------------
Date: Wed, 26 Jul 2000 00:21:33 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how do you ? question
Message-Id: <Pine.GHP.4.21.0007260019480.26198-100000@hpplus03.cern.ch>
On Tue, 25 Jul 2000, Chris wrote:
> The answer to your question , I've been watching this group for a long
> long time
So you've no excuse, but you learned nothing from the experience.
I'd already scored you down, there's only one place you can go next.
--
A patent application requires an implementation,
which is impossible due to the lack of sufficently
dense material to make one that would work.
- Glenn Randers-Pehrson discussing specification for a clue-stick
------------------------------
Date: Tue, 25 Jul 2000 17:17:27 -0700
From: "Mark Watters" <mwatters@cobaltgroup.com>
Subject: No Data from Database
Message-Id: <8llaog$hs1$1@pinto.cobaltgroup.com>
My cgi (is supposed to)first query a db, then display on a webpage:
&queryDb;
&displayResults;
sub queryDb {
#stores info in scalar or array
}
sub displayResults {
#takes info, puts in appropriate columns puts on page
}
The problem is this, when I run from the command line 'perl myprogram.cgi"
the output is the correct html, but when I access it from the web page the
db info doesn't show up. Anyone?
--
Mark Watters
------------------------------
Date: Tue, 25 Jul 2000 23:33:23 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: perl as part of unix distribution
Message-Id: <slrn8ns8tp.56f.tjla@thislove.dyndns.org>
I was shocked! How could Russ Jones <russ_jones@rac.ray.com>
say such a terrible thing:
>Eric Bohlman wrote:
>I'm not talking about implied security. Many large corporations
>(including some I've worked for) make it a condition of purchase that
>a vendor's software works.
*shrug* well I'm sure if you paid enough money for it, someone would be
happy to offer you a guarantee on paper that perl "worked" for some
definition of "worked". This is not to say that it would do you any
good in the event that it failed. You would not however be buying perl
per se. but rather the guarantee. Lots of things come with "extended
warantee's" and what have you's so why not perl?
>To paraphrase Oscar Madison, it took me thirty minutes to figure out
>that IANAL meant "I am not a lawyer."
I always thought it meant "I am Anal" :) but that's just me.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Please go away.
------------------------------
Date: Tue, 25 Jul 2000 22:58:24 GMT
From: "Peter Tutko" <pmtutko@worldnet.att.net>
Subject: Re: perl v. tcl
Message-Id: <kYof5.8498$RG6.723408@bgtnsc05-news.ops.worldnet.att.net>
Morten Skaarup Jensen <morten@nospam.org> wrote in message
news:8ljfp9$ika$1@news.net.uni-c.dk...
> Wow, I loved seeing this the twosidedness of this discussion.
>
> I have a similar question which I might as well pose now:
>
> What main advantages disadvantages does Perl have over Tcl when one is
> developing interactive web pages.
>
> Background: I already know how to program Tcl, but know nothing about
Perl,
> except that it is by far the most popular of the two for interactive web
> pages. Is this because it is better? Is it possibly easier to do simple
> arithmetic?
I have been helping to develop an e-commerce website in Tcl, building an
online catalog database (currently only flat file), shopping cart, and
online ordering with eventual interface to credit card processing. Even
though I already know Tcl (been a Tcl developer for 2 years now), I
evaluated Perl and found (for *me*) that Tcl was less cryptic and easier to
maintain. -- I freely admit my Tcl bias here.
The point of my entry into the discussion here is that the website hosting
company (Verio) is having some difficulty in understanding anything about
providing Tcl interpreter support on the web host. First they told me it
wasn't supported. Then I pointed out where to look and they "discovered"
tclsh in /usr/bin. No one I talked to in tech support had ever heard of Tcl.
Finally, after convincing Verio that they already supplied Tcl as a service
(in the path) I had the support tech start a tclsh and tell me what version
they are running (v7.4). My scripts fail because I must be using some 8.x
features. I am now in discussions with Verio to talk them into upgrading
their support to the current v8.3.1 level.
I think that many web hosting services are unaware that Tcl is probably
already installed on their systems, and they remain ignorant of how to deal
with it. Ultimately, if Verio will not upgrade, I will have to de-tune my
scripts or consider re-writing in Perl or even find another web hosting
service.
--
Peter M. Tutko
------------------------------
Date: Tue, 25 Jul 2000 22:44:08 GMT
From: mike@excite.com ()
Subject: Re: perl-5.6.0: Bug with "not" operator?
Message-Id: <slrn8ns70m.eea.mike@zorak.happyfish.org>
Earlier, Keith Calvert Ivey <kcivey@cpcug.org> wrote:
>Can you give an example of an expression you'd use in a real
>program where the changed behavior makes a difference and where
>you prefer the old behavior? I find it hard to imagine that
>someone would use "not($a) and $b" to mean "not($a and $b)".
I think this glosses over an important point. The operators not, and,
and or have a different precedence from !, &&, and ||, respectively.
not ($a) or $b; # not has a HIGHER precendence than or
SHOULD be different from:
not ($a) || $b; # not has a LOWER precedence than ||
(where $a is a non-trivial expression that needs parens around it)
That's the whole point of mixing the words and the symbols. Parens
shouldn't change that.
Mike
------------------------------
Date: 25 Jul 2000 18:17:56 EDT
From: abigail@foad.org (Abigail)
Subject: Re: READING hashes eats memory!?
Message-Id: <slrn8ns4gd.vcg.abigail@alexandra.foad.org>
Ilmari Karonen (iltzu@sci.invalid) wrote on MMDXX September MCMXCIII in
<URL:news:964559802.25515@itz.pp.sci.fi>:
##
## There is probably a better solution; Instead of treating your data
## structure as a sparse 2**32 times 2**32 matrix, checking each and
## every possible combinations, it makes more sense to treat it as what
## it is - a hash of hashes - and only look at the keys that do exist.
##
## foreach my $src (keys %cell) {
## foreach my $dst (keys %{ $cell{$src} }) {
## my $i = $cell{$src}{$dst}{packets};
## # ...
## }
## }
##
## Or, alternatively, to minimize dereferencing and hash lookups:
##
## while (my ($src, $src_v) = each %cell) {
## while (my ($dst, $dst_v) = each %$src_v) {
## my $i = $dst_v->{packets};
## # ...
## }
## }
##
## This of course assumes you don't have any keys in %cell that are not
## in %src, or any keys in the second-level hashes that are not in %dst.
## If there are any, you could always explicitly skip them.
Perhaps. But maybe you want to traverse the elements in order, and sorting
the keys can be very unwieldy. 2**20 keys is only a fraction of the total
possible keys, but one hell of a lot of keys to sort.
When dealing with huge amounts like this, the Perl datastructures break
down, and you'll need something else. Depending on what exactly you want,
perhaps PDL or Math::Pari can work, but I don't know how whether they
have support for sparse datastructures.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: Wed, 26 Jul 2000 00:00:02 GMT
From: my_deja_v@my-deja.com
Subject: Record length
Message-Id: <8ll9m0$g8e$1@nnrp1.deja.com>
How can I control the record lengths of a file that is being created
from the concatination of several other files.
Th eproblem is that the file needs to go to the mainframe which expects
the lines to be in 512k blocks. I would like to read from the files and
write to FILEBIG with 512k blocks...
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 25 Jul 2000 23:27:23 GMT
From: michaelgartlan@my-deja.com
Subject: trapping INT signal on system call
Message-Id: <8ll7om$en4$1@nnrp1.deja.com>
HI ,
I am relatively new to the perl world of IPC
so all advice/contstructive crticism welcome.
Please read below to see the program which
I am strugling with - it describes what I'm
trying to do and the problem I have
with trapping the INT signal while
"system" is executing (I am aware that
system cmd blocks INT signal but hoping to
find a clever work around).
Thanks for help,
cheers,
Michael.
PS
Want to be able to detect an INT signal (e.g. CTRL-C
or LSF bkill command) in my application so that I can
put error message in log file to indicate failure and
so I can perform clean-up (moving/deleting files
from temp directory)
#! /usr/local/bin/perl -w
#
# This file is ctrlc.pl
#
# the purpose of this program is to have
# all data destined for STDOUT and STDERR
# to be displayed on screen and logged to
# a log file (LOG_FILE), including data from programs
# run using "system" command.
#
# If INT signal is detected (e.g. CTRL-C), want message
# "INT signal detected" to
# appear in log file to indicate this.
#
#
# Problem - if I run this program and hit Ctrl-C while
# ctrlc.pl is printing I see the desried result
# i.e. "INT..." message in logfile
# However if I hit Ctrl-C while "system" is running
# the program "stdmsg.pl" then I do not get the "INT..."
# message - NOR do I see the die "ERROR.." msg
# NOTE: I have read that system blocks SIGINT so my problem is how do I
# achieve the desired result of traping the INT signal as
# this signal may arrive while system is executing
$LOG_FILE = "mylog.txt";
$SIG{INT} = \&ctrl_c_handler;
$SIG{PIPE} = \&pipe_handler;
sub ctrl_c_handler {
open(LOG_FILE, ">>$LOG_FILE") or die "couldnt open LOG_FILE: $! \n" ;
syswrite LOG_FILE, "INT signal detected - e.g. CTRL-C -- ouch
!!!!!!\n";
exit;
}
sub pipe_handler {
close(STDOUT);
}
$process_id = open(STDOUT, "| tee $LOG_FILE") or die "Couldnt fork : $!
\n;" ;
open(STDERR, ">&STDOUT"); # this is to ensure that STDERR goes to same
place as STDOUT
select STDOUT; $| = 1; # select STDOUT and make unbuffered
for ($i=0; $i<5 ; $i++) {
sleep(1);
print STDOUT "$0 - HELLO STDOUT \n";
print STDERR "$0 - HELLO STDERR \n";
}
system("stdmsg.pl") == 0 or die "ERROR - stdmsg.pl did not succesfully
complete";
###############################
# contents of program stdmsg.pl
###############################
# #! /usr/local/bin/perl -w
#
# for ($i=0; $i<5 ; $i++) {
# sleep(1);
# print STDOUT "stdmsg.pl : msg to STDOUT\n";
# print STDERR "stdmsg.pl : msg to STDERR\n";
# }
# exit 0;
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 25 Jul 2000 19:54:24 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: USEing a perl module
Message-Id: <slrn8nsa5g.g8d.tadmc@magna.metronet.com>
On Wed, 26 Jul 2000 09:33:20 +1200, Peter Sundstrom <peter.sundstrom@eds.com> wrote:
>
>Tad McClellan wrote in message ...
>>On Tue, 25 Jul 2000 13:57:57 +1200, Peter Sundstrom
><peter.sundstrom@eds.com> wrote:
>>>
>>>Glen Heide wrote in message ...
>>>>On the server I use (paid server), they don't have the MIME::Lite module,
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>>>>I have to install it myself... though I've been having no luck so far.
^^^^^^^
^^^^^^^
>>>If you have set the path correctly in the "use lib", then everything will
>be
>>>fine (assuming of course, that the rest of your code has no bugs).
>> ^^^^
>> ^^^^
>>
>>
>>Eh?
>>
>>The module is not installed.
>>
>>"use lib" isn't going to install the module.
>
>
>Glen said that he has installed the module,
^^^^^^^^^^^^^
"no luck" and "has installed" don't seem to go together.
>but just can't use it.
What he said was that it was not installed on his "server".
He then went on to say that he has it working fine on
his PeeCee (implying that the problem was with the
differing environment (missing module) rather than
with his Perl code).
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 25 Jul 2000 23:23:35 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Was Why won't "use strict;" work?
Message-Id: <397E21AB.B70EEFC8@home.com>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Thanks for all the help. I'm still working on it before posting my final
for further critique. A few more questions. :-(
<p>1. If I choose to put in the absolute path to the data file(instead
of a relative path), is there a way to do this with a referrer, instead
of using my entire server addy? When I give this code to someone, I don't
want it to show my full directory path. Say, the entire URL is <A HREF="http://members.tripod.com/~dennis/count.txt">http://members.tripod.com/~dennis/count.txt</A>
...and I just want to show count.txt?
<p>2. Do I need to set include a file permission, such as 666, when I call
out:
<br>sysopen(count, $counter, O_RDWR|O_CREAT, 0666) Why or why not?
<p>3. I noticed that most examples(including the one from PerlFaq5), with
a filehandle defined as a scalar, show it similar to: $number = <COUNT>
|| 0; However, someone here questioned using the || 0;
Why is it not a good idea to use the 0 value? What value should be used,
and why?
<p>4. TRUNCATE: I'm a little confused about "truncate". Out of the numerous
sites that I have researched (including CPAN), here's all the info that
I have found on the "truncate" function. In general, they say you can either
use truncate(COUNTER, 0) or truncate with a scalar value such as truncate($COUNTER,
0). The value was explained as the length... and after much more research
another site explained that length meant "byte length".
<p>Now, I understood Abigail to be questioning the use of 0 for the "truncate
value", saying it would wipe out the data file. However, I noticed
that all examples (including Lou Hevly's) have the value at 0. Since the
byte size changes on a counter, what byte size should I use?... or do I
even need one?
<p>5. TELL & CHOMP
<br>Yes, I've read about them in the perl man pages. Why are they needed
though? Doesn't "truncate" do the same thing?
<p>Kind regards,
<br>Dennis</html>
------------------------------
Date: 25 Jul 2000 19:37:46 EDT
From: abigail@foad.org (Abigail)
Subject: Re: Was Why won't "use strict;" work?
Message-Id: <slrn8ns964.vcg.abigail@alexandra.foad.org>
What A Man ! (whataman@home.com) wrote on MMDXX September MCMXCIII in
<URL:news:397E21AB.B70EEFC8@home.com>:
:} <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
What follows isn't HTML, but you should post HTML or pseudo-HTML on
Usenet in the first place.
Get some real tools on your computer.
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: Tue, 25 Jul 2000 16:51:10 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Was Why won't "use strict;" work?
Message-Id: <MPG.13e7c7c86f01897898abea@nntp.hpl.hp.com>
In article <slrn8ns964.vcg.abigail@alexandra.foad.org> on 25 Jul 2000
19:37:46 EDT, Abigail <abigail@foad.org> says...
> What A Man ! (whataman@home.com) wrote on MMDXX September MCMXCIII in
> <URL:news:397E21AB.B70EEFC8@home.com>:
> :} <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
>
> What follows isn't HTML, but you should post HTML or pseudo-HTML on
> Usenet in the first place.
s/(should)/$1n't/;
> Get some real tools on your computer.
Amen!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 25 Jul 2000 23:18:49 GMT
From: rurban@sbox.tu-graz.ac.at (Reini Urban)
Subject: Re: When to use for and foreach?
Message-Id: <397e202d.213784325@news>
Jim Cook wrote:
>What are the opinions here? When would it be better to use 'for' or
>'foreach?'
trust the docs.
--
Reini
------------------------------
Date: 25 Jul 2000 19:38:58 EDT
From: abigail@foad.org (Abigail)
Subject: Re: When to use for and foreach?
Message-Id: <slrn8ns98c.vcg.abigail@alexandra.foad.org>
Reini Urban (rurban@sbox.tu-graz.ac.at) wrote on MMDXX September MCMXCIII
in <URL:news:397e202d.213784325@news>:
)) Jim Cook wrote:
)) >What are the opinions here? When would it be better to use 'for' or
)) >'foreach?'
))
)) trust the docs.
'for' is more than twice as fast [1] as 'foreach'.
[1] to type
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
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 3803
**************************************