[17726] in Perl-Users-Digest
Perl-Users Digest, Issue: 5146 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 18 21:10:31 2000
Date: Mon, 18 Dec 2000 18:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977191813-v9-i5146@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 18 Dec 2000 Volume: 9 Number: 5146
Today's topics:
read contain of file to variable <kolisko@penguin.cz>
Re: read contain of file to variable (Martien Verbruggen)
Re: RegEx: \s but not \n <thomas@geffert.com>
Re: should subroutines do their own error checking? <tick.toff@spam.com>
Re: should subroutines do their own error checking? (Abigail)
Re: substrings - // question <jeffp@crusoe.net>
Re: temporary files (Tad McClellan)
Re: time, schedules, advice (Tad McClellan)
Re: time, schedules, advice <ng@fnmail.com>
Trying to extract only names with letters in regex exp? <robert@chalmers.com.au>
Re: variables in html files <aks_music@hotmail.com>
Re: variables in html files (Tad McClellan)
Re: Why isn't Perl highly orthogonal? <brannon@lnc.usc.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 19 Dec 2000 03:10:04 +0100
From: "Michal Kolesar" <kolisko@penguin.cz>
Subject: read contain of file to variable
Message-Id: <91m92b$1cu$1@news.vol.cz>
Hi all..
i tried this but this not work:
$fh1 = new IO::File;
if ($fh1->open("< laststat")) {
my $poslednizaznam = $fh1;
# print <$fh1>;
$fh1->close;
}
print $poslednizaznam;
Could You help me?
Tx
--
---
Michal Kolesar
kolisko@penguin.cz
http://www.egarden.cz
public server of free unix services
------------------------------
Date: Tue, 19 Dec 2000 02:02:08 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: read contain of file to variable
Message-Id: <slrn93tg8u.j5f.mgjv@verbruggen.comdyn.com.au>
On Tue, 19 Dec 2000 03:10:04 +0100,
Michal Kolesar <kolisko@penguin.cz> wrote:
> Hi all..
>
> i tried this but this not work:
> $fh1 = new IO::File;
> if ($fh1->open("< laststat")) {
> my $poslednizaznam = $fh1;
> # print <$fh1>;
> $fh1->close;
> }
> print $poslednizaznam;
>
> Could You help me?
The bit you commented out above actually has the <> operator in it,
which is what you want.
my $poslednizaznam = <$fh1>;
Look at the documentation for IO::File (which you seem to have done, a
little bit, judging by the code presented) and the perlop
documentation, which describes the <> operator.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: 19 Dec 2000 01:14:05 +0100
From: Thomas Geffert <thomas@geffert.com>
Subject: Re: RegEx: \s but not \n
Message-Id: <87vgshjmia.fsf@cal056202.student.utwente.nl>
mcafee@waits.facilities.med.umich.edu (Sean McAfee) writes:
> In article <91k7f9$rdd@netnews.hinet.net>,
> John Lin <johnlin@chttl.com.tw> wrote:
> >May I ask a further question? I want to join lines as well as removing
> >the prefixing and trailing spaces. That is, for those strings
> > "abc\n def"
> > "abc \n def"
> > "abc \ndef"
> > "abc\ndef"
> >the results are all "abcdef". But not for "abc def" because it contains no
> >"\n".
> >My code is
>
> > s/[^\S\n]*\n[^\S\n]*//;
>
> >It works. But I think there is still a lot of space for improvement, right?
>
> Well, maybe a little. How about:
>
> s/(?=\s*?\n)\s+//;
I would have chosen the following:
s/\s*\n\s*//;
And I must admit that I don't understand your use of the
zero-width-look-ahead . Especially I'm not sure, why your
s/(?=\s*?\n)\s+// works for "abc\ndef". I thought, the \s+ would need
at least one whitespace after the (?=\s*?\n) term. What am I missing
with this look-ahead approach?
Thomas
------------------------------
Date: Mon, 18 Dec 2000 23:35:39 GMT
From: "SuperGumby" <tick.toff@spam.com>
Subject: Re: should subroutines do their own error checking?
Message-Id: <fbx%5.23936$xW4.184945@news-server.bigpond.net.au>
Jesse James Jensen wrote in message <3A3E944F.B2B3CD0B@uchicago.edu>...
>What do you all think?
>
>Say I want to call a subroutine and pass it some variables. If a
>particular one of these variables is empty, I don't want the subroutine
>to work its magic. This check, however, is tangential to the
>subroutine; i.e., based on other, more important conditions, I would
>want to run the subroutine. Should I check in the main program and not
>run the subroutine, or should I leave the check to the subroutine to
>figure out? Is there a general consenus on this?
>
IMHO
An object oriented model would do the validation in the subroutine, but
you're looking at a tradeoff speedwise. Validation before the subroutine
call will be quicker.
I don't work on a lot of cooperative programming, so playing by the rules
worries me less (though I try). I am more likely to use the program logic to
ensure the state of items, initialise to valid state, validate on input and
try not to throw it out of whack in your logic.
------------------------------
Date: 19 Dec 2000 00:40:15 GMT
From: abigail@foad.org (Abigail)
Subject: Re: should subroutines do their own error checking?
Message-Id: <slrn93tbjf.u2n.abigail@tsathoggua.rlyeh.net>
Jesse James Jensen (jesse@uchicago.edu) wrote on MMDCLXVI September
MCMXCIII in <URL:news:3A3E944F.B2B3CD0B@uchicago.edu>:
__ What do you all think?
__
__ Say I want to call a subroutine and pass it some variables. If a
__ particular one of these variables is empty, I don't want the subroutine
__ to work its magic. This check, however, is tangential to the
__ subroutine; i.e., based on other, more important conditions, I would
__ want to run the subroutine. Should I check in the main program and not
__ run the subroutine, or should I leave the check to the subroutine to
__ figure out? Is there a general consenus on this?
Well, if you check in the subroutine, you will be sure it's never run.
Checking by the caller might in some cases lead to clearer code.
And note that there's no law that prevents you from doing both.
Abigail
--
print 74.117.115.116.32, 97.110.111.116.104.101.114.32,
80.101.114.108.32, 72.97.99.107.101.114.10;
------------------------------
Date: Mon, 18 Dec 2000 15:34:58 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: substrings - // question
Message-Id: <Pine.GSO.4.21.0012181532250.22284-100000@crusoe.crusoe.net>
[posted & mailed]
On Dec 18, Adam Levenstein said:
>USER:username
>
>followed by a newline, and the username is of varying lengths. I'm
>trying to get the username and put it into $user. Here's the line I've
>been using, but doesn't seem to work:
>
>$user = "VALUE=\"" . ($data[3] =~ /USER:\S{1,}\n$/) . "\"";
A regex in scalar context returns success. Perhaps you meant:
$user = 'VALUE="' . ($data[3] =~ /USER:(.+)/)[0] . '"';
First, I changed \S{1,} to .+, since . won't match \n by default. And I
put ()'s around it so that we would save what matched there. Then, I took
subscript 0 of the list returned by the regex (effectively getting $1).
Please read 'perldoc perlre'.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
PerlMonks - An Online Perl Community http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
------------------------------
Date: Mon, 18 Dec 2000 18:04:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: temporary files
Message-Id: <slrn93t5vv.7g8.tadmc@magna.metronet.com>
EM <me@privacy.net> wrote:
>how do i save a file to the memory/disk where that when the script
>terminates any temporary files are automatically deleted
Write an "END block" that deletes the temp files.
END blocks are documented in the "Package Constructors and Destructors"
section:
perldoc perlmod
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 18 Dec 2000 18:15:07 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: time, schedules, advice
Message-Id: <slrn93t6jr.7g8.tadmc@magna.metronet.com>
[ Text rearranged into a normal time sequence ]
Enrico Ng <ng@fnmail.com> wrote:
>Enrico Ng <ng@fnmail.com>
Err, what?
You are quoting yourself?
Please figure out how to quote properly, or folks will start
ignoring you.
"Quoting Style in Newsgroup Postings"
http://www.geocities.com/nnqweb/nquote.html
>"jbuff" <jbuff1856@my-deja.com> wrote in message
>news:91lvp6$ckg$1@nnrp1.deja.com...
>> In article <91k90k$jm0$1@info1.fnal.gov>,
>> "Enrico Ng" <ng@fnmail.com> wrote:
>> > I am making a webpage for alocal tv station.
>> > I would like some advice on the schedule system.
>> > I want to be able to display the schedule by calling a function that
>> takes
>> > two(or three) arguments, date,time, duration.
>> > and have it display a grid (table) with the times and the shows.
>> >
>>
>> Tread carefully, someone actually has a patent on displaying TV
>> schedules in a grid with time on one axis. Silly, but true.
>>
>> The owner of the patent is quite litigious, and you could find yourself
>> enjoined, or be required to pay a royalty.
>actually this is a webpage for the tvstation of my university
>the page would only be accessable to those in the university domain
That's nice, but has nothing whatsoever to do with using
a patent without permission.
Why do you think that that is germane?
>I'm looking for some advice on how to store a date or a number
>that represtents the date and time.
Use the number of seconds since midnight, Jan 1 1970.
That's how Unix does it.
perldoc -f time
perldoc -f localtime
perldoc -f gmtime
>since when the data is stored, it will be a begin time and duration, i need
>an easy way to add times
Use the addition operator (+) :-)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 18 Dec 2000 19:29:14 -0600
From: "Enrico Ng" <ng@fnmail.com>
Subject: Re: time, schedules, advice
Message-Id: <91mdqm$phm$1@info1.fnal.gov>
can i use localtime backwards? to convert a date/time to seconds?
--
Enrico Ng <ng@fnmail.com>
"Tad McClellan" <tadmc@metronet.com> wrote in message
news:slrn93t6jr.7g8.tadmc@magna.metronet.com...
>
> Use the number of seconds since midnight, Jan 1 1970.
>
> That's how Unix does it.
>
> perldoc -f time
> perldoc -f localtime
> perldoc -f gmtime
>
> >since when the data is stored, it will be a begin time and duration, i
need
> >an easy way to add times
>
>
> Use the addition operator (+) :-)
>
>
> --
> Tad McClellan SGML consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Tue, 19 Dec 2000 11:53:04 +1000
From: "Robert Chalmers" <robert@chalmers.com.au>
Subject: Trying to extract only names with letters in regex exp?
Message-Id: <e5y%5.35$Zu.5296@nsw.nnrp.telstra.net>
Hi,
trying to extract from a list, only those names that contain letters. No numbers, no dashes or stops etc. Just A-Z
I though this would do it. The name is at most 4 letters long, so should'n this do it? Match only letters in the A-Z range, and in
the position, 0 to 4 in the string $name.?
but it doesn't do it... I admitto getting real confused with regex, but this seems so easy ! and I'm stumped.
if ($name =~ /[A-Z]{0,4}/) {
print "$name\n";
}
If any kind soul can pointout the error of my ways, I'd really appreciate it.
thanks
robert
--
---
Robert Chalmers
http://www.quantum-radio.net.au Quantum Radio robert@quantum-radio.net.au
http://www.inexpensivewebsites.com Domain Name Registrations info@inexpensivewebsites.com
------------------------------
Date: Tue, 19 Dec 2000 00:05:01 GMT
From: =?iso-8859-1?Q?=D0=2DVolta?= <aks_music@hotmail.com>
Subject: Re: variables in html files
Message-Id: <3A3EA32E.C0C1A6C3@hotmail.com>
Hi EM:
The following code shows a working example:
#!/usr/bin/perl -w
# Ð-Dvolta PCP'd
$my_name = "Ð-Volta";
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
<title>Print Out A Scalar</title>
<body>
<center>
<h2>Greetings Earthlings!</h2>
<font size =3>My perl pcp pseudonym is <b>$my_name</b></font>
</center>
</body>
</html>~;
EM wrote:
> i am making a script and using html templates
> the problem is that the html file will contain variables such as
> <html><body><b>$text</b></body></html>
> but when perl opens the html and prints it to the screen it does not
> translate $text
> how do i get this to work?
>
> -------------
> Eric
------------------------------
Date: Mon, 18 Dec 2000 18:19:10 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: variables in html files
Message-Id: <slrn93t6re.7g8.tadmc@magna.metronet.com>
EM <me@privacy.net> wrote:
>the problem is that the html file will contain variables such as
^^^^^^^^
><html><body><b>$text</b></body></html>
>but when perl opens the html and prints it to the screen it does not
>translate $text
Of course not.
You seem to not be making the essential distinction between what
is code and what is data.
Stuff that your program reads from a file is _data_.
Variable are only expanded in _code_.
>how do i get this to work?
By checking the Perl FAQ *before* posting to the Perl newsgroup:
perldoc -q variable
"How can I expand variables in text strings?"
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 19 Dec 2000 01:09:46 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: Why isn't Perl highly orthogonal?
Message-Id: <lbn1dt9pyr.fsf@lnc.usc.edu>
Michael Carman <mjcarman@home.com> writes:
> Terrence Brannon wrote:
> >
> > [C]onceptually similar operations do not map to the same name
> > in Perl. Why does this make Perl a better and not worse language,
> > than the intended replacement to Perl, Ruby, which is in fact highly
> > regular in all places where Perl isn't [...]
>
> Heh. Careful, there! By whom is Ruby intended to be a replacement to
> Perl? ;)
>
> Most of the responses have centered on your example, not the subject of
> your question. Perl is non-orthogonal by design. From 'perldoc perl'
>
> "The language is intended to be practical (easy to use,
> efficient, complete) rather than beautiful (tiny, elegant,
> minimal)."
well, thanks. This clears things up. I do recall reading this many
years ago when first finding Perl.
>
> IIRC, Larry Wall has referred to Perl as being a "diagonal" language.
> Instead of forcing a rigid method of doing things, Perl provides you
> with options and allows you to choose the most natural (i.e. idiomatic)
> method. Whether this is a good thing or a bad thing is largely a matter
> of preference. If you want a minimal language, then it's awful. But if
> you want to be able to write an arbitrary piece of code quickly and
> concisely, then it's wonderful.
You aren't kidding. Everytime I have a text-processing task, my brain
goes into Perl-mode and I rip right through it. Now of course, afer
it's done, I can engage in the armchair philosophy that led to this
question.
> IMHO, orthogonality is overrated. It sounds nice on the surface, but you
> invariably end up with a situation where you have to write some ugly
> hack to get around the restrictions of the language.
Yeah, or you end up doing a whole lot more typing before the task gets
done.
--
Terrence Brannon
Carter's Compass...
I know I'm on the right track when by deleting code I'm adding
functionality.
------------------------------
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 5146
**************************************