[8885] in Perl-Users-Digest
Perl-Users Digest, Issue: 2503 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 5 12:17:27 1998
Date: Tue, 5 May 98 09:01:41 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 5 May 1998 Volume: 8 Number: 2503
Today's topics:
help a novice in perl! <info@atig.fr>
Re: HELP Me PLEASE! <aqumsieh@matrox.com>
Re: help wanted (trivial) <aqumsieh@matrox.com>
Re: HELP: Can someone help me with this problem ?? <jdf@pobox.com>
Re: HELP: Can someone help me with this problem ?? (Tad McClellan)
Re: How do I reuse functions in several programs? <jdf@pobox.com>
How to send email (was Re: Ever Wonder Why Not Everyone (Bennett Todd)
Re: how to use eval and-or $@ <jdf@pobox.com>
Re: Interrupts ... or whatever they are called <aqumsieh@matrox.com>
Re: list from regexp (Hunter Johnson)
Re: malformed header? <aqumsieh@matrox.com>
Re: Mutliple emails <spamfree@yahoo.com>
Re: parsing query string <lr@hpl.hp.com>
Re: passing .htaccess login info (Chris Hamilton)
Re: Perl and MVS - how to? <ward.kaatz@pss.boeing.com>
Re: perl script to trans smtp mail text to html <quednauf@nortel.co.uk>
Re: regex newline substitution question (Tad McClellan)
seek, syssek, tell... Where is systell? (Bart Lateur)
Re: seek, syssek, tell... Where is systell? (Mark-Jason Dominus)
Re: stat function (Tom Grydeland)
Re: What it perl? (Tad McClellan)
Re: writing to a file <barnett@houston.Geco-Prakla.slb.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 5 May 1998 17:04:07 +0200
From: "sg" <info@atig.fr>
Subject: help a novice in perl!
Message-Id: <6inaas$phd$1@minus.oleane.net>
hello everybody!!
I would wanted to do a perl script which can
put in a table, *.html files founded in a directory.
but (even if i've made some researches on
FAQ, and try to found an information on perl
book) i didn't found a function which can return
(or repertoriate) the *.html files in a directory.
thanks you very much to help me!
sg
info@atig.fr
------------------------------
Date: Tue, 05 May 1998 11:11:15 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: HELP Me PLEASE!
Message-Id: <354F2C13.C5455680@matrox.com>
Aaron Faby wrote:
> Umm... IE is the problem, get Netscape.
>
> Aaron
>
> Alex wrote:
>
> > Hello,
> > I have a problem, I cannot chat in Java chats because I cannot type
> > in the fields. I use Windows 98 1702 beta with IE. Help me, please. What is
> > wrong?
> >
> > Sincerly,
> >
> > Alex.
The problem might be in IE ... but the real problem is laziness. How would
posting to a perl newsgroup help in Java chats?
--
Ala Qumsieh | "How much wood would a woodchuck
ASIC Design Engineer | chuck if a woodchuck could
Matrox Graphics Inc. | chuck wood?"
Montreal, Quebec | - Trivial ... 5!
------------------------------
Date: Tue, 05 May 1998 11:08:13 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: help wanted (trivial)
Message-Id: <354F2B5D.68EB4F0F@matrox.com>
fantha wrote:
> Hi there !
>
> First of all :
>
> I'm new with perl, so this is a very trivial question I have.
>
> Today I bought a book so that I can start my career as a perlmaster :)
> While reading it I tried to code a program that handles hashes.
> But it doesn't work in that way I thought it should do.
> In my opinion it should return "schwarz" if you type "black". But it
> returns nothing. What's wrong here ?
>
> Please answer to my question by posting here or by email
>
> fantha@berlin1.netsurf.de
>
> Thanks, Jens
>
> Here's my tiny prog
>
> #!/usr/bin/perl
> %COLORS =
> (
> "black" => "schwarz",
> "white" => "wei_",
> "blue" => "blau",
> "yellow" => "gelb",
> "red" => "rot",
> "green" => "gr|n"
> );
> print "Bitte geben Sie eine Farbe ein :";
> $farbe = <STDIN>;
>
If you type black and hit enter, $farbe will contain "black\n" (I hope
you know that!)So, you'll have to chop() off that pesky \n character ..
use this instead:
chop($farbe = <STDIN>);
> # print $farbe;
> #
> # This only was a test, to see if $farbe contains data
> # It does !
>
> print $COLORS{$farbe};
Enjoy
--
Ala Qumsieh | "How much wood would a woodchuck
ASIC Design Engineer | chuck if a woodchuck could
Matrox Graphics Inc. | chuck wood?"
Montreal, Quebec | - Trivial ... 5!
------------------------------
Date: 05 May 1998 10:56:28 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Nguyen LY <nl@medex.anhb.uwa.edu.au>
Subject: Re: HELP: Can someone help me with this problem ??
Message-Id: <lnsglnir.fsf@mailhost.panix.com>
Nguyen LY <nl@medex.anhb.uwa.edu.au> writes:
> <1>
> TI File title
> AU File author
> AB File abstract
> RE References
>
> <2>
> TI
> AU
> .
> .
> .
>
> <n>
This is the sort of problem that's a pleasure to approach with Perl.
As you learn more about Perlish thinking, certain approaches will
present themselves to you as obvious solutions. Here's one way: an
array of hashes. If you don't yet understand hashes, you must buy and
read _Learning Perl_, which gently will explain them to you. You
should also read perldata, perllol, perldsc, and perlref (and the
perlfaqs, of course). In the meantime, check this out.
Each element of the array @files is a hash whose keys are 'TI', 'AU',
etc.
$files[0] = { TI => 'File title',
AU => 'File author',
#etc.
};
You might create this structure like so (this is *sample* code, and is
not well suited for production; it doesn't check for errors and
boundary conditions):
while (<THEFILE>) {
$current_index = $1 - 1, next if /^<(\d+)>/;
next if /^\s*$/;
($key, $val) = split ' ', $_, 2;
$files[$current_index]->{$key} = $val;
}
You'd then get the abstract of the third file with this expression:
$files[2]->{AB}
I hope this is of some help to you. Do get _Learning Perl_, if you
don't already have it.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Tue, 5 May 1998 07:58:42 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: HELP: Can someone help me with this problem ??
Message-Id: <2e2ni6.161.ln@localhost>
Nguyen LY (nl@medex.anhb.uwa.edu.au) wrote:
: Can anyone help me out with this problem ???
Yes.
: I'm trying to write a script that will filter an imported text file
: which has the following format:
: ------------File begin--------------
[snip file format]
: The algorithm I'm trying to come up with will read the file in
: line by line
^^^^^^^^^^^^
It will be _much_ easier if you don't put that restriction on the solution.
: So basically, what I want to come up with is an @array with
: $array[0] = 1, [1] = string in TI, [2] = string in AU... etc..
Perl has 'paragraph mode' just for such an occasion as this.
(your sample above has each record separated by a blank line, para mode
will take advantage of that)
See INPUT_RECORD_SEPARATOR in the perlvar man page.
Execute this and see if it does what you need:
------------------------
#!/usr/bin/perl -w
$/ = ''; # enable paragraph mode
while (<DATA>) {
# @array = /^<(\d+)>\nTI (.*)\nAU (.*)\nAB (.*)\nRE (.*)/; # one line version
@array = /^<(\d+)>\n # match digits in angle brackets at start of record
TI\s(.*)\n # match the first "flagged" field
AU\s(.*)\n
AB\s(.*)\n
RE\s(.*)
/x;
foreach $elem (@array) {
print "'$elem'\n"
}
print "\n";
}
__DATA__
<1>
TI File title
AU File author
AB File abstract
RE References
<2>
TI File title2
AU File author2
AB File abstract2
RE References2
------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 05 May 1998 10:04:37 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: How do I reuse functions in several programs?
Message-Id: <n2cwlpx6.fsf@mailhost.panix.com>
Jonathan Feinberg (that's me) <jdf@pobox.com> writes:
>Keith Vertrees <keith@comcore.com> writes:
>> Modules seem like they might be the answer, but all that I can
>> "easily" find out about modules is that they go into files with a
>> .pm suffix.
> By "easily," you seem to mean, "without reading the docs!"
I owe it to Mr. Vertrees to say that my response was presumptuous; he
had indeed done a good deal of reading. He has pointed out to me in
private correspondence that the Camel's chapter 5 (which concerns
modules) mentions neither the PERL5DB environment variable nor the
'use lib' pragma. It was also one of those cases where he couldn't
quite hit upon the right search expression to find the answers in the
FAQ. Hmm.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Tue, 5 May 1998 15:22:21 GMT
From: bet@network.rahul.net (Bennett Todd)
Subject: How to send email (was Re: Ever Wonder Why Not Everyone Uses Modules?)
Message-Id: <slrn6kuc34.p5r.bet@ritz.mordor.net>
My favourite approach is pretty simple-minded, and portable to absolutely
anything I'll every care about porting to:-).
use IO::File;
$ENV{'PATH'} .= ':/usr/sbin:/usr/lib';
my($mail) = IO::File->new('|sendmail ' . join(' ',@who)) or die;
$mail->print("From: myself\n");
$mail->print("To: whoever\n");
$mail->print("Subject: my subject of choice\n");
$mail->print("\n");
$mail->print(@lines_of_body);
$mail->close;
or thereabouts. The "-t" option is available on sendmail and widely emulated
by other MTAs; I'm not personally all that fond of it anyway.
Now if you want to port to e.g. an Apple ][, or a TRS-80 running TRS-DOS, or
god help you Windows NT, then you're going to have to come up with your own
email handling system; perhaps you'll want to code up a local convention for
reliably finding the address of a reliably-available SMTP server, and talk to
it directly, in which case there's help to be found in modules, but talking to
the local standard API for sending email is too painless to need help in any
language on reasonable systems.
-Bennett
------------------------------
Date: 05 May 1998 11:04:24 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: mshavel@erols.com (Michael Shavel)
Subject: Re: how to use eval and-or $@
Message-Id: <iunkln5j.fsf@mailhost.panix.com>
mshavel@erols.com (Michael Shavel) writes:
> The problem I am having is that if the connection fails the whole
> script quits.
There is nothing in your code sample that shows why that would
happen. What comes after printing to the LOG file? Are you sure the
LOG filehandle was successfully associated with a writable file? Are
you using the -w switch?
> eval{
> $ftp = Net::FTP->new($host) or warn "Could not connect to host: $!\n";
> };
> if ($@) {print LOG "Danger will robinson!!\n";}
Perhaps more helpful would be
if (defined $@) { print LOG "$@"; die "$@" }
Since, I'm thinking, you *do* want to stop if you can't connect.
Perhaps better still would be
sub log_and_die { my $msg = shift; print LOG $msg; die $msg }
$ftp = Net::FTP->new($host) or log_and_die("Can't connect: $!");
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Tue, 05 May 1998 10:20:11 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Interrupts ... or whatever they are called
Message-Id: <354F201B.E0C133@matrox.com>
Pablo Hortal wrote:
> Hi,
>
> I need to do the following:
> The user of my system stores a date and a time (Windows 95). At that date &
> time, I need one of my scripts to be called (i.e. like an interrupt).
>
Hmmmm... If I understand correctly, you need an alarm mechanism!Within an
infinite while loop keep checking the current time (every minute or hour or
whatever) .. and call the script when it's the correct time (use system() ).
There might be an easier way using one of the modules! Check the man pages!
> How can I do this?
>
> Thanks,
> Espinete.
--
Ala Qumsieh | "How much wood would a woodchuck
ASIC Design Engineer | chuck if a woodchuck could
Matrox Graphics Inc. | chuck wood?"
Montreal, Quebec | - Trivial ... 5!
------------------------------
Date: 5 May 1998 14:55:48 GMT
From: jhunterj@lexis-nexis.com (Hunter Johnson)
Subject: Re: list from regexp
Message-Id: <6in99k$607@mailgate.lexis-nexis.com>
In article <354E9507.E5392CDA@sni.net>,
Bruce Langlois <langlois@sni.net> wrote:
> What I was wondering is if there is a way to get a regexp to return
> backreferences as a list?
Yep; just use the regexp in a list context (e.g., by assigning it to
your list using the '=' operator).
HTH,
Hunter
--
J. Hunter Johnson | "A little consistent wholesome modeling and
jhunterj@lexis-nexis.com | costly servanthood are worth millions of
(937) 865-6800 x5385 | true words harshly spoken."
Lexis-Nexis, Dayton, OH | -- Ron Sider
------------------------------
Date: Tue, 05 May 1998 10:16:41 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: malformed header?
Message-Id: <354F1F49.11D992AD@matrox.com>
How about a missing semicolon after the 12-th line?
my $taxrate = 1.0743;
~arthur wrote:
> Hi,
> Anyone know why I get the ole' malformed header message when i try and
> get the following program on the net. the problem is O"Reilly's llama
> book, Learning Perl page 190-----
> #!/usr/bin/perl -w
> #cgi-bin/ice_cream:program answer-generate icecream
> #order form (version 4)
> use strict;#enforce variable declarations and quoting
> use CGI qw(:standard);
>
> print header, start_html("Ice Cream Stand"), h1("Ice Cream Stand");
> if (param()) {
> my $who = param("name");
> my $flavor = param("flavor");
> my $scoops = param("scoops");
> my $taxrate = 1.0743
> my $cost = sprintf("%.2f", $taxrate * (1.00 + $scoops * 0.25));
> print p("OK, $who, have $scoops scoops of $flavor for \$$cost.");
> } else {
> print hr();
> print start_form();
> print p("Whats your name? ", textfield("name"));
> print p("What flavor: ", popup_menu("flavor",
> ['mint',
> 'cherry', 'mocha']));
> print p("How many scoops? ", popup_menu("scoops", [1..3]));
> print p(submit("order"), reset("clear"));
> print end_form(), hr();
> }
> print end_html
> } else {
> print hr, start_form;
> print p("Please select a flavor: ", textfield ("flavor", "mint"));
> print end_form, hr;
> }
> -------
> I get these errors
> # syntax error, near "my"
> File 'StarMax HD:Desktop Folder:Mac_Perl:extra folder:ice_cream_stand';
> Line 13
> # Unmatched right bracket, at end of line
> File 'StarMax HD:Desktop Folder:Mac_Perl:extra folder:ice_cream_stand';
> Line 13
> # syntax error, near "end_html
> }"
> File 'StarMax HD:Desktop Folder:Mac_Perl:extra folder:ice_cream_stand';
> Line 13
> # # Execution of StarMax HD:Desktop Folder:Mac_Perl:extra
> folder:ice_cream_stand aborted due to compilation errors.
> # Callback called exit, <IN> chunk 1.
> File 'StarMax HD:Desktop Folder:Mac_Perl:extra folder:ice_cream_stand';
> Line 1
> # END failed--cleanup aborted, <IN> chunk 1.
> File 'StarMax HD:Desktop Folder:Mac_Perl:extra folder:ice_cream_stand';
> Line 13
> ------
>
> Thank you!
> ~arthur
> star@sonic.net
--
Ala Qumsieh | "How much wood would a woodchuck
ASIC Design Engineer | chuck if a woodchuck could
Matrox Graphics Inc. | chuck wood?"
Montreal, Quebec | - Trivial ... 5!
------------------------------
Date: Tue, 05 May 1998 11:37:23 -0400
From: Dave Bushong <spamfree@yahoo.com>
Subject: Re: Mutliple emails
Message-Id: <354F3231.14D83248@yahoo.com>
Guy Einy, EPN wrote:
> Hi,
>
> I'm trying to write a program that will send email to multiple users.
> I've tried using the following (this is just the relevant code):
>
> foreach $recipient(@recipients) {
> send_email($recipient);
> }
>
> sub send_email {
> $recipient = $_[0];
> open (MAIL, "|$mailprog $recipient");
> print MAIL ("To: $recipient\n");
> print MAIL ("From: epnguy\@sinfor.it\n");
> print MAIL ("Subject: A special offer!\n\n");
> [...]
> This format of print commands works fine for a single message.
>
> Does anybody have any ideas?
I would suggest that you change the subject line, because anything with
that subject is automatically deleted from my mailbox before I even read
it. I don't like getting unsolicited spam, but that's just my opinion.
Just out of curiosity, did you get your question answered about how to
collect email addresses from usenet postings?
Kisses,
Dave
------------------------------
Date: Tue, 5 May 1998 07:33:51 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: parsing query string
Message-Id: <6in81m$jpk@hplntx.hpl.hp.com>
Mariana Wuerz wrote in message
<354EEB3B.C8C2240B@magnum.fernuni-hagen.de>...
...
>> $tabellenfelder =~ s/%([\da-fA-F]){2}/chr(hex($1))/eg;
>> $zahl=hex($1);
>> $character=chr($zahl);
>>
>> print "Tabellenfelder: $tabellenfelder <BR>\n";
>>
>> $tabellenfelder =~ tr/"+"/ /;
Two more errors unrelated to the problem corrected by Hakan Hjelstrom:
1. There should not be any quotes here, unless you really want to
convert quotes to spaces (as well as plus signs).
2. The conversion of plus signs to spaces should be done before the
conversion of %xx escapes, lest a real plus sign in the data (encoded as
%2B) end up as a space.
Others may also tell you to use CGI instead. :)
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
>
>
>
------------------------------
Date: 5 May 1998 15:51:09 GMT
From: chrish@squonk.net (Chris Hamilton)
Subject: Re: passing .htaccess login info
Message-Id: <6inchd$elr$1@duke.squonk.net>
Beck Web Servers & Design (bwsd@bwsd.com) wrote:
: The user logs on with username and password...according to .htaccess
: file. However, the password is encrypted in the .passwd file specified,
: and also, I don't know how to trap the input variables from the pop up
: login box that pops up when an .htaccess protected directory is accessed
: on the web.
It's to my understanding that ...
When you connect to a webserver (Apache for example), if an htaccess file
is NOT present, the webserver will attempt to use the RFC1413 auth/ident
method to get the userid of the remote user (if the server is configured
to do so). However, if an htaccess file IS present, and the authentication
is successfull, the username provided (or the userid from the ident
request) is set in the REMOTE_USER environment variable.
As far as the password goes, there isn't a way to pass or retreive the
value unless you design your own method of authenticaion (or possibly hack
the webserver source code).
---
Chris Hamilton C7 F9 1E FF 4F D8 F8 87
chrish@squonk.net F8 13 5F 69 63 B5 EB A8
"You're just jealous because the 'voices' talk to me."
------------------------------
Date: Tue, 5 May 1998 15:28:51 GMT
From: Ward Kaatz <ward.kaatz@pss.boeing.com>
Subject: Re: Perl and MVS - how to?
Message-Id: <354F3033.438C@pss.boeing.com>
Christian Bastholm Jensen wrote:
> I want to use perl on an mvs to access a DB2 database. I have no
> previous experince with mvs, so I have been looking for info on how to
> integrate perl with mvs, but I haven't been able to find any.
Christian,
We are using Perl on MVS. It runs in Unix System Services (formerly
"Open Edition").
So far I have not found any real differences in functionality running on
MVS. (CPAN scripts I've grabbed have worked great so far). I haven't
done any "native" TSO stuff with Perl like TSO commands and file access,
but I expect you can use any Unix system commands including some special
Unix-TSO calls in the command reference (see below). However, using the
Domino Webserver you can access TSO datasets by treating them as URL's
(your webmaster will have to do the mapping, we have a binary called
"MVSDSN" that we include in the URL).
> I have found the modules to use (DBD::DB2) to do it, but I want to know
> more about how Perl and MVS work together, and how much of the UNIX core
> functionality there is available in the MVS ported distributuion of
> Perl.
Have not had a chance to try DBD::DB2, we currently use IBM's Net.Data
to access DB2 and if Perl is needed to augment net.data's somewhat
limited functionality, we can call out to Perl using the net.data
language extensions. You can pass the entire cursor in "table/list"
form to Perl subroutines and write to file, browser or return data back
to net.data. This usage is not real efficient, but depending on the
workload, our 3090 is such a screamer that response time is not much of
an issue.
I am mostly using perl for CGI not requiring DB2 data, massaging
flatfiles into static pages. Although some of the net.data stuff we are
doing requires perl to do robust string manipulation. Perl SCREAMS
from the shell (especially when working with large amounts of file io)
on MVS!
> I have experience using perl on unix and windows, but thats a different
> world all togehter!
Unix System Services on MVS is Unix, you can use an ISPF interface to
access HFS and shell via TN3270 or use Telnet to a shell and use vi,
etc. It appears to be a pretty full implementation of I expect, AIX.
> Where can I get this info, all help will be greatly appreciated.
if you have DB2, you have net.data and likely perl (although probably
not the latest version), if you're using the server as a webserver, then
you have Unix System Services already installed (Domino runs on Unix,
not native MVS).
If you have Book Manager installed, then you probably have the USS
Documents (still called Open Edition). I think all the books are also
available from an unknown-by-me IBM site.
Here is the BookMgr command Reference Doc number:
OS/390 V1R2.0 OpenEdition Command Reference - BPXA502
I expect you'll find like I that your admins will be fairly
unknowledgable about this stuff (although our MVS guys have done a great
job handling what appears to be a relatively steep learning curve wrt
unix), you may find yourself supporting them for awhile.... :-)
Hope this helps!
Ward Kaatz
------------------------------
Date: Tue, 05 May 1998 16:03:45 +0100
From: "Frank L. Quednau" <quednauf@nortel.co.uk>
Subject: Re: perl script to trans smtp mail text to html
Message-Id: <354F2A51.C1AF210B@nortel.co.uk>
scott@softbase.com wrote:
> ageorge@best.com wrote:
>
> > Does anyone know where I can find a script that will translate smtp mail text
> > to html?
>
> This question doesn't make a lot of sense. How do you want "smtp mail"
> translated to HTML? (Or, rather, "http HTML"?) Do you want some kind of
> AI package that inserts bold, italics, etc based on intuitive guesses
> about where the user put emphasis? If this isn't the case, mail is just
> plain text. Slap a <pre> before it and a </pre> after it and you're
> done. What's so hard about that?
Rough guess: ageorge's email client doesn't understand html formatted messages
he/she gets from other people, and wants to be able to read them. In that case you
could simply open the textfile your email client stores the emails in (at least my
Netscape does save in textfiles). Then you could parse that textfile with perl,
give it maybe the subject line you're looking for as an argument, and perl then
extracts the body of the message and saves it to a file, which could then be read
with a browser. Alternatively, do some cut'n paste!
>
>
> You could, alternatively, use Outlook as the e-mail client.
> It generates HTML formatted messages.
Not only Outlook but also Netscape's
free-source-code-megacool-as-zillions-write-bug-patches-now Communicator.
--
____________________________________________________________
Frank Quednau
Phone: +44 (0)1279 402447
http://www.surrey.ac.uk/~me51fq MailTo:F.L.Quednau@bnr.co.uk
____________________________________________________________
------------------------------
Date: Tue, 5 May 1998 07:38:23 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: regex newline substitution question
Message-Id: <v71ni6.e21.ln@localhost>
lou@visca.com wrote:
: Here's a simple little script to copy html files into text files. It works
: fine except that the first file in the directory, in ASCII-betical order,
: isn't affected by the line: "$line =~ s/\n+/\n/gs;", though it is by both the
^
: s/\t//gs;
^
Those modifiers have no effect other than a mild obfuscatory one ;-)
The s///s modifier changes the interpretation of dot in a regex, but
neither of those regexen even _have_ a dot in them...
: and s/<.*?>//gs; lines. All other files get their multiple newlines
^
Now that one you need.
: replaced by one newline and if I stick in a dummy file (00.html), then the
: formerly first file is changed too.
: Can anyone explain to me why this is? Thank-you.
You do not enable 'paragraph mode' until _after_ you are done reading
the first file. So the elements of @a are not multiline strings when
processing the first file (each element has only one newline in it).
A simple print statement in your loop would have exposed that...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 05 May 1998 15:04:56 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: seek, syssek, tell... Where is systell?
Message-Id: <35502a38.25938880@news.tornado.be>
There are two different sets of words with the same purpose: read,
write, seek, tell make one set, and syswrite, sysread, sysseek make
another. These must be kept apart, or bugs will occur in our program.
Note that there is no sys* counterpart for tell. On current MacPerl
implementatations, tell doesn't work combined with sysread/sysseek.
Argh!
What actually doesn't make any sense, is that there are TWO FILE
POSITION POINTERS. That's right: two number per file with the same
purpose. Why?
Wouldn't it be possible to keep both hidden, using seek to set both,
tell would return the most recently updated one, and if you intermingle
read and sysread, (write and syswrite would cause buffering proiblems),
both would keep track of the fact that the other one has been executed
last, and next time, if necessary, they would do their own version of
seek first, if needed, to keep track of the one and only true file
position pointer.
The purpose of the whole exercise would, of course, be that there would
only appear to be just one file position pointer, one seek function, one
tell function, and a simpler interface for the Perl application
programmer.
Bart.
------------------------------
Date: 5 May 1998 11:12:06 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: seek, syssek, tell... Where is systell?
Message-Id: <6ina86$ivc$1@monet.op.net>
Keywords: Allentown drop Kilgore Tartary
In article <35502a38.25938880@news.tornado.be>,
Bart Lateur <bart.mediamind@tornado.be> wrote:
>Note that there is no sys* counterpart for tell.
That's because sysseek(FH, 1, 0) will return the current file position.
> On current MacPerl
>implementatations, tell doesn't work combined with sysread/sysseek.
Of course not. They do two different things.
>What actually doesn't make any sense, is that there are TWO FILE
>POSITION POINTERS. That's right: two number per file with the same
>purpose. Why?
Perl normally uses the standard I/O library. This provides buffered
I/O. Consider this program:
open FH, "file" or die ...;
for ($i=0; $i<10; $i++) {
getc FH;
}
The first `getc' makes Perl read a large amount of data from the file,
probably about 8K. Then it returns a character from this buffer. The
next 9 calls to `getc' get characters from this buffer. Perl only had
to read from the real disk once.
Now, look what happened: To the operating system, the seek pointer is
8K into the file, and the next time the operating system is asked for
data, it should return bytes 8192...16383. But for Perl, the seek
pointer is only 10 bytes into the buffer, and the next time you issue
a buffered read command, say getc, you should get byte #10.
All the normal Perl I/O functions operate on the buffer, including
`read', print, seek, <FH>, getc, and so on.
For normal use, the rule is: Always use the buffered functions. `seek'
and `tell' operate on the buffer. Usually that is what you want.
sysseek and systell give instructions to the operating system to move
the real file pointer. Usually this is not what you want.
Intermingling calls to thsee will confuse the standard I/O library and
deliver unpredictable results.
Sometimes, for special applications, you need to do unbuffered I/O.
Perl gives you an escape hatch. That's what sysseek, sysread, and
syswrite are for.
>The purpose of the whole exercise would, of course, be that there would
>only appear to be just one file position pointer, one seek function, one
>tell function, and a simpler interface for the Perl application
>programmer.
It is already simpler. The simple interface is: Don't use sysread,
sysseek, and syswrite if you don't know what they are for. Use the
ordinary Perl I/O functions, and stay away from sys*.
------------------------------
Date: 5 May 1998 14:22:18 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: stat function
Message-Id: <slrn6ku84q.q2g.Tom.Grydeland@mitra.phys.uit.no>
On Tue, 05 May 1998 11:56:43 GMT,
Mark Austin <mark@tmsnet.co.uk> wrote:
> I've written a routine to get the file size of each file within a specific
> directory.
> however, it only works on particular files. There doesn't seem to be a
> pattern either. I'm using NT as a platform.
Can't say anything for NT.
> Any suggestions ?
chdir "dirname" or die "Can't chdir to dirname: $!";
opendir DIR, "." or die "Can't open dirname: $!";
# create list of [name, size] pairs
@pairs = map {[$_, -s]} readdir DIR;
# print out pairs?
foreach $pair (@pairs) {
printf "%32s: %d\n", @$pair;
}
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: Tue, 5 May 1998 10:05:28 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: What it perl?
Message-Id: <or9ni6.1h2.ln@localhost>
Lars Chr Hausmann (36haus@but.auc.dk) wrote:
: I have to write something about, what Perl is.
This is the very first Frequently Asked Question in the very
first part of the Perl Frequently Asked Questions list.
"What is Perl?"
"Perl is a high-level programming language with..."
: I need some crystal clear info about, what perl is.
What's lacking from that First Of All Frequently Asked Questions?
: So if any of you
: would be so kind just to mail. Then I would be grateful!
If you would be so kind as to check the FAQ for a newsgroup before
posting to the newsgroup, then folks would like you.
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq1/What_is_Perl_.html
See also:
http://language.perl.com/info/synopsis.html
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 05 May 1998 08:41:39 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: Inge Soetens <soetensi@se.bel.alcatel.be>
Subject: Re: writing to a file
Message-Id: <354F1713.CE795123@houston.Geco-Prakla.slb.com>
[cc to cited author]
Inge Soetens wrote:
>
> Hello,
>
> can anyone help me with this ?
> I'm trying to put some data in a new file,
> but I have a little problem :
>
> this is the code I use....
>
> #!/usr/local/bin/perl
> if ($ENV{'REQUEST_METHOD'} eq 'POST')
> {
> # Get the input
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> # Split the name-value pairs
> @pairs = split(/&/, $buffer);
use CGI.pm;
# this makes the whole data extraction part easy.
# It is part of the standard dist. with at least 5.004_01
# See perldoc CGI for documentation
Does @pairs actually contain data?
If not, none of the following code will do anything.
Do you have these in your code:
#!/usr/local/bin/perl -w on the first line
use strict;
Both will help point out flaws in your logic.
Have you run this through the debugger?
Using CGI.pm will allow you to run the script in offline mode, and feed
data to it. This and the debugger combined should allow you to figure
out where the script is falling over.
<snip>
>
> $tdp_file = "../tdp_arm.txt";
> $test = "Testing ....";
> open (TDPARM, ">$tdp_file")|| die "Can't find article $TDPARM: $!\n"; ;
> print TDPARM $test ;
> close (TDPARM) ;
The 5 lines above (when fed into a perl script by themselves) work fine.
>
> }
>
> This doesn't work.
In what way?
Is a file created, but is empty?
Is there no file created?
Do you get some kind of error message?
Does the system come to a screeching halt?
> Please help ....
See above.
>
> Thanks
> Inge
HTH.
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
----------------------------------------------------------------------
Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
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 2503
**************************************