[11296] in Perl-Users-Digest
Perl-Users Digest, Issue: 4896 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 15 10:17:16 1999
Date: Mon, 15 Feb 99 07:14:50 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 15 Feb 1999 Volume: 8 Number: 4896
Today's topics:
Bug in perl win32 dbm hashes? <Ian@nospam.blcleathertech.com>
calculate and print a period of days nguyen.van@imvi.bls.com
Re: Can 2 "submit" buttons in 1 form do different thing <flavell@mail.cern.ch>
Re: Can 2 "submit" buttons in 1 form do different thing <rkingsto@jwgrnci6.jaguar.ford.com>
Re: Can 2 "submit" buttons in 1 form do different thing <bmb@ginger.libs.uga.edu>
Re: Comments in Perl code <rra@stanford.edu>
david <vasquez@zap.a2000.nl>
Re: Editor <bmb@ginger.libs.uga.edu>
Re: Editor (Randal L. Schwartz)
Re: executing second script (Sam Holden)
FREE CV - RESUME <john@NOSPAMonline-cv.net>
Re: getting full path of program name (Randal L. Schwartz)
Re: HELP stripping NEWLINE character nguyen.van@imvi.bls.com
Re: how to get file creation time? <jdf@pobox.com>
Irix port of Perl - problem installing new modules. <dimitrio@fantom.com>
Irix port of Perl - problem installing new modules. (Super-User)
Irix port of Perl - problem installing new modules. (Super-User)
Need your opinion ---> starting my own web company? <vanluc@faltec.com>
Re: Newbie question (Sam Holden)
Re: ODBC question <woerdehoff@sdm.de>
Perl and SQL consultant required. (Adam Thyer)
Perl not user friendly? wuz: HOW pass input to perlscri <bmb@ginger.libs.uga.edu>
Re: PFR: read_file, write_file <4mschulz@informatik.uni-hamburg.de>
Re: Please Help a New Perl Student (John D.)
Printing an emailadres <Eric.Richter@hsij.nl>
Re: Printing an emailadres (Sam Holden)
Re: reading a file <M.Pales@alcatel.de>
Scandinavians! Go to http://www.eksperten.dk <jfl@jfl.dk>
Re: silly simple query (Dimitri Ostapenko)
Re: silly simple query <dimitrio@sympatico.ca>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Feb 1999 12:50:54 GMT
From: "Ian Gaffron" <Ian@nospam.blcleathertech.com>
Subject: Bug in perl win32 dbm hashes?
Message-Id: <01be58e1$4ed943e0$26616182@ian>
I'm using dbm hashes with small databases (currently < 20 entries) and
entries are "disappearing". i.e. some keys are not returned when I use
"keys" but they ARE in the
dbm file, for example...
dbmopen(%myhash, $file, undef);
$key = "RCL98-9-203";
$myhash{$key} = "something";
@items = keys %myhash; # Above entry is missing!
print $myhash{$key}; # Shows the value!
I keep deleting and reentering the same key/value pairs and it keeps
missing the same entries. When I try the same application and data on
perl/Linux it works perfectly.
Is this a bug in perl/Win32?
------------------------------
Date: Mon, 15 Feb 1999 13:43:32 GMT
From: nguyen.van@imvi.bls.com
Subject: calculate and print a period of days
Message-Id: <7a98a3$ejf$1@nnrp1.dejanews.com>
Hi guys,
I just wonder if any body have a script or leads to calculate and print out
days of a period. For example: the input is like 01/19/1999-02/15/1999 or
12/15/1999-01/15/1999, the script will print out as following:
01/19/1999
01/20/1999
01/21/1999
........
02/13/1999
02/14/1999
02/15/1999
Thanks
Van Nguyen
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 15 Feb 1999 11:33:21 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Can 2 "submit" buttons in 1 form do different things?
Message-Id: <Pine.HPP.3.95a.990215112052.2813A-100000@hpplus01.cern.ch>
On Sun, 14 Feb 1999, Pamela Schultz wrote:
> Subject: Can 2 "submit" buttons in 1 form do different things?
Sure. This is not a perl problem. You can have a dozen different
submit buttons in one form, if you want.
http://ppewww.ph.gla.ac.uk/~flavell/www/trysub.html
> and my "view results" button is in another form -- therefore they are on
> separate lines in my html page since I can't put 2 forms on the same line.
Well, that's a different issue. If you wanted to have separate
forms there would be a way of dealing with that (TABLE).
> My perl script looks for values in hidden fields in order to determine what
> to do.
You can do that if you want, but the submit button has name and
value attributes that you can use, which may seem more logical.
------------------------------
Date: Mon, 15 Feb 1999 11:26:27 +0000
From: Richard Kingston <rkingsto@jwgrnci6.jaguar.ford.com>
Subject: Re: Can 2 "submit" buttons in 1 form do different things?
Message-Id: <36C80462.3BB970A@jwgrnci6.jaguar.ford.com>
Pamela Schultz wrote:
> What I'd like to do is have my 2 buttons side by side in the
> same form instead of one on top of the other. Is there a way to do this? I'm
> new to perl and cgi, so I'm not sure what gets passed to the perl script.
> Can I have 2 submit buttons in the same form that do different stuff?
>
Not a problem!
In the HTML define 2 submit buttons and give both different Values. eg.:-
<INPUT TYPE=SUBMIT NAME='Choice' VALUE='Change Directory'>
<INPUT TYPE=SUBMIT NAME='Choice' VALUE='Load Cell'>
In the CGI script you then just check to see what has been sent as the value of
(in this case) Choice.
Have a look through CGI.pm documentation to see exactly how to read what is
passed to the script.
------------------------------
Date: Mon, 15 Feb 1999 08:45:36 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
To: Pamela Schultz <vikette@earthlink.net>
Subject: Re: Can 2 "submit" buttons in 1 form do different things?
Message-Id: <Pine.A41.4.02.9902150836040.49404-100000@ginger.libs.uga.edu>
On Sun, 14 Feb 1999, Pamela Schultz wrote:
> Can I have 2 submit buttons in the same form that do different stuff? Can I
> somehow pass to the perl script which button is pressed by the user? Thanks
> for your help!
Yes and No. You can have two submit buttons in the same form. *You*
can't pass which button is pressed by the user, but your browser does.
Example:
<html><head><title>Test</title></head><body>
<form method=POST action="mail.cgi">
<input type=submit name="_preview" value="Preview">
<input type=submit name="_mail" value="Mail">
</form>
</body></html>
If the user presses "Preview" the browser sends _preview=Preview.
If the user presses "Mail" the browser sends _mail=Mail.
You can, of course, choose your own names and values, and you are
definitely not limited to just two buttons. I've used up to seven so far.
Are you reading the CGI news groups?
Regards,
-Brad
------------------------------
Date: 15 Feb 1999 02:18:29 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Comments in Perl code
Message-Id: <yl90e06kcq.fsf@windlord.stanford.edu>
Warning: This is about MULE in emacs and hence is a totally off-topic
digression.
Stephen F Palincsar <palincsars.isc@gao.gov> writes:
> Apropos of MULE, isn't this something that if you ignore it and do not
> even look at the menu, it doesn't bother you?
I wish.
It may be better now (or at least it's supposed to be, and 20.4 may be
better), but originally MULE had the habit of utterly mangling anything
you edit that happened to have non-ASCII characters. I actually edit
binaries in emacs on a not-infrequent basis for various reasons and
because emacs could always cope with them (provided that you set
require-final-newline to nil). MULE wants to save such files in some
mangled internal encoding, and had a tendency to do the same thing for any
files that contained standard ISO 8859-1 characters. Which are used even
for English text and occur frequently in people's names.
I'm pretty much stuck with upgrading to an emacs with MULE support of some
sort (at least as a compile time option) since Gnus is going to require
emacs 20 in the next release and the feature are *well* worth the upgrade,
but MULE is an utter debacle in the eyes of a lot of long-time emacs
users.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Mon, 15 Feb 1999 11:04:39 +0100
From: Joel Wijngaarde <vasquez@zap.a2000.nl>
Subject: david
Message-Id: <36C7F137.8D13566C@zap.a2000.nl>
Heb gebeld, vrijdag was ze er niet en nu moet ik woensdag terugbellen.
Maar ze heeft de Fax wel gekregen geloof ik...
--
Joel Wijngaarde (Physics student)
vasquez@zap.a2000.nl
Quote:
"The final solution is possibly a little extreme - create a new
country - and then export all lawyers there. The Brit's tried
this with Australia, but somehow something went awry
somewhere along the line."
"Hrm. The whole of Europe did that with America and it seems to
have been moderately successful."
------------------------------
Date: Mon, 15 Feb 1999 08:47:34 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Editor
Message-Id: <Pine.A41.4.02.9902150846280.49404-100000@ginger.libs.uga.edu>
You mean THE programmer's editor? VI, of course :-) (vim for windows)
Did you search the web?
On Mon, 15 Feb 1999, Douglas Piccinini Gerhardt wrote:
> Where I can get the Programer's Editor??
> Thanks
> Doug
------------------------------
Date: 15 Feb 1999 06:21:24 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Editor
Message-Id: <m1lnhzbvdn.fsf@halfdome.holdit.com>
>>>>> "Douglas" == Douglas Piccinini Gerhardt <dpg@ez-poa.com.br> writes:
Douglas> Where I can get the Programer's Editor??
http://www.gnu.org/software/emacs/emacs.html has the instructions.
:-)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 15 Feb 1999 10:26:26 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: executing second script
Message-Id: <slrn7cftii.9g0.sholden@pgrad.cs.usyd.edu.au>
On Mon, 15 Feb 1999 09:37:40 GMT, egonw@sci.kun.nl <egonw@sci.kun.nl> wrote:
>
>
>Can someone explain me what goes wrong:
>
>there are two scripts, run.pl and getnews.pl (listed below).
>When I run run.pl at the command line it works, however, when
>i have them executed via CGI the second script does NOT give
>the resulting news.xml file...
>
>both scripts are chmod 775 and news.xml is chmod 777
Do you really want to execute an xml file? If not then why have you
set it to be executable?
>
>run.pl
>------
>#!/usr/local/gnu/bin/perl
>
>print "Content-type: text/html\n\n";
>print "Running program...\n";
>
>exec 'getnews.pl';
You really should be checking for failure when calling exec especially
since you know the problem is with executing the second script...
. probably isn't in the path.
>open (OUT, ">$newsfile");
You should being checking the return value of your OPEN call as well...
--
Sam
compiling kernels is what I do most, so they do tend to stick to the
cache ;) --Linus Torvalds
------------------------------
Date: Mon, 15 Feb 1999 14:44:11 -0000
From: "John Sternbick" <john@NOSPAMonline-cv.net>
Subject: FREE CV - RESUME
Message-Id: <7a9c15$170$1@plug.news.pipex.net>
Hi
You can put your CV online Free with this great perl script, it allows you
to input all your details and upload your photo for at your own personal web
address of www.online-cv.net/yourname/
If you would like to try this service go to:
http://www.online-cv.net
and fill in the forms, and you can then immediately use your new online-cv.
If you have any feedback on the scripts or ideas please post the them back
to the group.
Thanks
John
------------------------------
Date: 15 Feb 1999 06:26:48 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: getting full path of program name
Message-Id: <m1g187bv4n.fsf@halfdome.holdit.com>
>>>>> "Xah" == Xah <xah@best.com> writes:
Xah> What is a reliable and portable way of getting the absolute path of the
Xah> running script?
See FindBin in the standard distribution.
And beware... it can be spoofed. There's no absolutely reliable way
to do this.
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 15 Feb 1999 13:48:13 GMT
From: nguyen.van@imvi.bls.com
Subject: Re: HELP stripping NEWLINE character
Message-Id: <7a98ir$eua$1@nnrp1.dejanews.com>
Hi,
The best way to strip newline is read every input in and use "chomp" ( not
chop ). Chomp function is specially designed to remove "\n".
Van Nguyen
In article <36C5860A.54483F5@tampabay.rr.com>,
saij <saij@tampabay.rr.com> wrote:
> I am using s/\n/<br>/sg;
>
> Why does it leve the newline characters in there??
>
> Saij
>
> please e-mail asap
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 15 Feb 1999 09:55:10 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: %[5a?_ <kflin@alumni.csie.nctu.edu.tw>
Subject: Re: how to get file creation time?
Message-Id: <m3n22fra29.fsf@joshua.panix.com>
%[5a?_ <kflin@alumni.csie.nctu.edu.tw> writes:
> if a file is modified,(e.g. appending some data) the mtime & ctime
> will be both updated. so I won't get any info about the create time
> of a file. Anybody knows the solution?
You'll have to change your desire! Create time simply isn't stored in
unix inodes. I can't speak for other OSs.
If your application is the only one to create and use the files in
question, then you can keep your own database of file creation times.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Thu, 11 Feb 1999 16:50:57 -0500
From: Dimitri Ostapenko <dimitrio@fantom.com>
Subject: Irix port of Perl - problem installing new modules.
Message-Id: <36C350C0.FBDA3C3B@fantom.com>
I've got perl 5.005 and gcc 2.8.1 ports for irix installed on
Indigo 2 (irix6.5). Problem is, perl environment is set to use
MIPS C compiler, which I don't have. No wonder I get bunch of
messages about illegal options and make terminates with fatal
errors.
Do I need to recompile perl with gcc to be able to install new modules?
Thanks,
Dimitri Ostapenko
Hamilton, Canada
------------------------------
Date: Thu, 11 Feb 1999 21:18:41 GMT
From: root@fantom.com (Super-User)
Subject: Irix port of Perl - problem installing new modules.
Message-Id: <ROHw2.262$86.999@198.235.216.4>
I've got perl 5.005 and gcc 2.8.1 ports for irix installed on
Indigo 2 (irix6.5). Problem is, perl environment is set to use
MIPS C compiler, which I don't have. No wonder I get bunch of
messages about illegal options and make terminates with fatal
errors.
Do I need to recompile perl with gcc to be able to install new modules?
Thanks,
Dimitri Ostapenko
Hamilton, Canada
------------------------------
Date: Thu, 11 Feb 1999 21:28:17 GMT
From: root@fantom.com (Super-User)
Subject: Irix port of Perl - problem installing new modules.
Message-Id: <RXHw2.265$86.999@198.235.216.4>
I've got perl 5.005 and gcc 2.8.1 ports for irix installed on
Indigo 2 (irix6.5). Problem is, perl environment is set to use
MIPS C compiler, which I don't have. No wonder I get bunch of
messages about illegal options and make terminates with fatal
errors.
Do I need to recompile perl with gcc to be able to install new modules?
Thanks,
Dimitri Ostapenko
Hamilton, Canada
------------------------------
Date: Mon, 15 Feb 1999 08:57:44 -0400
From: "LukeV" <vanluc@faltec.com>
Subject: Need your opinion ---> starting my own web company?
Message-Id: <vKVx2.171$Vb7.418@wagner.videotron.net>
Hi,
i know this as nothing to do with prg support, but i'm sure someone here
could help me. I'm seriously thinking about starting my own web design
company. I've been doing pages for about 2 years, but lately i've been
learning a lot about .CGIs and starting to learn about ASP. I was wondering
if any people just did what i wanna do, and if so, their opinion about the
whole thing. If anyone has any suggestions, please do not hesitate. Taking a
look at my web site might not be a bad idea too! Thanks everyone for your
time!
--
LukeV
illusion@illusion.qc.ca
www.illusion.qc.ca
------------------------------
Date: 15 Feb 1999 10:37:11 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Newbie question
Message-Id: <slrn7cfu6n.9g0.sholden@pgrad.cs.usyd.edu.au>
On 15 Feb 1999 10:45:45 +0100, Joakim Hove <hove@ido.phys.ntnu.no> wrote:
>seong joon bae <seongbae@students.uiuc.edu> writes:
>
>Well, you have got some advice already, but anyway:
>
>1. #!/usr/bin/perl -w
>
>the -w (warn) gives you various diagnostic warnings which are
>generally very helpful. IMHO you should _always_ use the -w switch.
>
>
>2. if (open(INFILE,"filename")) {
> while (defined <INFILE>) {
> $TheLine = $_;
> [.....]
> }
> } else {
> print("Could not open filename \n");
> }
>
>you must open the file with the open() statement, and check that it
>succededs. Changing while(<INFILE>) -> while(defined<INFILE>) will
>assure that you don't read past end of file [I think at least...]
Maybe instead of just guessing what it does and then posting the advice for
the whole world to see you could check what it actually does...
Your while loop reads a line of input checks if it's defined and discards
it, you then treat whatever happens to be $_ as though it is that line.
A simple test would have revealed this to you...
If you had bothered to read perlsyn to check what while(<INFILE>) you would
have found that it does a defined check itself. If you had bothered to test
it you would have seen that it does with an obvious test.
At least your advice about warnings was good...
If you are using an old version of perl which is lazy about while(<>) and
doesn't do the defined check then it's time to upgrade...
--
Sam
Fifty years of programming language research, and we end up with C++ ???
--Richard A. O'Keefe
------------------------------
Date: Mon, 15 Feb 1999 12:28:30 +0100
From: Hendrik =?iso-8859-1?Q?W=F6rdehoff?= <woerdehoff@sdm.de>
Subject: Re: ODBC question
Message-Id: <36C804DE.295B92BE@sdm.de>
Graffiti schrieb:
>
> Hi all,
>
> I'm not sure where I'm supposed to post this question, so feel
> free to flame me or point out faqs/howtos/newsgroups/etc that cover
> this. :-)
>
> I'm trying to connect to a M$ SQL server from Solaris, using
> Perl's ODBC module and the iodbc server.
Did you install an ODBC driver on Solaris? iodbc is just an ODBC driver
manager but you need an ODBC driver as well. But there ist no MS SQL
Server ODBC driver for Solaris.
> I tried using Intersov's ODBC driver, but that didn't work. It
> simply told me no data source was defined, even though it was
> (different .ini file).
Ah. You thought of the driver. Very good.
You .odbc.ini has the line
> Description = Sample OpenLink MT DSN
in it. Do you use the OpenLink middleware or did you just the the
.odbc.ini file somewhere?
Have a look at http://www.openlinksw.com/ and get their download
package. I got it working very quickly on Linux. My .odbc.ini look
something like
---
[ODBC Data Sources]
Default = OpenLink (MT)
[Default]
Driver = /u/xyz/lib/openlink/odbcsdk/lib/oplodbc.so.1
---
Your had the line
> Driver = /opt/iodbc/lib/libiodbc.so
in it. No wonder that iodbc tried to start itself over and over again.
You have to give the name of the real driver not the driver manager.
Yours
Hendrik
Pursuant to US Code, Title 47, Chapter 5, Subchapter II, Sec. 227,
any and all unsolicited commercial E-mail sent to this address
is subject to a download and archival fee in the amount of $500
US (per infraction). E-mailing denotes acceptance of these terms.
--
Hendrik W"ordehoff |s |d &|m | software design & management
| | | | GmbH & Co. KG :
woerdehoff@sdm.de | | | | Thomas-Dehler-Str. 27 >B)
Tel/Fax (089) 63812-337/515 81737 M"unchen :
------------------------------
Date: Mon, 15 Feb 1999 15:39:01 GMT
From: adam@promethean.com.au (Adam Thyer)
Subject: Perl and SQL consultant required.
Message-Id: <7a9c04$ne1$1@reader1.reader.news.ozemail.net>
Hi all
I have ongoing project-based work for an *affordable* and experienced
consultant who can write SQL (ideally MySQL), CGI and Perl5 for Web site
back-ends on an Apache server running Redhat Linux. If you're interested,
please send your hourly rate (US$) and a detailed resume, URLs of previous
work and referees to adam@promethean.com.au.
Cheers
Adam
------------------------------
Date: Mon, 15 Feb 1999 08:33:31 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Perl not user friendly? wuz: HOW pass input to perlscript ?
Message-Id: <Pine.A41.4.02.9902150823390.49404-100000@ginger.libs.uga.edu>
On 15 Feb 1999, Thelma Lubkin wrote:
> Philip Class <philip.class@popcorn-studio.ch> wrote:
> : PS: Looking for Perl Code Help and tutorial / manuals I get very much the
> : impression that Perl is the less user friendly programming language. To fix
> : Perlscript-Bugs I loose/spend more time that with any other programming
> : language.
> : Does someone share my view ?
> I don't -- it's the easiest language I've worked with,
> but then I came to it in the midst of struggling with
> C++ [and I'm still struggling with that]
> Perhaps you haven't yet found all the documentation that
> comes with most implementations...
> --thelma
"any other programming language"? Like which ones. I've used BASIC,
C, PL/I, Rexx, Awk, Java, not to mention DOS "batch"/UNIX shell and
various macro languages in products like WordPerfect, Lotus 1-2-3,
etc., etc. Perl is without match for ease of use and bug-freeness
IMHO. Haven't touched Python, and the other come-latelies--why
bother? There is nothing I've needed to do that Perl couldn't. Of
course, you have to learn some stuff first ...
Now, what was your question?
-Brad
------------------------------
Date: 15 Feb 1999 12:43:11 GMT
From: Marko Schulz <4mschulz@informatik.uni-hamburg.de>
Subject: Re: PFR: read_file, write_file
Message-Id: <7a94ov$72n$1@rzsun02.rrz.uni-hamburg.de>
In comp.lang.perl.moderated Uri Guttman <uri@sysarch.com> wrote:
>
> here are 2 little favorites of mine which seem to get asked for by all
> newbies. read a file as a list or a single string and write a file from
> a list or string.
Ack
> # utility sub to read a file in.
> # it can return a single string or a list of lines
I would rather write it like this:
use Carp;
sub read_file {
my($file_name) = shift;
my($text, @lines);
local(*FH);
open(FH, $file_name) or croak "can't open '$file_name' $!";
@lines = <FH>;
close(FH);
wantarray() ? @lines : join '',@lines;
}
--
marko - Nordisch by Nature
"And sanity is a full-time job in a world that is always changing"
'Sanity' - Bad Religion -
------------------------------
Date: Mon, 15 Feb 1999 09:48:24 -0500
From: "Dudley (John D.)" <noEmal@noPlace.com>
Subject: Re: Please Help a New Perl Student
Message-Id: <4sWx2.1753$y51.370@dustdevil.neo.rr.com>
Great Link!
Which scripting tool would you recommend for Win95/98 ??
--John
Jonathan Stowe <gellyfish@btinternet.com> wrote in message
news:7a4ncv$4dk$1@gellyfish.btinternet.com...
>On Sat, 13 Feb 1999 14:33:00 -0500 William M. Toohey wrote:
>>
>> Simply, I know Perl is a free language, but where do I type in the perl
code
>> and how do I save it?
>>
>
>You can use any text-editor you like - notepad or the DOS edit will work
>but you might want to avail yourself of something a little more useful
>for programming work - in order to avoid the inevitable ridiculous
>debate over peoples favourite editors I would suggest that you look at
>
> <http://reference.perl.com/query.cgi?editors>
>
>Everyone has their own preference over editors but the thing is to find
>one that works for you.
>
>/J\
>--
>Jonathan Stowe <jns@btinternet.com>
>Some of your questions answered:
><URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
>Hastings:
<URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Tue, 09 Feb 1999 14:00:55 +0100
From: Eric Richter <Eric.Richter@hsij.nl>
Subject: Printing an emailadres
Message-Id: <36C03187.AA8E9D5B@hsij.nl>
I'm making a perl-script for making my statistics from the sendmail
maillog.
But when I want to print an email adres (print $adres), nothings gets
printed.
I think it's something with the '@' symbol, but I don't know what.
Can anyone tell me this?
Eric Richter
Eric.Richter@hsij.nl
------------------------------
Date: 15 Feb 1999 11:04:58 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Printing an emailadres
Message-Id: <slrn7cfvqq.a8g.sholden@pgrad.cs.usyd.edu.au>
On Tue, 09 Feb 1999 14:00:55 +0100, Eric Richter <Eric.Richter@hsij.nl> wrote:
>I'm making a perl-script for making my statistics from the sendmail
>maillog.
>
>But when I want to print an email adres (print $adres), nothings gets
>printed.
>
>I think it's something with the '@' symbol, but I don't know what.
>
>Can anyone tell me this?
If you posted the code the someone might be able to help. As it is I can
only guess that you have written 'thunk' where you meant to write 'print'
on line 94.5.
--
Sam
Fifty years of programming language research, and we end up with C++ ???
--Richard A. O'Keefe
------------------------------
Date: Mon, 15 Feb 1999 13:00:55 +0100
From: Martin Pales <M.Pales@alcatel.de>
Subject: Re: reading a file
Message-Id: <36C80C77.67C1542@alcatel.de>
dan wrote:
> lets say i did this:
>
> #!/usr/bin/perl
> print "Content-type:text/html\n\n";
> open(TEST, "template.txt");
> @test = <TEST>;
> close(TEST);
> print "@test";
>
> how can i have the script read the file until it reaches a certain
> string and then stop? for the sake of argument, lets say $search =
> "12345"
The easiest way seems to be the following one:
#!/usr/bin/perl
$search = "12345";
print "content-type:text/html\n";
open(TEST, "template.txt");
while(<TEST>) {
if(/$search/) {
last;
}
print $_;
}
close(TEST);
> also, how can i get it to read the file from $search on? thanks for your
> help
#!/usr/bin/perl
$found = 0;
#search = "12345";
print "content-type:text/html\n";
open(TEST, "template.txt");
while(<TEST>) {
if(/$search/) {
$found = 1;
next;
}
if($found) {
print $_;
}
}
close(TEST);
Not as clever as can be, but gives an idea...
Harl
------------------------------
Date: Mon, 15 Feb 1999 13:00:52 GMT
From: Jacob <jfl@jfl.dk>
Subject: Scandinavians! Go to http://www.eksperten.dk
Message-Id: <7a95q2$cot$1@nnrp1.dejanews.com>
Scandinavian surfers! Go to http://www.eksperten.dk
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 11 Feb 1999 22:42:42 GMT
From: euclid@fantom.com (Dimitri Ostapenko)
Subject: Re: silly simple query
Message-Id: <C1Jw2.277$86.712@198.235.216.4>
> i.e. I want to slurp a entire file in, and count the amount of times that a
> certain piece of text is matched in that file.
>
open (F, $f);
@f = <F>;
$n = grep /$str/, @f;
print $n;
______
Dimitri Ostapenko
Hamilton, Canada
------------------------------
Date: Thu, 11 Feb 1999 19:53:12 -0500
From: Maria Ostapenko <dimitrio@sympatico.ca>
Subject: Re: silly simple query
Message-Id: <36C37B78.2BDFE84F@sympatico.ca>
This is a multi-part message in MIME format.
--------------68516E51BDB9F0F9D2D2D270
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
@lines=<F>;
$n = grep(/$str/), @lines;
print $n;
>
> i.e. I want to slurp a entire file in, and count the amount of times that a
> certain piece of text is matched in that file.
>
>
Dimitri Ostapenko,
Hamilton
Canada
--------------68516E51BDB9F0F9D2D2D270
Content-Type: text/x-vcard; charset=us-ascii;
name="dimitrio.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Maria Ostapenko
Content-Disposition: attachment;
filename="dimitrio.vcf"
begin:vcard
n:Ostapenko;Dimitri
tel;cell:905.730.1959
tel;home:905.389.3660
tel;work:905.734/7476 x 258
x-mozilla-html:TRUE
org:Fantom Technologies Inc.;Engineering
adr:;;91 Ascoli Dr.;Hamilton;ON;L9B 1Y3;Canada
version:2.1
email;internet:dimitrio@sympatico.ca
title:CAD Designer (Euclid) / Sys Admin (Irix)
fn:Dimitri Ostapenko
end:vcard
--------------68516E51BDB9F0F9D2D2D270--
------------------------------
Date: 12 Dec 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 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4896
**************************************