[11690] in Perl-Users-Digest
Perl-Users Digest, Issue: 5290 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 3 11:05:19 1999
Date: Sat, 3 Apr 99 08:00:31 -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, 3 Apr 1999 Volume: 8 Number: 5290
Today's topics:
Re: Brief questions about Module File:: <gellyfish@gellyfish.com>
Copy from Perl? <computerguru@mailexcite.com>
Re: Copy from Perl? (Kim Saunders)
Re: Copy from Perl? (Bob Trieger)
Re: Copy from Perl? <jdf@pobox.com>
Re: Copy from Perl? (Larry Rosler)
Re: Getting user last login time and date from perl <gellyfish@gellyfish.com>
Re: Help! Perl5 Regex \b problem!? (Tad McClellan)
Re: Help! (Peter L. Berghold)
Help-Perl Usergroups (Tony )
Re: Help: require() doesn't work under WIN95 (Larry Rosler)
Re: Help: require() doesn't work under WIN95 <gellyfish@gellyfish.com>
Re: How to include code to the script from other file? (Damon61)
Re: How to set the Printer fonts using perl? smnayeem@my-dejanews.com
Re: How to set the Printer fonts using perl? <gellyfish@gellyfish.com>
is there any ceiling function in perl? agniora@usa.net
Re: is there any ceiling function in perl? <jdf@pobox.com>
Re: is there any ceiling function in perl? smnayeem@my-dejanews.com
Re: is there any ceiling function in perl? (Larry Rosler)
Re: is there any ceiling function in perl? <jdf@pobox.com>
Re: is there any ceiling function in perl? <skilchen@swissonline.ch>
Re: Modifying a File <account@asiamake.com>
Re: Modifying a File <account@asiamake.com>
Re: Modifying a File (Bob Trieger)
Perl Question for generating HTML cjsub@hotmail.com
Re: Perl Question for generating HTML <ffchopin@worldnet.att.net>
Pls help... regex to recognise a phone number. (Kim Saunders)
Pls help... regex to recognise a phone number. (Kim Saunders)
Reading /proc/meminfo using split /:/ <gavin@optus.net.au.dontspam.myass>
Re: Reading /proc/meminfo using split /:/ <gellyfish@gellyfish.com>
ReadParse library - Output not in same sequence as inpu rajesh_bhave@my-dejanews.com
Re: ReadParse library - Output not in same sequence as <flavell@mail.cern.ch>
Re: simple request/question (Ronald J Kimball)
Re: Very large regular expressions (Ronald J Kimball)
Re: Why Perl does this... (Ronald J Kimball)
WWW::Search problem pmwhelan@my-dejanews.com
WWW::Search problem pmwhelan@my-dejanews.com
WWW::Search problem pmwhelan@my-dejanews.com
www::Search pmwhelan@my-dejanews.com
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Apr 1999 15:19:12 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Brief questions about Module File::
Message-Id: <7e5bhg$5ir$1@gellyfish.btinternet.com>
On Sat, 03 Apr 1999 02:36:50 GMT sstarre@my-dejanews.com wrote:
> Just two multi-part questions please:
>
> (1) What is "syscopy()"? I don't see it in Camel. Is it part of perl? Would it
> be preferable to use it vs. File::Copy?
>
I assume that it is a system library function that causes the copying
to be done by some lower-level mechanism than would normally be the case.
If you are not on either of the named OS then you neednt concern yourself
about it I guess.
> (2) Assuming that I'm using File::Copy (which I am) I wonder- does it behave
> "safely"? If the copy fails for any reason (collision with another user,
> process terminated, etc.) will it NOT do the copy? In other words does it
> complete either (a) correctly, or (b) without disturbing the destination?
>
I would suggest no more or less safe than 'cp' or 'COPY' or on your system.
If a copying process is terminated that thats it - copying will stop at the
point that the termination took place unless you are on a system with some
fancy file system that could 'rollback' incomplete file I/O and the majority
of systems dont have this facility.
Concurrent access is also at the mercy of the way in which your system
works.
/J\
--
Jonathan Stowe <jns@gellyfish.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: Sat, 3 Apr 1999 09:49:41 -0500
From: "Computer Guru Consulting" <computerguru@mailexcite.com>
Subject: Copy from Perl?
Message-Id: <923151102.164.25@news.remarQ.com>
Hello
I have a simple(?) question...
I am trying to copy the contenys of test.txt to test.dat...
In unix I simply do this
cp test.txt test.dat
How do I do this in Perl? Thanks
--
Computer Guru Consulting
Bringing your business to the world
http://www.cguru.com
------------------------------
Date: Sat, 03 Apr 1999 15:01:53 GMT
From: kims@tip.net.au (Kim Saunders)
Subject: Re: Copy from Perl?
Message-Id: <37062cad.40096858@news.apex.net.au>
>I am trying to copy the contenys of test.txt to test.dat...
>In unix I simply do this
>cp test.txt test.dat
Use the sytsem function to do same???
system('cp test.txt test.dat');
Or maybe open it, and write it to something else?
open FILE "<test.txt";
$filetext = <FILE>;
close FILE;
open FILE ">test.dat";
print FILE $filetext;
close FILE;
------------------------------
Date: Sat, 03 Apr 1999 15:05:47 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Copy from Perl?
Message-Id: <7e5al1$5ph$1@birch.prod.itd.earthlink.net>
"Computer Guru Consulting" <cguru@hotpop.com> wrote:
o>I am trying to copy the contenys of test.txt to test.dat...
o>In unix I simply do this
o>cp test.txt test.dat
o>How do I do this in Perl? Thanks
perldoc File::Copy
perldoc -f system
Good luck
Bob Trieger
sowmaster@juicepigs.com
------------------------------
Date: 03 Apr 1999 10:18:38 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: kims@tip.net.au (Kim Saunders)
Subject: Re: Copy from Perl?
Message-Id: <m31zi1ybox.fsf@joshua.panix.com>
kims@tip.net.au (Kim Saunders) writes:
> >I am trying to copy the contenys of test.txt to test.dat...
> >In unix I simply do this
> >cp test.txt test.dat
>
> Use the sytsem function to do same???
>
> system('cp test.txt test.dat');
That's not portable.
> Or maybe open it, and write it to something else?
>
> open FILE "<test.txt";
That won't compile. You probably mean
open FILE, "<test.txt";
and you should mean
open FILE, "<test.txt" or die "Can't open test.txt for read: $!\n";
> $filetext = <FILE>;
> close FILE;
You've just read the first line of test.txt and thrown the rest away.
A portable and correct solution might read
use File::Copy;
copy( 'test.txt', 'test.dat' );
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sat, 3 Apr 1999 07:49:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Copy from Perl?
Message-Id: <MPG.116fd846dced0aa0989826@nntp.hpl.hp.com>
In article <37062cad.40096858@news.apex.net.au> on Sat, 03 Apr 1999
15:01:53 GMT, Kim Saunders <kims@tip.net.au >says...
> >I am trying to copy the contenys of test.txt to test.dat...
> >In unix I simply do this
> >cp test.txt test.dat
>
> Use the sytsem function to do same???
>
> system('cp test.txt test.dat');
What if this fails for some reason? How will you know?
> Or maybe open it, and write it to something else?
>
> open FILE "<test.txt";
This is not correct syntax. Even if it were, what if this fails for
some reason? How will you know?
> $filetext = <FILE>;
Dare one suppose that he wants to copy the entire file, not just the
first line?
> close FILE;
>
> open FILE ">test.dat";
This is not correct syntax. Even if it were, what if this fails for
some reason? How will you know?
> print FILE $filetext;
Dare one suppose that he wants to copy the entire file, not just the
first line?
> close FILE;
It is *very* bad policy to post any code here -- no matter how trivial
it seems -- without testing that it compiles and then produces
reasonable results.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Apr 1999 15:07:14 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Getting user last login time and date from perl
Message-Id: <7e5ar2$5ie$1@gellyfish.btinternet.com>
On 1 Apr 1999 06:10:48 GMT Tony Keating wrote:
>
> Is there a way to easily get the last login time and date of a user on the
> system directly from perl? Or do I have to run finger and extract the
> relevent data?
>
Just for fun of course here is a barebones example of 'lastlog' that would
work on *my* system
(Linux gellyfish 2.2.0 #3 Sat Mar 13 15:43:01 GMT 1999 i686 unknown)
#!/usr/bin/perl -w
use strict;
my $lastlog = '/var/log/lastlog';
open(LASTLOG,$lastlog) || die "Cant open $lastlog - $!\n";
my $record;
my $uid = getpwnam($ARGV[0]) ;
my $counter = 0;
while(read(LASTLOG,$record,32))
{
my ($time,$line,$host) = unpack "L A12 A16", $record;
print scalar(localtime($time))," $line $host\n" if ($counter == $uid);
$counter++;
}
close LASTLOG;
The more observant reader will notice that I havent used the OFFSET
argument to read but have counted the records instead - for some reason
I couldnt get it to work right and got bored trying to work it out.
For some other systems it might be necessary to check /usr/include/lastlog.h
to find the format of the records in the 'lastlog' file. Indeed on some
systems it may not exist at all and you will have to grovel through
wtpm instead - I seem to recall posting something that did that a short
while ago. Of course if you are not on a Unix like system at all then all
bets are off.
/J\
--
Jonathan Stowe <jns@gellyfish.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: Fri, 2 Apr 1999 21:37:01 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help! Perl5 Regex \b problem!?
Message-Id: <dsu3e7.sbg.ln@magna.metronet.com>
stuart@mohawk.net wrote:
: I am having trouble getting the following regex to work.
: For example:
: foo and bar or nil
: should become:
: special=foo and special=bar or special=nil
: The original solution I was shown:
: $my_str = "foo bar nil";
: $spec_word = "special";
: $my_str =~ s/(\b(?!and\b|n?or\b)\S+(?:\s|$))/$spec_word=$1/gi;
^^ ^^
: works great until one of the non-booleans is preceeded by punctuation. For
: example:
: foo and 'bar or nil
: becomes:
: special=foo and 'special=bar or special=nil
: I've been over the "lookahead" and "non-capturing" parens part of Friedl's
: great "Mastering Regular Expressions" (ISBN 1-56592-257-3)but I can't spot
: the problem.
See "Word Boundaries (p14), which talks about egrep's version
of Perl's \b.
In egrep you get one way to match the (null) space between
\w\W and another way for \W\w.
In Perl, \b is used for both.
/b cannot match between /W/W (where the 2nd one would be
your single quote char).
: Does anyone have any ideas how to get this regex to treat the
: punctuation as part of the key word? Thanks aplenty!
$my_str =~ s/('?\b(?!and\b|n?or\b)\S+(?:\s|$))/$spec_word=$1/gi;
^^
But that only works for one punctuation character, so:
$my_str =~ s/([^\s\w]?\b(?!and\b|n?or\b)\S+(?:\s|$))/$spec_word=$1/gi;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 03 Apr 1999 15:03:40 GMT
From: Peter@Berghold.Net (Peter L. Berghold)
Subject: Re: Help!
Message-Id: <g5qN2.1637$qy5.1067@news.rdc1.nj.home.com>
In article <37015470.AC836BC8@mail.nwos.lucent.com>,
fuchin@mail.nwos.lucent.com says...
>
>Does anyone know how to set uid in Perl?
>e.g. How can I set the user id to root while the perl process is ran by
>other uid and get the permission to change the permission of the files
>which are owned by root.
>Then uid can be changed back to continue running the rest of the script?
>
There are a couple of ways of skinning this cat. The easiest that I know of is
to create a "wrapper" program that does the SUID stuff using the setuid system
call and has its permissions set for SUID. The wrapper then in turn executes
the perl script using the exec() or system() system calls.
What you are describing is slightly different. I'd suggest you look into a
program called "sudo." This allows you to execute single commands as root and
also provides loggin of its use by who used it and what command they executed.
The configuration of sudo also sets up lists of who can and cannot execute sudo
and on what system(s).
--
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Peter L. Berghold Peter@Berghold.Net
"Linux renders ships http://www.berghold.net
NT renders ships useless...." ICQ# 11455958
------------------------------
Date: 3 Apr 1999 13:37:02 GMT
From: tonyd@aracnet.net (Tony )
Subject: Help-Perl Usergroups
Message-Id: <7e55hu$b17$1@charlotte.aracnet.net>
Can someone direct me to a group where I can post some of my job openings for
Perl Web Masters. The openings I have currently are in Toronto Canada. I have
heard that there is a Usergroup called Perl Mongerers (not sure of the
spelling) Help in these two areas would really be appreciated.
Thank You!
------------------------------
Date: Fri, 2 Apr 1999 22:23:13 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help: require() doesn't work under WIN95
Message-Id: <MPG.116f53a493b8cb1d989822@nntp.hpl.hp.com>
In article <7e454d$g0p$1@bgtnsc02.worldnet.att.net> on Fri, 2 Apr 1999
23:16:52 -0500, Jason Simms <ffchopin@worldnet.att.net >says...
> > I'm trying to write a utility file that I will include in other files.
> > I tried using require 'util.pl', but I continually get the error
> > "util.pl did not return a true value". If anyone knows why, I would be
> > grateful for their help.
>
> Some guy was aking this earleir in the week. You can say:
>
> return 1;
No, you cannot, because 'return' is meaningful only within a subroutine.
The use of the word 'return' in the diagnostic is ambiguous. It is
intended to mean "The value of the last expression evaluated during
execution of the file must be TRUE."
> or even:
>
> 1; (I think)
>
> at the very end of the include file and it should work fine.
Yes, that works fine (if you put a # between the ; and the ( :-).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Apr 1999 12:02:59 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Help: require() doesn't work under WIN95
Message-Id: <7e501j$1lj$1@gellyfish.btinternet.com>
[The deceased and now probably very smelly comp.lang.perl removed ]
In comp.lang.perl.misc matthew <erlermf@skypoint.com> wrote:
> I'm trying to write a utility file that I will include in other files.
> I tried using require 'util.pl', but I continually get the error
> "util.pl did not return a true value". If anyone knows why, I would be
> grateful for their help.
You have to have:
'I am the spirit of hell fire';
as the last executable line in your required file.
/J\
--
Jonathan Stowe <jns@gellyfish.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: 3 Apr 1999 06:27:13 GMT
From: damon61@aol.com (Damon61)
Subject: Re: How to include code to the script from other file?
Message-Id: <19990403012713.10738.00001927@ng13.aol.com>
There are a few ways do to this. One way is:
require "filename";
at the top of the program.
Damon
>From: Sergei Gnezdov <sergeiga@hotpop.com>
>Date: Fri, Apr 2, 1999 19:57 EST
>Message-id: <37056795.77A10CD9@hotpop.com>
>
>I want to decrease the size of the script file, so I want to use
>something like #include in C. How can I do this?
>
>Thank you
------------------------------
Date: Sat, 03 Apr 1999 06:40:48 GMT
From: smnayeem@my-dejanews.com
Subject: Re: How to set the Printer fonts using perl?
Message-Id: <7e4d5f$uqt$1@nnrp1.dejanews.com>
In article <7e44nj$ed8$1@bgtnsc02.worldnet.att.net>,
"Jason Simms" <ffchopin@worldnet.att.net> wrote:
> > Hi fellas, Is there any ways to change the default text font when writing
> > plain text files in perl? cuz usually the font that it prints gets really
> big
> > and then i cant use perl to create nice-looking reports or invoices.
> thanks
> > in advance. Nayeem Programmer, Agni Systems Ltd.
>
> Unless I'm really missing something, plain text files means just that -
> plain, ascii text. Without more information on exactly what you're trying
> to do (i.e., you mention printing in your header but use an ambiguous
> reference to printing in the body), I can't be of much help. Do you want to
> actually print the document to a printer, or just are wondering if you can
> change the font that the text file gets output in? If it is the later, then
> no, I don't think so, as Perl will write it in plain ASCII text. And what
> do you mean by "the font gets really big..."? As in, going from 9 pt. to 12
> pt. to 14 pt., etc.? Please be more specific, and please stop using CUZ...
>
> Jason Simms
>
>
what i mean is if there is any way that i can use perl to change the default
font of the printer and use/access any of the other built-in fonts. I am using
a HP6MP printer.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 3 Apr 1999 11:09:33 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to set the Printer fonts using perl?
Message-Id: <7e4std$1gd$1@gellyfish.btinternet.com>
On Sat, 03 Apr 1999 06:40:48 GMT smnayeem@my-dejanews.com wrote:
> what i mean is if there is any way that i can use perl to change the default
> font of the printer and use/access any of the other built-in fonts. I am using
> a HP6MP printer.
You gets out the manual for your printer and looks up the appropriate
codes to cause the printer to change the font. The printer that you have
supports Postscript so you will probaby want to be outputting that.
A way that I use that is printer independent is to output nroff marked up
text and post-process that with some troff-alike before printing usually
in a pipe. But I guess that you're going to say that you are NT and dont
have the ability to do that - well its to the manuals.
I did start work on a module in my last job that would have made this easier
but I left the job before I finished and I dont have a printer here.
/J\
--
Jonathan Stowe <jns@gellyfish.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: Sat, 03 Apr 1999 06:07:31 GMT
From: agniora@usa.net
Subject: is there any ceiling function in perl?
Message-Id: <7e4b6v$t41$1@nnrp1.dejanews.com>
does anyone know if theres any ceiling function in perl that would round up
decimal numbers to the integer.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 03 Apr 1999 01:47:44 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: agniora@usa.net
Subject: Re: is there any ceiling function in perl?
Message-Id: <m3wvzuw67j.fsf@joshua.panix.com>
agniora@usa.net writes:
> does anyone know if theres any ceiling function in perl that would
> round up decimal numbers to the integer.
See perlfaq4, "Does perl have a round function? What about ceil() and
floor()? Trig functions?"
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sat, 03 Apr 1999 08:26:31 GMT
From: smnayeem@my-dejanews.com
Subject: Re: is there any ceiling function in perl?
Message-Id: <7e4jbi$499$1@nnrp1.dejanews.com>
In article <7e4b6v$t41$1@nnrp1.dejanews.com>,
agniora@usa.net wrote:
> does anyone know if theres any ceiling function in perl that would round up
> decimal numbers to the integer.
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
>
By the way, i already checked the faq and cpan, i will require the posix.pm
module, but i cant seem to find the winNT version of posix.pm.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 2 Apr 1999 23:14:36 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: is there any ceiling function in perl?
Message-Id: <MPG.116f5faee35cf21989823@nntp.hpl.hp.com>
In article <7e4b6v$t41$1@nnrp1.dejanews.com> on Sat, 03 Apr 1999
06:07:31 GMT, agniora@usa.net <agniora@usa.net >says...
> does anyone know if theres any ceiling function in perl that would round up
> decimal numbers to the integer.
perlfaq4: "Does Perl have a round() function? What about ceil() and
floor()? Trig functions?"
But it seems easy enough just to write:
sub ceil { ($_[0] != int $_[0]) + int $_[0] }
Note to 'c.l.p.moderated' group (crosspost added to this thread):
According to a recent thread, it is apparently not documented that the
numeric value of a TRUE Boolean is 1, though I believe that is so in
every implementation. One can avoid the issue by writing one of these:
sub ceil { ($_[0] != int $_[0] ? 1 : 0) + int $_[0] }
sub ceil { ($_[0] != int $_[0] && 1) + int $_[0] }
But I don't think it should be necessary. In C, the TRUE value of a
Boolean is documented as 1. Why should Perl be worse than C?
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 03 Apr 1999 10:01:32 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: smnayeem@my-dejanews.com
Subject: Re: is there any ceiling function in perl?
Message-Id: <m34smxychf.fsf@joshua.panix.com>
smnayeem@my-dejanews.com writes:
> By the way, i already checked the faq and cpan, i will require the
> posix.pm module, but i cant seem to find the winNT version of
> posix.pm.
There is no "posix.pm". You must
use POSIX qw/ ceil floor /;
Capitalization counts.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sat, 3 Apr 1999 17:25:15 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: is there any ceiling function in perl?
Message-Id: <7e5c36$353$1@news.swissonline.ch>
Larry Rosler schrieb in Nachricht ...
>In article <7e4b6v$t41$1@nnrp1.dejanews.com> on Sat, 03 Apr 1999
>06:07:31 GMT, agniora@usa.net <agniora@usa.net >says...
>> does anyone know if theres any ceiling function in perl that would round
up
>> decimal numbers to the integer.
>
>perlfaq4: "Does Perl have a round() function? What about ceil() and
>floor()? Trig functions?"
>
>But it seems easy enough just to write:
>
>sub ceil { ($_[0] != int $_[0]) + int $_[0] }
>
Except that the result is wrong for negative numbers ...
what about:
sub myceil { $_[0] > 0 ? int($_[0] + 1) : int($_[0]) }
sub myfloor { $_[0] > 0 ? int($_[0]) : int($_[0] - 1) }
--
Samuel Kilchenmann
skilchen@swissonline.ch
------------------------------
Date: Sat, 03 Apr 1999 16:51:09 +0800
From: Alex <account@asiamake.com>
To: Jason Simms <ffchopin@worldnet.att.net>
Subject: Re: Modifying a File
Message-Id: <3705D67D.21EBC0C6@asiamake.com>
Dear Jason,
Thank you for your help. Please tell me the url of the FAQ
Thanks
Alex
------------------------------
Date: Sat, 03 Apr 1999 16:50:20 +0800
From: Alex <account@asiamake.com>
To: Jason Simms <ffchopin@worldnet.att.net>
Subject: Re: Modifying a File
Message-Id: <3705D64B.1301B16C@asiamake.com>
Dear Jason,
Thank you for your help. Please tell me the url of the FAQ
Thanks
Alex
------------------------------
Date: Sat, 03 Apr 1999 14:18:55 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Modifying a File
Message-Id: <7e57t4$2t9$3@birch.prod.itd.earthlink.net>
Alex <account@asiamake.com> wrote:
o>Dear Jason,
o>Thank you for your help. Please tell me the url of the FAQ
If you installed perl taking all the defaults, the FAQs are on your machine at
c:\perl\html\lib\pod or you can go to http://www.perl.com and follow the
links.
I suggest, you run not walk to your nearest book store and buy a copy of
"Learning Perl".
Good luck,
Bob Trieger
sowmaster@juicepigs.com
------------------------------
Date: Sat, 03 Apr 1999 05:55:31 GMT
From: cjsub@hotmail.com
Subject: Perl Question for generating HTML
Message-Id: <7e4agg$skt$1@nnrp1.dejanews.com>
I have been using perl for a few years to manipulate text files.
Now i want to start formatting my output into HTML docs.
Is the best way to do this using the Format Statement to create the misc
stuff at the top of my html doc ??
and then use the Format again for the body
and then use format a third time for my closing <\> tags ??
Any help or faq's will be greatly appreciated
thanks
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 3 Apr 1999 01:06:07 -0500
From: "Jason Simms" <ffchopin@worldnet.att.net>
Subject: Re: Perl Question for generating HTML
Message-Id: <7e4bi1$es7$1@bgtnsc02.worldnet.att.net>
<cjsub@hotmail.com> wrote in message news:7e4agg$skt$1@nnrp1.dejanews.com...
> I have been using perl for a few years to manipulate text files.
> Now i want to start formatting my output into HTML docs.
> Is the best way to do this using the Format Statement to create the misc
> stuff at the top of my html doc ??
> and then use the Format again for the body
> and then use format a third time for my closing <\> tags ??
> Any help or faq's will be greatly appreciated
Do you mean output an HTML file or CGI dynamic web content?
------------------------------
Date: Sat, 03 Apr 1999 14:03:52 GMT
From: kims@tip.net.au (Kim Saunders)
Subject: Pls help... regex to recognise a phone number.
Message-Id: <37061d1c.36111639@news.apex.net.au>
Hiya again everyone...
Me again, same plea for regex help. Can someone please help with with
a regex (and associated code) that will analyse a string, and every
time a phone number is in it, match, and print it?
Now, the bit that gets me is that this must recognise a number written
by a human. And humans write numbers in silly ways... I am trying to
get american numbers, which are in the format:
((+)1) (123) 456 7890
Of courses, the problems are that the numbers can be in varing
formats, with different puctuation, spaces in different places,
brackets, hyphens, pluses (for international number). Basically, I
thing if I can get something that will recognise a block of 7-16 or so
characters, with nothing but digits, spaces, hyphens, brackets, and
pluses, and at least 7 of them actual digits, I will be doing well. No
matter what I do, it won't be foolproof, but just a few simple ones
would be great to get me started.
Ideally, something that would need say at least two sets of pure
digits of length three or more would be great.
Anyway, thanks a lot all you folks, you are lifesavers...
KimS
------------------------------
Date: Sat, 03 Apr 1999 14:58:26 GMT
From: kims@tip.net.au (Kim Saunders)
Subject: Pls help... regex to recognise a phone number.
Message-Id: <37062c8c.40064100@news.apex.net.au>
Hiya again everyone...
Me again, same plea for regex help. Can someone please help with with
a regex (and associated code) that will analyse a string, and every
time a phone number is in it, match, and print it?
Now, the bit that gets me is that this must recognise a number written
by a human. And humans write numbers in silly ways... I am trying to
get american numbers, which are in the format:
((+)1) (123) 456 7890
Of courses, the problems are that the numbers can be in varing
formats, with different puctuation, spaces in different places,
brackets, hyphens, pluses (for international number). Basically, I
thing if I can get something that will recognise a block of 7-16 or so
characters, with nothing but digits, spaces, hyphens, brackets, and
pluses, and at least 7 of them actual digits, I will be doing well. No
matter what I do, it won't be foolproof, but just a few simple ones
would be great to get me started.
Ideally, something that would need say at least two sets of pure
digits of length three or more would be great.
Anyway, thanks a lot all you folks, you are lifesavers...
KimS
------------------------------
Date: Sat, 03 Apr 1999 08:33:32 GMT
From: Gavin Cato <gavin@optus.net.au.dontspam.myass>
Subject: Reading /proc/meminfo using split /:/
Message-Id: <923127887.1851898270@news0.optus.net.au>
Hello All,
newbie perl prob :-)
I'm trying to read /proc/meminfo on a linux system and grabbing the memto=
tal
field
I'm using
open(MEMORY, "<$memtotal");
while (<MEMORY>) {
if (/MemTotal/) {
$memtemp =3D(split/:/) [1];
print $memtemp;
}
}
The problem is - it prints the correct figure but with a bunch of spaces =
(or a
couple of tabs) in front of the figure. I can't work out a way to have it=
strip
off the whitespace in front of it natively with perl.
I worked around it nastily using
$memtemp =3D `echo $memtemp`;
chomp $memtemp;
Anyone know what I'm missing?
Cheers,
Gavin
------------------------------
Date: 3 Apr 1999 11:55:50 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Reading /proc/meminfo using split /:/
Message-Id: <7e4vk6$1l4$1@gellyfish.btinternet.com>
On Sat, 03 Apr 1999 08:33:32 GMT Gavin Cato wrote:
> Hello All,
>
> newbie perl prob :-)
>
> I'm trying to read /proc/meminfo on a linux system and grabbing the memtotal
> field
>
> I'm using
>
> open(MEMORY, "<$memtotal");
Always check the success of the open.
> while (<MEMORY>) {
> if (/MemTotal/) {
> $memtemp =(split/:/) [1];
you could use:
$memtemp = (split(/:\s+/))[1];
to get rid of the extra whitespace.
> print $memtemp;
> }
> }
>
Anyhow for some reason this tickled my fancy and as I needed to check if
the brain was still in gear and just for fun of course is a little thing
that will put the contents of /proc/meminfo into a couple of hashes for
later use:
#!/usr/bin/perl -w
use strict;
my $meminfo = '/proc/meminfo';
my %summary ;
my %detail = ();
open(MEMINFO,$meminfo) || die "Can't open $meminfo - $!\n";
my $categories = <MEMINFO>;
chomp $categories;
my @cats = ($categories =~ /(\w+):/g);
for ( 1 .. 2 )
{
my $index = 0;
my ($key,$values) = split /:/,<MEMINFO>;
my @value = split ' ', $values;
foreach (@value)
{
$summary{$key}->{$cats[$index++]} = $_;
}
}
my ($type,$blah);
foreach $type (keys %summary)
{
foreach $blah ( keys %{$summary{$type}} )
{
print "$type $blah $summary{$type}->{$blah}\n";
}
}
while(<MEMINFO>)
{
chomp;
if ( /^(\w+):\s+(\d+)/ )
{
$detail{$1} = $2;
}
}
foreach (keys %detail)
{
print "$_ $detail{$_}\n";
}
close MEMINFO;
I cannot guarantee that this will work on anything other than :
Linux gellyfish 2.2.0 #3 Sat Mar 13 15:43:01 GMT 1999 i686 unknown
However.
/J\
--
Jonathan Stowe <jns@gellyfish.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: Sat, 03 Apr 1999 13:11:32 GMT
From: rajesh_bhave@my-dejanews.com
Subject: ReadParse library - Output not in same sequence as input
Message-Id: <7e5422$gdf$1@nnrp1.dejanews.com>
Hello
I am using ReadParse library provided by Perl to get all the input
passed to the CGI script and display it on the HTML page. Since this
library uses associative array, so I am unable to get the output in the
same sequence in which input has to be given. Ofcourse, the (key, value)
pairs displayed are OK, but the order is random. Can somebody help me
out in this. I want the output in HTML to be displayed in same order as
the input.
Your help is highly appreciated.
Regards,
Rajesh Bhave
Extn: 1318
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 3 Apr 1999 16:51:29 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: ReadParse library - Output not in same sequence as input
Message-Id: <Pine.HPP.3.95a.990403163212.4296H-100000@hpplus01.cern.ch>
On Sat, 3 Apr 1999 rajesh_bhave@my-dejanews.com wrote:
> I am using ReadParse library provided by Perl to get all the input
> passed to the CGI script and display it on the HTML page.
Let's hope you're using the supported CGI.pm, rather than the old and
unsupported cgi-lib.pl
> Since this
> library uses associative array, so I am unable to get the output in the
> same sequence in which input has to be given.
Well, yes, but that's only part of the story. While it's true that the
HTML4.0 spec calls for the fields to be submitted in the same order that
they appeared in the HTML document, I don't recall there being any
guarantee of this ordering in earlier HTML specs, and I see no
particular benefit in relying on it. You may as well code your scripts
in such a way that it works with the fields in any order. And then
there won't be a problem.
> Ofcourse, the (key, value)
> pairs displayed are OK, but the order is random.
Of course, but when you query the value of the fields "FOO" and "BAR" it
doesn't matter whether "FOO" comes before or after "BAR" in the hash, so
where's the problem?
> I want the output in HTML to be displayed in same order as
> the input.
I'd recommend using CGI.pm to write the form in the first place, then
you know what order your fields are in, right there in the script, and
when the form is submitted, you can process the fields in the order that
you want them. Having CGI.pm write the form _and_ evaluate the
submission, using the same script for both invocations, is a very useful
technique, as you can then trivially detect missing or invalid
responses, re-display the form with the valid input re-entered as
default, and ask the customer to try again, without them needing to
re-answer questions that they'd already validly answered.
good luck
------------------------------
Date: Sat, 3 Apr 1999 02:49:06 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: simple request/question
Message-Id: <1dpnyr5.kuamc317b16f4N@p95.block1.tc5.state.ma.tiac.net>
David L. Cassell <cassell@mail.cor.epa.gov> wrote:
> my $total = 0; # assuming you 'use strict' as you ought to
> $total += $1 while ( /%7C([0-9.]+?)%5E/g )
The non-greedy quantifier is not needed. The character class [0-9.]
does not include the character '%'. :)
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 3 Apr 1999 02:49:07 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Very large regular expressions
Message-Id: <1dpnz0b.1uuzc3f1od83jaN@p95.block1.tc5.state.ma.tiac.net>
Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
> sub parse_form ($$\@) {
> my ($letter, $form, $keys) = @_;
> my ($n, $i, %hash) = 0;
> my @regex = map qr/^$_/xs, split /\n/, $form;
> foreach $regex (@regex) {
> return unless $letter =~ $regex;
> # Extract the contents of the capturing parentheses:
> for ($i = 1; defined $$i; $i++) {
> $hash{$keys->[$n++]} = $$i;
This won't work if you have capturing parentheses on different sides of
an alternative:
DB<1> $_ = 'bar'
DB<2> x /(foo)|(bar)/
0 undef
1 'bar'
DB<3>
You could assign the results of the match to a list instead:
return unless @matches = $letter =~ $regex;
$hash{$keys->[$i]} = $matches[$i] for $i (0 .. $#matches);
> }
> $letter = $';
Isn't this just another way of doing scalar(m//g)?
Although you can't use @matches = $letter =~ $regex and scalar(m//g) at
the same time... Pity.
> }
> \%hash;
> }
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
perl -e '$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Sat, 3 Apr 1999 02:49:10 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Why Perl does this...
Message-Id: <1dpnzpj.1pc1ue016744utN@p95.block1.tc5.state.ma.tiac.net>
PropART <propart@mediaone.net> wrote:
> But, it still seems weird to me that an array mentioned in a print
> statement *after* a sub-routine call which initializes the array, isn't
> automatically interpolated when double quotes are used.
The subroutine call happens at run-time. The print statement has to be
compiled at compile-time.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 03 Apr 1999 14:32:32 GMT
From: pmwhelan@my-dejanews.com
Subject: WWW::Search problem
Message-Id: <7e58q0$k2k$1@nnrp1.dejanews.com>
i found this code in a previous post for how to use
WWW::Search
my $query = param('query');
print header,start_html("Search results for $query");
my($search) = new WWW::Search('AltaVista');
$search->native_query(WWW::Search::escape_query($query));
my($result);
print "<UL>\n";
while ($result = $search->next_result()) {
print "<LI>\n",$result->url, "</LI>\n";
};
but when i call it in unix i get nothing!!!
csh> perl -w wic5.cgi query=foo
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Search results for foo</TITLE>
</HEAD><BODY><UL>
</UL>
</BODY></HTML>csh>
does anyone know why this is so?
thanks
paul whelan
pmwhelan@alf2.tcd.ie
print "</UL>\n",end_html;
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 03 Apr 1999 14:32:35 GMT
From: pmwhelan@my-dejanews.com
Subject: WWW::Search problem
Message-Id: <7e58q3$k2n$1@nnrp1.dejanews.com>
i found this code in a previous post for how to use
WWW::Search
my $query = param('query');
print header,start_html("Search results for $query");
my($search) = new WWW::Search('AltaVista');
$search->native_query(WWW::Search::escape_query($query));
my($result);
print "<UL>\n";
while ($result = $search->next_result()) {
print "<LI>\n",$result->url, "</LI>\n";
};
but when i call it in unix i get nothing!!!
csh> perl -w wic5.cgi query=foo
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Search results for foo</TITLE>
</HEAD><BODY><UL>
</UL>
</BODY></HTML>csh>
does anyone know why this is so?
thanks
paul whelan
pmwhelan@alf2.tcd.ie
print "</UL>\n",end_html;
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 03 Apr 1999 14:32:33 GMT
From: pmwhelan@my-dejanews.com
Subject: WWW::Search problem
Message-Id: <7e58q2$k2m$1@nnrp1.dejanews.com>
i found this code in a previous post for how to use
WWW::Search
my $query = param('query');
print header,start_html("Search results for $query");
my($search) = new WWW::Search('AltaVista');
$search->native_query(WWW::Search::escape_query($query));
my($result);
print "<UL>\n";
while ($result = $search->next_result()) {
print "<LI>\n",$result->url, "</LI>\n";
};
but when i call it in unix i get nothing!!!
csh> perl -w wic5.cgi query=foo
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Search results for foo</TITLE>
</HEAD><BODY><UL>
</UL>
</BODY></HTML>csh>
does anyone know why this is so?
thanks
paul whelan
pmwhelan@alf2.tcd.ie
print "</UL>\n",end_html;
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 03 Apr 1999 14:38:04 GMT
From: pmwhelan@my-dejanews.com
To: pmwhelan@alf2.tcd.ie
Subject: www::Search
Message-Id: <7e594c$k6p$1@nnrp1.dejanews.com>
i use this code as an example of www::Search
#!/usr/local/perl
use CGI qw(:standard);
use WWW::Search;
my $query = param('query');
print header,start_html("Search results for $query");
my($search) = new WWW::Search('AltaVista');
$search->native_query(WWW::Search::escape_query($query));
my($result);
print "<UL>\n";
while ($result = $search->next_result()) {
print "<LI>\n",$result->url, "</LI>\n";
};
print "</UL>\n",end_html;
but when i call it in unix
csh> perl -w wic5.cgi query=foo
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Search results for foo</TITLE>
</HEAD><BODY><UL>
</UL>
</BODY></HTML>csh>
where are the results????
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
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 5290
**************************************