[11585] in Perl-Users-Digest
Perl-Users Digest, Issue: 5185 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 20 09:07:24 1999
Date: Sat, 20 Mar 99 06:00:22 -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 Sat, 20 Mar 1999 Volume: 8 Number: 5185
Today's topics:
Calculating the current time in London or GMT+x thst@my-dejanews.com
Re: convert a file <ebohlman@netcom.com>
File test operator for modification/access time. (miedo)
Re: Filehandle Q... (Bart Lateur)
Re: help with perl and win98 <seannln@bit-net.com>
Re: Here 's a good one !!! nospam@here.com
Re: How do I split an list of text into separate lists <aqumsieh@matrox.com>
Re: How to let users of website know there are others p (Larry Rosler)
Re: Input for PERL Course request (Bart Lateur)
Re: Need a one liner... <aqumsieh@matrox.com>
Re: Need Faster Approach (Bart Lateur)
Re: Newbie question about form to mail program <aqumsieh@matrox.com>
Re: Perl Excel OLE (Jan Dubois)
Re: PERL Text Handling (Larry Rosler)
problem with fnctl F_GETFL in Perlf5 <Wm.Blasius@ks.sel.alcatel.de>
Remove HTML codes <kcchan@csis.hku.hk>
Re: Remove HTML codes <ebohlman@netcom.com>
Re: Remove HTML codes <kcchan@csis.hku.hk>
Re: Remove HTML codes <m-rau@gmx.de>
Re: Removing white space. (Larry Rosler)
Re: script or module to convert number to binary and ba <aqumsieh@matrox.com>
Re: Some Perl questions <aqumsieh@matrox.com>
Re: Speeding up Multi Word Searches (Boolean OR) (Larry Rosler)
Text Wrapping without Text::Wrap <revjack@radix.net>
Re: Which OS am I in (Bart Lateur)
Re: Why can't i create a file with >>$file? (Larry Rosler)
Re: Why can't i create a file with >>$file? (Larry Rosler)
Re: Windows NT Path Resolution (Larry Rosler)
Re: XML::Parser - 'Objects' style <jeff@vpservices.com>
Re: XML::Parser - 'Objects' style <ebohlman@netcom.com>
Re: XML::Parser - 'Objects' style <ebohlman@netcom.com>
Re: || vs "or" (Larry Rosler)
Re: || vs "or" (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 20 Mar 1999 12:26:32 GMT
From: thst@my-dejanews.com
Subject: Calculating the current time in London or GMT+x
Message-Id: <7d045j$73a$1@nnrp1.dejanews.com>
Assuming a server is located in California/USA. Now I want to find out the
current time in London or some other places in europe.
Well if I add constantly an amount of time (let's say 60*60*8=28800 for a time
lag of 8 hours) like
localtime(time + 28800)
doesn't work, because summer time rules remain unconsidered.
Is there something like a special parameter
localtime(time,GMT+1) or something else ?
Bye
Thomas
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 20 Mar 1999 07:45:19 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: convert a file
Message-Id: <ebohlmanF8vuvK.292@netcom.com>
chongchanlee@hotmail.com wrote:
: I have a data file written in 16-bit binart little endian format of 43Mb.
: I can't read this file. If anyone knows how to read or convert (if necessary)
: this file, please help me.
You probably want to read it in chunks with read() or sysread(), and
parse it with unpack(). All these functions are documented in perlfunc.
: I have Pentium II with 450mh with 256MB RAM in Window NT 4.0.
You'll need to make sure to use binmode() on any filehandles you use for
reading or writing data in that format.
------------------------------
Date: Thu, 18 Mar 1999 14:58:04 GMT
From: latorre69@arrakis.es (miedo)
Subject: File test operator for modification/access time.
Message-Id: <36f11323@news.arrakis.es>
I want to know how many days a file was modificated/accessed ago, but
using the operator -M, I only got to know the days the file was
created ago, so I have to delete and create the file allways to know
the days the file wass accesed ago.
$date = -M "$file";
What is the problem?
Please reply to my email.
Thanks.
------------------------------
Date: Sat, 20 Mar 1999 08:57:37 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Filehandle Q...
Message-Id: <36f76090.2855550@news.skynet.be>
Larry Rosler wrote:
>> system("whois $domain >$out_file) && die "system(whois) failed $!";
>
>You mean "$?" (not "$!"). Force of habit, I guess.
I've always wondered why Perl has that many different different
variables to return an error message? It makes no sense. I know of:
$!
$?
$@
$^E
and I still may have missed a few.
Why?
Bart.
------------------------------
Date: Sat, 20 Mar 1999 06:11:59 -0500
From: Sean Phillips <seannln@bit-net.com>
To: Andrew Tipson <atipson@wesleyan.edu>
Subject: Re: help with perl and win98
Message-Id: <36F3827F.A0F8BF8B@bit-net.com>
Andrew -
What messages do you get when you try to run the script?
What do you mean by "...make this script work independantly"?
- Sean
Andrew Tipson wrote:
> urg- I can't seem to make the command line work in my Win98 version of
> perl-
> is there any way to make this script work independantly? It may be
> that my
> version just isn't cofigured properly, I'll check it again.
>
> Sean Phillips wrote:
>
> > Andrew -
> >
> > Here is a piece of code that I have used to do a similar task. It
> > wouks UNIX, NT and 95 - I have not tried it on 98...
> >
> > In this form, it works from the command line as
> > "perl cgigetdoc.pl http://www.slashdot.com/ultramode.txt"
> > But I'm sure that you can modify it to your liking...
> >
------------------------------
Date: Sat, 20 Mar 1999 00:18:15 GMT
From: nospam@here.com
Subject: Re: Here 's a good one !!!
Message-Id: <36f2e90e.1160008@mars.dsu.edu>
If you're using NT you can set a buffer size for your command prompt
window. Then all you have to do is scroll up to your first error.
On Sun, 14 Mar 1999 19:47:02 -0800, lr@hpl.hp.com (Larry Rosler)
wrote:
>In article <comdog-ya02408000R1403991724100001@news.panix.com> on Sun,
>14 Mar 1999 17:24:10 -0500, brian d foy <comdog@computerdog.com >says...
>> In article <7chaap$7da$1@ionews.ionet.net>, "Travis" <Travis@wildboysnet.com> posted:
>> > when using the -w on code I often get a screen full of errors due to the
>> > fact that I forgot an
>> > quotation mark somewhere ( on a print statement ) . Anyone know how the
>> > errors can be saved to a file so
>> > you can read the first offending error ?
>>
>> why save it to a file?
>>
>> perl -cw script_name | more
>
>Doesn't this pipe STDOUT to 'more'? The perl diagnostics are written to
>STDERR, which goes straight to the terminal unless redirected.
>
>--
>(Just Another Larry) Rosler
>Hewlett-Packard Company
>http://www.hpl.hp.com/personl/Larry_Rosler/
>lr@hpl.hp.com
------------------------------
Date: Thu, 18 Mar 1999 12:37:08 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How do I split an list of text into separate lists of paragraphs
Message-Id: <x3yaexa8zst.fsf@tigre.matrox.com>
jbritain@home.com (Jim Britain) writes:
> That's fine for file processing, but how do you apply it for array
> processing? Remember, the text is already stored in @abstracts
I'm sure there's more than one way to do it. Here's one:
my @abstracts; # this contains all lines in the file
my @paragraphs;
my $i = 0;
my $line;
while ($line = shift @abstracts) {
if ($line =~ /^\s*$/) {
$i++;
} else {
$paragraphs[$i] .= $line;
}
}
Note: This will create a sparse array if you have multiple consecutive
empty lines. The fix is left as an exercise.
HTH,
Ala
------------------------------
Date: Thu, 18 Mar 1999 16:00:26 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to let users of website know there are others present
Message-Id: <MPG.115b3374d1475b8e989781@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36f18b11$0$26630@newton> on Fri, 19 Mar 1999 00:28:56 +0100,
Carlo <news@ntt.nl> says...
...
> on.pl loads whenever someone enters the site and upps a counter
> off.pl loads on an unload event when someone closes the browser or goes to
> another page and lowers the counter.
Except for issues of file locking, you are asking in the wrong
newsgroup.
But for your general edification: There is no such thing as an 'unload
event'. The server has no way of knowing 'when someone closes the
browser or goes to another page'. The only way it could know would be
if your users submitted an 'unload' action explicitly first. But you
know that they're not going to do that, so don't expect it!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 20 Mar 1999 08:57:44 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Input for PERL Course request
Message-Id: <36f96241.3281878@news.skynet.be>
David H. Adler wrote:
>>aspect of Tim Christiansen's Camel reviews is reading the ones where he
> ^^^
>Hmm... Is he new? :-)
No. That's what his mother calls him.
;-)
Bart.
------------------------------
Date: Thu, 18 Mar 1999 12:53:17 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Need a one liner...
Message-Id: <x3y90cu8z1u.fsf@tigre.matrox.com>
John Safrit <safrit@mindspring.com> writes:
> Is there a one-liner that will discard all lines except those between
> START and END tags? It is easy to discard everything between them:
>
> perl -ne 'print unless /^START$/../^END$/' file.txt
>
> But to keep all lines between seems impossible. Any ideas? It must not
> include the tags themselves...
Either you must be kidding, or I am missing something!
What's wrong with:
% perl -ne 'print if /^START$/../^END$/' file.txt
??
------------------------------
Date: Sat, 20 Mar 1999 08:57:33 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Need Faster Approach
Message-Id: <36f6605c.2804195@news.skynet.be>
frogsmock@my-dejanews.com wrote:
>what I'm hoping for is a faster way (impossible?) to get to the 75,000th item
>instead of splitting off each preceding item.
If the data file is pretty much constant (to be used several times), one
line per entry, it is quite easy to create an index file. Something
like:
open(FILE,$datafile) or die "blah $!";
open(INDEX,">$indexfile") or die "blah $!"; binmode INDEX;
my $seek = 0;
while(<IN>) {
print OUT pack('V', $seek);
} continue {
$seek = tell(FILE);
}
close FILE; close INDEX;
There. One (4 byte) long per line.
Get the 75000th entry and the 49 following it, like this:
print getNthLinePlus(74999,50); # first is number 0
sub getNthLinePlus {
my($index,$wanted) = @_;
local(*FILE, *INDEX, $_);
local $/ = "\n";
open(FILE,$datafile) or die "blah $!";
open(INDEX,$indexfile) or die "blah $!"; binmode INDEX;
my $offset;
seek INDEX, 75000 * 4,0;
read INDEX, $offset, 4;
seek FILE, unpack('V',$offset), 0;
my $count = 0;
my @lines;
while (<FILE>) {
push @lines, $_;
last if ++$count >= $wanted;
}
return @lines;
}
(Note: code not tested in current status)
Bart.
------------------------------
Date: Thu, 18 Mar 1999 12:59:34 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Newbie question about form to mail program
Message-Id: <x3y7lse8yre.fsf@tigre.matrox.com>
buumzer@my-dejanews.com writes:
> @ is a special character in (some) perl interpreters. Try a backslash in
> front of it.
@ is special in "some Perl interpreters" ? How many interpreters are
there? Could you count them for me please? In which ones is @ special?
Do you have any idea what you're talking about?
Inside a single quoted string (like the one in the original poster's
question), @ is NOT special. There is nothing wrong with his hash
declaration.
> > Also is this syntax correct?
> >
> > %alias = ( 'myemail' => 'dbrotman@hotmail.com');
Why don't people read some docs before posting?
Life would be a better place.
Ala
------------------------------
Date: Sat, 20 Mar 1999 14:18:02 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: Perl Excel OLE
Message-Id: <36f494b5.16916474@news3.ibm.net>
[mailed & posted]
dstanky@my-dejanews.com wrote:
>I need assistance opening an .xls file in ReadOnly mode in Perl. The .xls
>file was saved password protected - as a result everytime I use Perl to open
>the file I receive an Enter password or ReadOnly dialog box. I would some
>how like Perl to just open the file in ReadOnly mode from the begining
>avoiding the dialog box.
use strict;
use Win32::OLE;
my $Excel = Win32::OLE->new('Excel.Application');
my $Book = $Excel->Workbooks->Open({
FileName => 'i:\tmp\ole\test.xls',
ReadOnly => 1
});
-Jan
------------------------------
Date: Thu, 18 Mar 1999 16:35:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: PERL Text Handling
Message-Id: <MPG.115b3b9434ebcac6989783@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7cs3ao$ii2$1@nnrp1.dejanews.com> on Thu, 18 Mar 1999
23:47:40 GMT, jtreyes@mindspring.com <jtreyes@mindspring.com> says...
> I'm need some advice with basic Perl test manipulation. I'm unable to detemine
> how to concatenate strings. For instance, I'm using the command
> "$line+=$onechar;", but the result is a number not two characters. Any help
> would be appreciated.
+= means 'add'; .= means 'concatenate'. perldoc perlop.
> #!/usr/bin/perl
Where is '-w'? Where is 'use strict;'?
> $INFILE="input.txt";
> $OUTFILE="output.txt";
Single quotes are better when no interpolation.
> open (IN, "< $INFILE");
> open (OUT, "> $OUTFILE");
Where are your tests for failure to open these files?
> while (!eof(IN)){
Indent this loop body also (as you did the enclosed loop).
> $charascii=0;
> $line="";
> $onechar="";
>
> while ($charascii!=10) {
> $line+=$onechar;
> $onechar=getc(IN);
> $charascii=ord($onechar);
>
> }
This is an extremely poor way to read a line! (The 10 is the "\n"
character, folks!) Replace all of this (including the while...eof which
is almost never the right way to handle input) with:
while ($line = <IN>) {
> $header=substr($line,1,1);
I hope you realize that this extracts the *second* character of the
line.
> if ($header="=" or $header="-") {
'=' means assignment. Did you mean string comparison? Use 'eq'. (And
use '-w' to point these things out!
> print OUT "$line\n";
> print "$line\n";
If done right, $line will still have its "\n".
> }
>
> }
>
> close 1;
> close 2;
What are '1' and '2'? You may mean IN and OUT.
I hope you have bought 'Learning Perl' and are reading it cover-to-
cover!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 20 Mar 1999 11:40:16 +0100
From: William Blasius #42722 <Wm.Blasius@ks.sel.alcatel.de>
Subject: problem with fnctl F_GETFL in Perlf5
Message-Id: <36F37B10.167EB0E7@ks.sel.alcatel.de>
I am trying to use the fcntl function to get and set the flags. I seem
to have found a problem with the usage from the Camel book. Code snip:
----
use strict;
use diagnostics;
use FileHandle;
use Fcntl;
sub getflags {
my $fh = shift;
$flags = fcntl $$fh, &F_GETFL, 0 or $flags = -1; # get fioctl
flags
return $flags;
}
my $flags = getflags(\*STDERR, "xyzzy");
print "flags are $flags\n";
----
This has the peculiar property that the unused argument(s) in @_ find
their way into the subroutine constructor and cause an error:
Argument "xyzzy" isn't numeric in entersub at
/tools/gnu/lib/perl/5.004/sparc-sun-sunos4.1.3/Fcntl.pm line 69
(#1)
(W) The indicated string was fed as an argument to an operator that
expected a numeric value instead. If you're fortunate the message
will identify which operator was so unfortunate.
The value returns seems to be correct and the error occurs only once. I
can get around it by leaving off the & before F_[S|G]ETFL. Is this some
problem with Fcntl, with the documentation, or with my understanding?
Regards,
Wm Blasius
---
...now I'm <wm.blasius@ks.sel.alcatel.de> - no matter what my mail
server says!
------------------------------
Date: Sat, 20 Mar 1999 17:01:39 +0800
From: Rollo Chan Ka Chun <kcchan@csis.hku.hk>
Subject: Remove HTML codes
Message-Id: <Pine.GSO.4.03.9903201658280.1492-100000@virtue.csis.hku.hk>
Dear All,
I would like to ask...how to use regular expression to remove all
HTML codes in a file?...For example...I can open a file...the content is
something like this:
<td valign=top align=center>Hello Ar...
<td valign=top> NORTH FORCE 5
<b>abc de</b> hello ar...
I want to convert them into:
Hello Ar...
NORTH FORCE 5
abc de hello ar...
How can I do that? Thanks for your help...
Regards,
Rollo
------------------------------
Date: Sat, 20 Mar 1999 09:28:59 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Remove HTML codes
Message-Id: <ebohlmanF8vzoB.82B@netcom.com>
Rollo Chan Ka Chun <kcchan@csis.hku.hk> wrote:
: Dear All,
: I would like to ask...how to use regular expression to remove all
: HTML codes in a file?...For example...I can open a file...the content is
: something like this:
You don't. You use HTML::Filter.
------------------------------
Date: Sat, 20 Mar 1999 18:04:38 +0800
From: Rollo Chan Ka Chun <kcchan@csis.hku.hk>
To: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Remove HTML codes
Message-Id: <Pine.GSO.4.03.9903201803370.28181-100000@virtue.csis.hku.hk>
Sorry that I can't use the HTML::Filter. Any other method?...Thanks...
Regards,
Rollo
On Sat, 20 Mar 1999, Eric Bohlman wrote:
> Rollo Chan Ka Chun <kcchan@csis.hku.hk> wrote:
> : Dear All,
>
> : I would like to ask...how to use regular expression to remove all
> : HTML codes in a file?...For example...I can open a file...the content is
> : something like this:
>
> You don't. You use HTML::Filter.
>
>
>
------------------------------
Date: 20 Mar 1999 12:19:58 GMT
From: "Michael Rau" <m-rau@gmx.de>
Subject: Re: Remove HTML codes
Message-Id: <7d03pe$as8$1@surz18.HRZ.Uni-Marburg.DE>
Rollo Chan Ka Chun schrieb in Nachricht ...
>Sorry that I can't use the HTML::Filter. Any other method?...Thanks...
Use STRIPHTML.PL (by t.christiansen).
I can mail it to you. Just give me a sign if you want to.
mr.
------------------------------
Date: Thu, 18 Mar 1999 10:16:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Removing white space.
Message-Id: <MPG.115ae2bb93fa2edb98977b@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <Pine.SO4.4.05.9903181224110.9371-100000@msatsun64.hns.com>
on Thu, 18 Mar 1999 12:29:02 -0500, Brahmdeep Jandir <bjandir@hns.com>
says...
> I am sure this has been asked at least a million times .... but please bear
> with me.
That is why you will find a discussion of it in perlfaq4: "How do I
strip blank space from the beginning/end of a string?"
> $text =~ s#^\s*(.*)\s*$#$1#;
> $text =~ s#(.*)\s*$#$1#;
>
> Will the two above statements remove the white space at the end of the
> string or not ??
> They do not for me ! Why ??
Because the greedy regexes (.*) eat up as much as they can, including
the white-space characters at the end, if any.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 18 Mar 1999 13:34:34 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: script or module to convert number to binary and back
Message-Id: <x3y4sni8x51.fsf@tigre.matrox.com>
"Theodore" <newsgroups@kidkaboom.frogspace.net> writes:
> I am wondering if there is a script or module that would convert number to
> binary form and back, and also do math with them... I am thinking of putting
> a text counter on my page that would display the number of hits in binary
> (It would tell you of course) kind of the same idea as teh roman numeral
> counter.
>From perlfaq4:
How do I convert bits into ints?
To turn a string of 1s and 0s like '10110110' into a scalar
containing its binary value, use the pack() function
(documented in the section on pack in the perlfunc manpage):
$decimal = pack('B8', '10110110');
Here's an example of going the other way:
$binary_string = join('', unpack('B*', "\x29"));
HTH,
Ala
------------------------------
Date: Thu, 18 Mar 1999 13:02:12 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Some Perl questions
Message-Id: <x3y677y8ymz.fsf@tigre.matrox.com>
brandtr@my-dejanews.com writes:
> print "What is your favorite scripting language? ";
> $language = <STDIN>;
> if($language eq "Perl")
> {
> print "Congratulations!\n";
> }
> else
> {
> print "You're doing it the hard way!\n";
> )
I hope you see that this will print:
"You're doing it the hard way!"
no matter what you type in.
------------------------------
Date: Thu, 18 Mar 1999 15:53:23 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Speeding up Multi Word Searches (Boolean OR)
Message-Id: <MPG.115b31d174f46a49989780@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7crsll$bqa$1@nnrp1.dejanews.com> on Thu, 18 Mar 1999
21:54:04 GMT, regnery@ix.netcom.com <regnery@ix.netcom.com> says...
...
> foreach $term (@terms) {
> if ($coname =~ /$term/i) {
> $termhits[$termcounter]++;
> $key = 'yes';
> $orhits++;
> }
> $termcounter++;
> }
...
> This works, but it's fairly slow (there are about 125,000 items in the flat
> file (which consists of names of companies), and the search often gets many
> uses per minute).
>
> Is there a more efficient way of doing multiple word boolean OR searches
> without having to go to an index?
Yes. There is one method (for perl 5.005) shown in perlfaq6: "How do I
efficiently match many regular expressions at once?", in which your
method is described as "extremely inefficient". Another way (for
earlier perls) that I have used with great success is this:
Create a regex *once* that is the OR of your terms, and use it with the
/o modifier in your loop over the data, so it doesn't get recompiled
each time. Thus:
my $regex = '\b(?:' . join('|' => map { quotemeta } @terms) . ')\b';
(You should use 'quotemeta' to obviate users inputting terms that would
produce a broken regex, and use '\b' to force full-word matches if that
is what you want.)
Then you can count the number of hits per line this way:
my $hits = 0;
++$hits while $coname =~ /$regex/gio;
> Thanks in advance for your help. You can post here or send me email, to
> regnery@ix.netcom.com.
Both. No philosophical problem for me :-).
I would be interested in knowing if this approach relieves your
efficiency problem.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Mar 1999 13:21:07 GMT
From: Nordstrom Walt <revjack@radix.net>
Subject: Text Wrapping without Text::Wrap
Message-Id: <7d07c3$fjs$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
Surely there is an elegant way to word-wrap a string of text without
resorting to the Text::Wrap module. I'm sure that it does a fine job,
but it seems to me that wrapping text at, say, 70 characters would
be a cinch. Yet, I find that I can't compose the code for it.
Has anyone ever coded their own text wrap routine successfully?
--
/~\ deign Pete cushion collectible Neal tetrahedra provoke Aaron SE
C oo humble monstrosity Freud blather widow persiflage bootleg celeb
_( ^) 1 , 0 0 0 , 0 0 0 m o n k e y s c a n ' t b e w r o n g
/___~\ http://3509641275/~revjack 03/20/99 08:19:03 revjack@radix.net
------------------------------
Date: Sat, 20 Mar 1999 08:57:42 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Which OS am I in
Message-Id: <36f8614c.3037187@news.skynet.be>
Stephen Montgomery-Smith wrote:
>> How can a perl program tell whether it is running under DOS
>> or UNIX?
>Ignore my question I just found $^O in the documentation.
I still think it's a valid question. Every Perl port has a different
name in $^O.
How can we quickly group them, so that we really now it is Unix(-like),
don't care if it's Linux or Solaris, or PC-line (Win32, OS2, DOS, ...)?
I for one don't really want to include *every* OS-name I could possibly
encounter.
Bart.
------------------------------
Date: Thu, 18 Mar 1999 12:25:19 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Why can't i create a file with >>$file?
Message-Id: <MPG.115b010eddba067e98977c@nntp.hpl.hp.com>
In article <F8t2K0.GLJ@igsrsparc2.er.usgs.gov> on Thu, 18 Mar 1999
19:38:22 GMT, Vince Wilding <vince_wilding@NOSPAMusgs.gov> says...
> Possibly a version problem.
What does that mean? There is nothing in the code that is version-
dependent.
> I seem to remember having this problem with a
> prior , trying to append to a non-existant file. Make surte the file exists
> before trying to append to it.
That is not necessary. The following is quoted from the description of
the 'open' function:
If the filename begins with '>>', the file is opened for appending,
again being created if necessary.
> I'm using build 513 (V 5.005_03), and your
> code works as expected.
Indeed.
> Poohba <poohba@io.com> wrote in message
> news:Pine.BSF.4.05.9903181406190.16980-100000@dillinger.io.com...
> > I am trying to append to a file and it won't append nor will it create the
> > file if it isn't there. Why? I am using:
> >
> > $file = "file.dat";
> > open (FILE, ">>$file") || die "Can't open $file: $!\n";
> > print FILE "print all of this junk\n";
> > close(FILE);
> >
> > I can't get it to open or append to file. Why?
That is a good diagnostic on the failure to open the file. What does it
report on STDERR? If for some reason you can't read STDERR, simply
print the diagnostic to STDOUT and exit.
Some possibilities are: no permission to write to an existing file; no
permission to create a file in the current directory; no space in the
file system.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 18 Mar 1999 13:55:36 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Why can't i create a file with >>$file?
Message-Id: <MPG.115b1633de42f42798977e@nntp.hpl.hp.com>
In article <36f85e31.707318930@news.ford.com> on Thu, 18 Mar 1999
20:14:59 GMT, Clinton Pierce <cpierce1@ford.com> says...
> On Thu, 18 Mar 1999 14:08:14 -0500, Poohba <poohba@io.com> wrote:
> >I am trying to append to a file and it won't append nor will it create the
> >file if it isn't there. Why? I am using:
> >
> >$file = "file.dat";
> >open (FILE, ">>$file") || die "Can't open $file: $!\n";
> >print FILE "print all of this junk\n";
> >close(FILE);
> >
> >I can't get it to open or append to file. Why?
>
> Of course you can't. That's Perl's job.
Well, if we're going to get picky about it, it's perl's job. Perl just
tells perl what to do.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 18 Mar 1999 16:21:59 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Windows NT Path Resolution
Message-Id: <MPG.115b387fc9af9041989782@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36F18AD8.94FB6D19@123uk.net> on Thu, 18 Mar 1999 23:23:04
+0000, David Twaddell <david@123uk.net> says...
> If I refer to a file with no path extension, eg. "textfile.db" then my
> script finds the file ok. But if I provide a path extension,
> "/cgi-bin/links/textfile.db", my script says that it cannot find the
> file. The file is definitely in the directory "/cgi-bin/links" and so I
> deduce that for some reason Perl and Windows NT is getting the paths
> confused somehow.
For an absolute path on Windows/DOS systems, you have to specify the
drive also. Thus 'c:/cgi-bin/links/textfile.db' or whatever. Good to
see you using forward-slashes, in any case!
> Please help me if you can. I am off to purchase the best book on Perl I
> can find tomorrow, but your expertise may save me some time!
The book probably wouldn't have helped with this question. :-)
> Appreciatively yours,
>
> David Twaddell
> begin:vcard
> n:Twaddell;David
Don't send these any more, please!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 19 Mar 1999 22:08:06 -0800
From: Jeff Zucker <jeff@vpservices.com>
To: Jerry Zhao <zzhao@execulink.com>
Subject: Re: XML::Parser - 'Objects' style
Message-Id: <36F33B46.626AB0BD@vpservices.com>
[posted and mailed]
Jerry Zhao wrote:
> I am having a hard time figuring out the 'Objects' style of the
> XML::Parser. ... A simple illustration of the usage would be
> greatly appreciated!
Here's a short example. You can also use Data::Dumper to examine the
return of the parse() to see what more complex xml produces. If anyone
has other examples or tips on using Objects style, I'd like to hear them
too.
#!/usr/local/bin/perl -w
use strict;
use XML::Parser;
my $objsParser = XML::Parser->new( Style => 'Objects' );
my $objs = $objsParser->parse("<phrase w1='hello' w2='world!'/>");
my $firstObj = $$objs[0];
print $firstObj->{w1}, " ", $firstObj->{w2}; # prints "hello world!"
__END__
--
Jeff Zucker Co-coordinator, UNICEF Voices of Youth
\/ http://www.unicef.org/voy/
-<>-
/\ CTO, Virtual Production Services LLC
jeff@vpservices.com http://www.vpservices.com/jeff/
------------------------------
Date: Sat, 20 Mar 1999 07:42:14 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: XML::Parser - 'Objects' style
Message-Id: <ebohlmanF8vuqE.217@netcom.com>
Jerry Zhao <zzhao@execulink.com> wrote:
: I am having a hard time figuring out the 'Objects' style of the XML::Parser.
: The manual says that "a hash object is created for each element", but how
: does one make use of (refrence) the objects? A simple illustration of the
: usage would be greatly appreciated!
If you're familiar with the "tree" style, you'll know that it creates an
array of pairs for each element in the document. For non-text elements,
the first member of the pair is the name of the element and the second
member is a reference to an array whose first member is a (possibly
empty) hash of attributes for the element and whose remaining members are
pairs for the element's children. For text elements, the first member is
the number 0 and the second element is the actual text.
The "objects" style works just like this, except that
1) The first member for a non-text element is a reference to an object in
the class named Pkg::Element, where Pkg is the package argument passed to
the parser and Element is the name of the element (as found in the start
tag).
2) The attribute hash is stored in the 'Kids' field of the object rather
than in the second member of the array.
3) The first member for a text element is a reference to the class named
Pkg::Characters, where Pkg is as above and 'Characters' is a literal
name. The text is stored in the 'Text' field of the object, and there is
no second member.
It might be instructive to use the "objects" style to parse a short
document and use Data::Dumper to print out the results. It might also
help to look at the code for XML::Parser and compare the code for the
"tree" and "objects" styles; there's very little difference. Finally, it
might also help to join the Perl-XML mailing list; go to
<URL:http://www.activestate.com/support/> for details (despite the fact
that ActiveState hosts the list, the list's topics are *not* primarily
about Win32 systems. Such luminaries as Larry Wall, James Clark, Tim Bray
and David Megginson hang out there).
------------------------------
Date: Sat, 20 Mar 1999 07:53:58 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: XML::Parser - 'Objects' style
Message-Id: <ebohlmanF8vv9y.2up@netcom.com>
Eric Bohlman <ebohlman@netcom.com> wrote:
Oops, a couple errors here:
: The "objects" style works just like this, except that
: 1) The first member for a non-text element is a reference to an object in
: the class named Pkg::Element, where Pkg is the package argument passed to
: the parser and Element is the name of the element (as found in the start
: tag).
The attributes are stored as fields of the object.
: 2) The attribute hash is stored in the 'Kids' field of the object rather
: than in the second member of the array.
Actually, the element's content (what would have been stored in the
second array member) is stored in the 'Kids' field. There is no second
member.
: 3) The first member for a text element is a reference to the class named
: Pkg::Characters, where Pkg is as above and 'Characters' is a literal
: name. The text is stored in the 'Text' field of the object, and there is
: no second member.
IOW, each element corresponds to one array entry for both text and
non-text elements. Sorry about the confusion.
------------------------------
Date: Thu, 18 Mar 1999 12:29:39 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: || vs "or"
Message-Id: <MPG.115b020c9e97001c98977d@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <Pine.GSO.4.05.9903181438550.27602-
100000@mamba.cs.Virginia.EDU> on Thu, 18 Mar 1999 14:41:02 -0500, David
Coppit <dwc3q@mamba.cs.Virginia.EDU> says...
>
> Why does the following print "1,"? I thought they were equivalent except
> for precedence, and it doesn't seem like precedence is a factor here.
It is. Very much!
> $a = '' || 1;
> $b = '' or 2;
>
> print "$a,$b\n";
$a = ('' || 1);
($b = '') or 2;
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 18 Mar 1999 14:00:56 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: || vs "or"
Message-Id: <MPG.115b17706e06f49998977f@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36f162b8.10668522@news.skynet.be> on Thu, 18 Mar 1999
20:33:14 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> David Coppit wrote:
> >Why does the following print "1,"? I thought they were equivalent except
> >for precedence, and it doesn't seem like precedence is a factor here.
> >
> >---------------------------
> >$a = '' || 1;
> >$b = '' or 2;
>
> You must realize that "=" has a LOWER precedence than "or". So "$b = ''"
> (that's false) makes "2" to be evaluated. Since there is no side effect,
> nothing spectacular happens. $b is still an empty string.
You mean a HIGHER precedence. The assignment ('=') happens before the
disjunction ('or') -- it *precedes* it.
Note that the '-w' flag sheds a lot of light on this snippet. Maybe the
problem wouldn't have been posted in the first place.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 5185
**************************************