[8390] in Perl-Users-Digest
Perl-Users Digest, Issue: 2007 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 3 08:07:40 1998
Date: Tue, 3 Mar 98 05:01:00 -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 Tue, 3 Mar 1998 Volume: 8 Number: 2007
Today's topics:
Re: "Learning Perl" or "Programming Perl" <zkessin@lhr-sys.dhl.com>
Re: "Or" Operator? (Abigail)
Re: a newbie regexp question (David Waring)
ActiveState Perl Debugger Beta 2 (PAF)
Re: ActiveState Perl Debugger Beta 2 (Tom Grydeland)
CGI Script problem (Mark Stevenson)
Re: CGI Script problem <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: Conflict in this Newsgroup <scott.kirk@liffe.com>
Re: Cookie question <kitfox@golden.net>
Email processor: Procmail - Mail::Tools - Other ? <Koos_Pol@bigfoot.com>
Extracting text from a logfile (Christopher Jowell)
Re: Formats and diamond operator <ebohlman@netcom.com>
Re: Help me out please! (Bart Lateur)
Re: Help: Seeking cgi and html libs... <Dave.Cross@gb.swissbank.com>
Re: mail header stripping <Tony.Curtis+usenet@vcpc.univie.ac.at>
Maintaining creation dates of files <alexs@online.emap.com>
Re: Maintaining creation dates of files <alexs@online.emap.com>
Module for multi-set manipulations (Thomas Rock)
My little puzzle (thanks). SPC@popstar.com
Re: Opening Files <jdf@pobox.com>
Re: Opening Files <uri@sysarch.com>
Perl Scripts made on demand <javier@veurovips.com>
Read/write GIF/JPG <kitfox@golden.net>
regex problem - problem with * (David Waring)
Re: regex problem - problem with * <ebohlman@netcom.com>
Re: regex problem - problem with * (Tom Grydeland)
rounding off numbers <s027119@income.com.sg>
Re: simple perl question (Bart Lateur)
Re: Why doesn't "tr/\x0D//d" work? (Bart Lateur)
Re: Why doesn't "tr/\x0D//d" work? (Bart Lateur)
Re: Why I have a result such as 108.879999999999 Frank@but_dont_use_this.address
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 03 Mar 1998 08:52:04 +0000
From: Zachary Kessin <zkessin@lhr-sys.dhl.com>
Subject: Re: "Learning Perl" or "Programming Perl"
Message-Id: <m3n2f82m2z.fsf@pc-hhu-52.lhr-sys.dhl.com>
If you know several languages you may want to get Programing Perl. But
I would get Learning first. Or the win32 version of the same.
--Zach
>
> >Hi,
> >
> >I'm trying to get started with Perl and I'd like to purchase a book
> >from those fine people at O'Reilly but minimize my initial expenses by
> >only getting one. My question is "Learning Perl" or "Programming
> >Perl"?
> >
> >They both cover a lot of material. Is there much overlap between the
> >two? Do they complement each other or offer different things? Is
> >"Programming Perl" more advanced, or does it too start from scratch?
> >
> >I'm a Windows developer familiar with C, C++, Pascal and all sorts of
> >OSs and major and minor languages so I don't need to be completely
> >hand-held... I need a quick introduction to bring me up to speed.
> >
> >Any thoughts would be appreciated.
------------------------------
Date: 3 Mar 1998 05:30:59 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: "Or" Operator?
Message-Id: <6dg4ij$s6r$3@client3.news.psi.net>
Aaron Harsh (ajh@rtk.com) wrote on 1645 September 1993 in
<URL: news:6dfq7p$6jp$1@brokaw.wa.com>:
++ Abigail wrote in message <6d5mp2$nfc$3@client3.news.psi.net>...
++ >Duncan Cameron (dcameron@nospam.bcs.org.uk) wrote on 1640 September 1993
++ >++ ANY value of $var1 will either not equal 1 or will not equal 2
++ >Not in Perl!
++
++
++ I suppose you can do this with operator overloading:
++
++ package AbigailsRight;
++ %OVERLOAD = ( 'ne' => sub {} );
++ sub new { bless [] }
++
++ package main;
++ $var1 = new AbigailsRight; # Not equal to nothing :-)
++ print "Abigail's right\n"
++ unless $var1 ne 'value 1' || $var1 ne 'value2';
++
++ So there's nothing that's $var1 is not equal to, although pretty much
++ anything is not equal $var1.
++
++ How were you thinking of doing it, Abigail?
I was thinking of a tied scalar variable, where the first FETCH
would return 'value 1' and the second FETCH would return 'value 2'.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: 3 Mar 1998 09:48:40 GMT
From: dwaring@nwsr.com (David Waring)
Subject: Re: a newbie regexp question
Message-Id: <dwaring-0303980150030001@blv-lx103-ip25.nwnexus.net>
You were very vague in this question but I take it you really want to grab
the number out of $file and increment it. You are doing several things
wrong here.
In your code
:> $temp = ($file =~ /\d*/);
This assigment is not correct. The statement ($file =~ /\d*/) is true so
$temp =1 I don't know where you are getting your 3 digit number from but
one my system your code returns $next = 1
> if ($temp < 2) {
> $next = ($temp++);
> }
> else {
> $next = ($temp++);
> $prev = ($temp--);
> }
the $temp++ that you use increments $temp after the assignment of $temp to $next
similarly when you get to the $prev, $temp has been incremented so $temp--
gets you back to the original value, but before this has happened $prev
has been assigned the value of $temp+1. You can use ++$temp and --$temp
in order to do the increment and decrement before the assignment, but you
still have the problem that $temp is incremented before it gets to the
next line so --$temp would still get you back to the original value of
$temp.
Try the following
$file="some other things and 52 in a line";
$file=~/(\d+)/; #the parens store the value inside as $1
$temp=$1;
if ($temp < 2) {
$next = ($temp+1);
}
else {
$next = ($temp+1);
$prev = ($temp-1);
}
print "temp= $temp\n";
print "next= $next\n";
print "prev= $prev\n";
of course you could also use
else {
$next = ($temp);
$next++;
$prev = ($temp);
$prev++;
}
but why bother.
Of course there may be some much more elegant way to do this. I can think
of at least one way to make the assignment to $temp in a single line but
it isn't really pretty. Hope this helps.
David
In article <6dfpmq$auq$1@grouper.exis.net>, "Jeff Barnes"
<psrjeff@exisnospam.net> wrote:
> $temp = ($file =~ /\d*/);
> if ($temp < 2) {
> $next = ($temp++);
> }
> else {
> $next = ($temp++);
> $prev = ($temp--);
> }
> this doesn't work. if the number in $file is a 2 digit number, $next becomes
> a 3 digit number with the first digit being an increment of one of the \d's
> in $file. Why, and how can I fix it?
> Jeff Jeff
******************************
*
* David Waring
* Freelance Web Developer
* HTML, Perl/CGI, Graphics etc.
* dwaring@nwsr.com
* http://www.nwsr.com
*
******************************
------------------------------
Date: Tue, 3 Mar 1998 13:10:19 +0300
From: "Alexander Petrosyan (PAF)" <paf@i-connect.ru>
Subject: ActiveState Perl Debugger Beta 2
Message-Id: <6dgkus$k14$1@news.rinet.ru>
That sound's great, http://www.activestate.com/software/Perl_Debugger, but,
regretfully, I can't download it from there.
Anywhere else?
PAF.
------------------------------
Date: 3 Mar 1998 11:50:11 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: ActiveState Perl Debugger Beta 2
Message-Id: <slrn6fnrjj.v8j.Tom.Grydeland@mitra.phys.uit.no>
On Tue, 3 Mar 1998 13:10:19 +0300,
Alexander Petrosyan (PAF) <paf@i-connect.ru> wrote:
> That sound's great, http://www.activestate.com/software/Perl_Debugger, but,
> regretfully, I can't download it from there.
> Anywhere else?
It comes with Perl. In fact, Perl *is* the debugger.
perl -d
> PAF.
Some questions are asked more often than others. These are called
"Frequently Asked Questions", abbreviated FAQ.
In many cases, to avoid answering the same questions over and over,
some helpful soul compiles a list of such questions with authoritative
answers. It is commonly considered a minimum effort to search for such
a list and consult it before posting your problem to the newsgroup
-- especially if you're a beginner, since your problem is then even less
likely to be new. --
With your copy of perl, you should have received extensive
documentation, and the Perl FAQ is part of this documentation.
A search for the word "debug" in the headlines of the FAQ pages gives
only one hit:
perlfaq3.pod:=head2 How do I debug my Perl programs?
and there is also a separate perldebug manpage. perldoc perldebug
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: 3 Mar 1998 12:16:47 GMT
From: marks@dcs.shef.ac.uk (Mark Stevenson)
Subject: CGI Script problem
Message-Id: <6dgsbf$bq3$1@bignews.shef.ac.uk>
Hi,
I've written a short CGI script in Perl which takes an English word, calls
an executable which lists all the senses of the word and displays these on the
browser.
My problem is that when the executable is called there does not seem to be any
output generated. I'm calling the executable (which is also a Perl script)
in this way, and reading it thorugh a pipe:
open(PIPE, "/share/nlp/bin/lbf -r -w $word |") or print "Can't open pipe!\n";
while(<PIPE>) {
By putting a print statement in the while loop I can tell there is nothing
coming through this pipe.
But, and here the strangeness begins, if I run the script seperately (from the
command line) it works fine. I thought it might be the shell which was
being used by CGI but I tried several shells (csh, tcsh, bash) and it worked
fine under all of them.
My guess is it is something strange which happens under CGI which I don't know
about. This is the first CGI script I've written so I could easily be making
some really simple blunders.
Any help woudl be really appreciated,
Mark
------------------------------------------------------------------------------
Mark Stevenson
Research Assistant marks@dcs.shef.ac.uk
Natural Language Processing Group http://www.dcs.shef.ac.uk/~marks
Sheffield University (0114) 282 5562
-----------------------------------------------------------------------------
------------------------------
Date: 03 Mar 1998 13:53:26 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
To: marks@dcs.shef.ac.uk
Subject: Re: CGI Script problem
Message-Id: <7xsop0vsu1.fsf@beavis.vcpc.univie.ac.at>
Re: CGI Script problem, Mark <marks@dcs.shef.ac.uk> said:
Mark> But, and here the strangeness begins, if I run the
Mark> script seperately (from the command line) it works
Mark> fine. I thought it might be the shell which was being
Mark> used by CGI but I tried several shells (csh, tcsh,
Mark> bash) and it worked fine under all of them.
Mark> My guess is it is something strange which happens
Mark> under CGI which I don't know about. This is the first
Mark> CGI script I've written so I could easily be making
Mark> some really simple blunders.
Check the CGI faq:
http://www.boutell.com/
Also, don't pass the input $word to a command via anything
which could involve a shell interpreting it. It's just
asking for trouble.
man perlfaq
man perlfaq9
hth
tony
------------------------------
Date: 3 Mar 1998 10:42:54 GMT
From: "Scott Kirk" <scott.kirk@liffe.com>
Subject: Re: Conflict in this Newsgroup
Message-Id: <01bd4690$0970e330$d006309c@scott-kirk>
John Moreno <phenix@interpath.com> wrote in article
> As for something that will work in today's environment - I propose
> moderation via kill files and custom header/sig file. Anybody posting
> without the custom header/sig file get's sent the mini-faq. Anybody
> posting without the custom header/sig file who uses munging doesn't get
> a answer unless somebody decides to demunge and answer.
>
> Works like the moderation on alt.dev.null - you've got to do the
> required reading before you get any answers.
I've hesitated to post to this group before because I know too little
to answer dumb questions and too much to ask them :)
The idea of custom headers/sigs has been discussed a couple of times,
but not many seem to have picked this up. IMHO this seems like the
ideal solution. Any post without an approved tag gets a polite automated
reply. Dedicated killfilers can just filter out the noise.
Custom tags in the response like [SEEFAQ] etc seem like a good idea too.
--
Scott Kirk | You live, You learn
Not-quite half-way through | You love, You learn
the Llama book | You lose, You Learn!
| - Alanis Morrisette
------------------------------
Date: Tue, 03 Mar 1998 07:25:56 -0500
From: Mark McKay <kitfox@golden.net>
To: "Jan H.W.G." <info@realm.nl>
Subject: Re: Cookie question
Message-Id: <34FBF6D4.9CC2DA2D@golden.net>
Jan H.W.G. wrote:
>
> Hello,
>
> I have trided and trided to install the cookie script from
> matt@worldwidemart.com but it seems to be that I still have to learn a
> lot.
>
I've had a lot of cookie problems myself. Because of that, I completely
ignore the 'official' modules used to handle them and implement them
directly.
To send a browser a cookie, the first two lines of your document must
look like this:
print "Content-Type: text/html\n"
print "Set-Cookie: <name>=<value>; expires=<date>; path=<PATH>;
domain=<DOMAIN; secure\n"
print "\n"
print "<HTML><TITLE>.........
Note that the 'Set-Cookie' is issued immediatly after the Content-Type
and not two lines after, like HTML code.
The only field necessary in the set-cookie line is <name>=<value>. Only
include 'secure' if you want your cookie to be secure.
To read cookies, just examine the environment variable
$ENV{'HTTP_COOKIE'}.
Mark
--
+---------------------------------------------------------+
| Mark McKay - Hacker, news group lurker and nacho eater |
| extraordinare. *********************** |
| Surf on over to my web page; * If I could think of * |
| there are some cool Java * something witty, it * |
| programs I wrote there. * would go here... * |
| http://www.kitfox.com *********************** |
+---------------------------------------------------------+
------------------------------
Date: Tue, 03 Mar 1998 11:02:48 -0500
From: Koos Pol <Koos_Pol@bigfoot.com>
Subject: Email processor: Procmail - Mail::Tools - Other ?
Message-Id: <34FC29A7.3361@bigfoot.com>
Our department is about to offer internal, online services for the rest
of the company.
These services -ideally- are requested and *auto-triggered* by email
(searching a datbase, copying files, downloading, uploading, etc)
So I am thinking off a email robot to automate things.
Anyone can advise on the best tool to process the incoming email?
* Procmail
* Mail::Tools
* Net::POP3
* The weel you already invented ?
Rather fresh to Unix but fairly good on Perl.
--
Koos Pol
----------------------------------------------------------------------
S.C. Pol tel: +31 20 3116122
PC Systems Administrator email: Koos_Pol@bigfoot.com
Compuware Europe PGP public key available upon request
A little inaccuracy sometimes saves tons of explanation.
-- H. H. Munroe
------------------------------
Date: Tue, 03 Mar 1998 12:16:03 GMT
From: jowell@mindspring.com (Christopher Jowell)
Subject: Extracting text from a logfile
Message-Id: <34fd7096.12875509@news.mindspring.com>
Hi,
Using WIn95 and the latest offering of PERL from Activestate
I'm trying to extract this line from a text file
03FEB98 16:49
What I'm having problems with is that I need the date in one
key of a hash and the time in another. I'm also trying to learn the
most eloquent reqexp to match the date and time in this format. I
guess stating that I'm not a proficient PERL programmer now would kind
of redundant.
Anyway Thanks if anyone can help.
Christopher
------------------------------
Date: Tue, 3 Mar 1998 11:33:22 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Formats and diamond operator
Message-Id: <ebohlmanEp8qrM.MJp@netcom.com>
Brian Springstead <bspring@j51.com> wrote:
: I'm using perl to output a number of similar files to the printer by
: using the diamond operator <> and a format I designed. I wanted the
: top of the page format to include the filename and the page number(s).
: All works well if I only put one filename on the command line. If
: I list more than 1 file and if the information doesn't fill a page, it
: gets treated as one big file. How do I force an end of page and get
: the next filename? Thanks in advance.
When using the diamond operator, $ARGV is set to the name of the file
currently being read. Knowing that and reading perlform.pod, you should
be able to do what you want.
------------------------------
Date: Tue, 03 Mar 1998 09:44:29 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Help me out please!
Message-Id: <3501c7af.6897042@news.tornado.be>
sisiro@rocketmail.com wrote:
>The data file is in the format:
><email addr>|name|item|qty|flag
>Eg: sisiro@rocketmail.com|sisir|modem|100|O
Can't be done. An e-mail address can contain about any character.
I would use the e-mail address as the last field (anything up to the end
of the line), and accept it anyway. The flag then should indicate
whether you have succesfully sent e-mail to it.
To subdivide the line, do something like this:
chomp; # remove newline
($name, $item, $qty,$flag,$email) = split(/|/,$_,5);
HTH,
Bart.
------------------------------
Date: Tue, 3 Mar 1998 11:01:12 GMT
From: David Cross <Dave.Cross@gb.swissbank.com>
Subject: Re: Help: Seeking cgi and html libs...
Message-Id: <y4dd8g49gxz.fsf@gb.swissbank.com>
Patrick Sibenaler <patrick@arch.ethz.ch> writes:
> I'm currently looking for 2 things:
>
> 1. A lib or module that provides functions to dissect html
> code into its tags. I found some that needed htmlscript,
> but I need one without that.
You'll find that LWP does all you want and more. Get it from CPAN.
> 2. A cgi-lib that can deal with a multipart input that is
> uploaded (commonly known as 'uploading' through the web).
> Again, there are simple solutions that do this in php,
> but I need it in perl...
If you're using Perl 5.004 then CGI.pm is already included in your
distribution. If not, you can get it from CPAN.
hth,
Dave...
--
If I wasn't so busy writing status reports,
my status report might just become a progress report.
Dave.Cross@gb.swissbank.com
------------------------------
Date: 03 Mar 1998 12:01:28 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: mail header stripping
Message-Id: <7xpvk43unr.fsf@beavis.vcpc.univie.ac.at>
Re: mail header stripping, SenimotBor
<tomines@rohan.sdsu.edu> said:
SenimotBor> I'm a newbie to Perl and I was wondering if
SenimotBor> there was a more efficient way to strip mail
SenimotBor> headers from a /var/spool/mail/$file and write
SenimotBor> it out to another file. than the way I have it
SenimotBor> set up in the sub routine down below.
Modules, my son, modules!
Mail::Internet
Mail::Header
Mail::Util
tony
------------------------------
Date: Tue, 03 Mar 1998 08:40:19 +0000
From: Alex Schajer <alexs@online.emap.com>
Subject: Maintaining creation dates of files
Message-Id: <34FBC1F2.3EE8AE2D@online.emap.com>
Hi,
I have to PGP some files which I normally do in a perl batch process.
When this process is run the files get a new creation date - that of the
batch process. Is there anyway to keep or replace with the original
creation date?
Thanks
------------------------------
Date: Tue, 03 Mar 1998 09:58:43 +0000
From: Alex Schajer <alexs@online.emap.com>
Subject: Re: Maintaining creation dates of files
Message-Id: <34FBD453.5289A208@online.emap.com>
RTFM - Sorry, I've found the answer myself, bit of spade work never goes
amiss.
the answer is:
utime $atime,$mtime,$filename
If I store the atime and mtime before I create the file I can then force it
using utime.
Thanks for anyone's help anyway,
Alex
Alex Schajer wrote:
> Hi,
>
> I have to PGP some files which I normally do in a perl batch process.
> When this process is run the files get a new creation date - that of the
> batch process. Is there anyway to keep or replace with the original
> creation date?
>
> Thanks
------------------------------
Date: Sat, 28 Feb 1998 13:04:07 -0600
From: thomas@x-tekcorp.com (Thomas Rock)
Subject: Module for multi-set manipulations
Message-Id: <MPG.f621b9e3389ff1598968a@news.anet-chi.com>
I've been working with the PDL and Bit::Vector modules for awhile now and
find them quite convenient for working with simple sets. Now, however, I
have the need to work with multi-sets - that is, a set that can have
multiple copies of an element. For example, given the set of primary
colors, a multi-set could be {2'red, 3'blue, 1'yellow} which contains
6 elements.
I need to be able to compute intersection, union, sum and difference of
such sets. Does anyone know of any existing package which can do this?
Thanks,
--
Thomas Rock
thomas@x-tekcorp.com
------------------------------
Date: Tue, 03 Mar 1998 03:49:43 -0600
From: SPC@popstar.com
Subject: My little puzzle (thanks).
Message-Id: <6dgjmo$ler$1@nnrp1.dejanews.com>
Thank you for your help, I understand most of what you're saying, the bits I
don't understand I'll use my reference books to get my head round.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 02 Mar 1998 23:57:31 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Opening Files
Message-Id: <en0kid6s.fsf@news.concentric.net>
"$oq~Vrde|" <gossfam@wolfenet.com> writes:
> I am trying to use loops to open files, since al of them dont have to be
> opened at any particular time.
If no two files have to be open at the same time, then you only need
one filehandle:
for (whatever) {
# construct your $filename
open(FH, $filename) or die "$!";
# do something with FH, perhaps read from it via <FH>
close FH or die "$!";
}
> Can I do this?? @$var (meaning I want to create an array with a name
> of $var)
Yes. Please refer to the "perlref" and "perldata" documents.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 03 Mar 1998 00:15:21 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Opening Files
Message-Id: <x7hg5gz76e.fsf@sysarch.com>
"$oq~Vrde|" <gossfam@wolfenet.com> writes:
i hate to be rude, but have you ever read ANYTHING about perl in a
useful book or the FAQ? you are breaking so many rules and idiomatic
style it is incredible!!
first i assume you don't use -w, USE it and also use strict.
> sub open_spells {
> my($i);
> for ($i = 1; $i <= $max; $i++){
> $splevel = "m"."$i".".dat";
this is more readable and succinct as $splevel = "m$i.dat" ;
> $sphandle = "M"."$i";
ditto: "M$i"
> $var = "m" ."$i";
ditto ditto
> open ("$spandle", "$splevel");
you dont need quotes around scalar variables.
always check the result of open for errors
> @$var = <$sphandle>;
read the document perlref. you have no idea how to do this. you are
close but no cigar. this isn't even legal syntax from what i tried.
> while (@$var > 0) {
> print ("in");
> $popped = pop (@$var);
> print("$popped\n");
> }
> }
> }
--
Uri Guttman SYStems ARCHitecture and Software Engineering
uri@sysarch.com Have Perl, Will Hack
http://www.sysarch.com (781) 643-7504 x*2 FAX: (781) 643-2710
Try the Best Search Engine on the Net --------> http://www.northernlight.com
------------------------------
Date: Tue, 3 Mar 1998 12:04:46 +0100
From: "Javier Cristobal" <javier@veurovips.com>
Subject: Perl Scripts made on demand
Message-Id: <6dgnp4$n4l@wendy.mad.servicom.es>
Hi I'm Javier Cristobal, a perl programmer & html designer.
I have been programming perl for several years and now I put my knowledge to
the world.
You can see some of my work at:
www.veurovips.com/database1
www.micromouse.com
www.casaweb.com
www.profit.es
www.iolnet.com/perl/message
If you want to include custom cgi scripts in your web just e-mail me.
Sincerely yours
Javier
------------------------------
Date: Tue, 03 Mar 1998 07:10:01 -0500
From: Mark McKay <kitfox@golden.net>
Subject: Read/write GIF/JPG
Message-Id: <34FBF319.79318F2A@golden.net>
Anyone know where I can find modules to read/write the GIF and JPEG file
formats?
Mark
--
+---------------------------------------------------------+
| Mark McKay - Hacker, news group lurker and nacho eater |
| extraordinare. *********************** |
| Surf on over to my web page; * If I could think of * |
| there are some cool Java * something witty, it * |
| programs I wrote there. * would go here... * |
| http://www.kitfox.com *********************** |
+---------------------------------------------------------+
------------------------------
Date: 3 Mar 1998 10:21:01 GMT
From: dwaring@nwsr.com (David Waring)
Subject: regex problem - problem with *
Message-Id: <dwaring-0303980222170001@blv-lx103-ip25.nwnexus.net>
I cannot for the life of me figure out this problem. I am not new to
regex's but this confuses me. I am simply trying to grab a number frome a
line but if I use \d* it does not work while \d+ does. Here is a printout
of my code and the result:
[69] /www/bwaring/cgi-pvt>m a.pl
#!/usr/local/bin/perl
$line="blah blah blah 100 blah blah";
if ($line=~/(\d*)/){
$num=$1;
print "found it\n";
}
print "num= $num\n";
[70] /www/bwaring/cgi-pvt>a.pl
found it
num=
[71] /www/bwaring/cgi-pvt>
Why is this not working?
David
******************************
*
* David Waring
* Freelance Web Developer
* HTML, Perl/CGI, Graphics etc.
* dwaring@nwsr.com
* http://www.nwsr.com
*
******************************
------------------------------
Date: Tue, 3 Mar 1998 11:41:48 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: regex problem - problem with *
Message-Id: <ebohlmanEp8r5o.MtF@netcom.com>
David Waring <dwaring@nwsr.com> wrote:
: I cannot for the life of me figure out this problem. I am not new to
: regex's but this confuses me. I am simply trying to grab a number frome a
: line but if I use \d* it does not work while \d+ does. Here is a printout
: of my code and the result:
I think you need to reread perlre. \d* means "zero or more digits." A
regex consisting solely of \d* will match *any* string (at the invisible
position right before the first character).
------------------------------
Date: 3 Mar 1998 11:45:43 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: regex problem - problem with *
Message-Id: <slrn6fnrb7.v8j.Tom.Grydeland@mitra.phys.uit.no>
On 3 Mar 1998 10:21:01 GMT,
David Waring <dwaring@nwsr.com> wrote:
> I am simply trying to grab a number
> if I use \d* it does not work while \d+ does.
Because the leftmost match (the one that starts at the leftmost position
in your string) is always chosen.
\d* will match even if there are *no* digits (zero or more, remember?),
and will therefore match the zero digits before the first character of
your string.
As you pointed out, \d+ is what you want. Use that.
For a complete understanding of regular expressions, look for _Mastering
regular expressions_ by Jeffrey Friedl.
> * David Waring
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: 3 Mar 1998 08:35:16 GMT
From: "S. Sarkar" <s027119@income.com.sg>
Subject: rounding off numbers
Message-Id: <01bd467f$4c4c4660$2d1809a8@sarkar.income.com.sg>
Is there any function by way of which we can round off numbers like
123.456789 to the nearest 2 digits after decimal point. similarly for
converting 123 to 123.00 (while displaying amounts for eg.).
also i am using Perl 5.001 for WIN NT and when printing 123.40 i always get
123.4
if you people think this is too easy donot answer but aviod flaming me. I
am on a hot seat anyway.
thanx
sarkar
------------------------------
Date: Tue, 03 Mar 1998 09:44:55 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: simple perl question
Message-Id: <3503cb00.7745523@news.tornado.be>
sbnaran@bardeen.ceg.uiuc.edu (Siemel Naran) wrote:
>If I have a string and want to get the string minus the last character if
>it is a '/', how can I do it? For example,
> /home/sbnaran/stuff ==> /home/sbnaran/stuff
> /home/sbnaran/stuff/ ==> /home/sbnaran/stuff
s|/$||;
>(b) If I have a string and I want to return a substring in it starting at
>a given search-substring, how? For example, if the search-substring is
>"sbnaran", then
> /home/sbnaran/stuff ==> sbnaran/stuff
($result) = /(\Q$search\E.*)/;
HTH,
Bart.
------------------------------
Date: Tue, 03 Mar 1998 09:44:20 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Why doesn't "tr/\x0D//d" work?
Message-Id: <3500c5c2.6404035@news.tornado.be>
Tom Christiansen <tchrist@mox.perl.com> wrote:
>Funny how people forget that text files are newline *terminated*.
That's not my definition. This is:
A text file is a file you can create using a text editor by simply
typing.
A file with a final line not ending in a newline is perfectly possible.
Bart.
------------------------------
Date: Tue, 03 Mar 1998 09:44:24 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Why doesn't "tr/\x0D//d" work?
Message-Id: <34ffc399.5851270@news.tornado.be>
aml@world.std.com (Andrew M. Langmead) wrote:
>>Should the goal be to *always* eliminate *all* warning messages
>>from your code?
>Only the ones that you know will not cause bugs in your programs.
>If you know that a particular section of code will generages a
>spurious warning. (I personally really hate the "argument isn't
>numeric" warning. Maybe I want to sort strings like "123abc"
>numerically.) You can always disable in a a section of code by
>toggling $^W.
I agree. I personally using possibly undefined variables without an
error generated.
I just hate the spurious warnings. If you get a warning inside a loop,
you'll get a LOT of warnings.
I just wish Perl would allow masking out specific kinds of warnings via
a mask, instead of just "all or nothing".
Bart.
------------------------------
Date: 03 Mar 1998 08:35:38 +0100
From: Frank@but_dont_use_this.address
Subject: Re: Why I have a result such as 108.879999999999
Message-Id: <yo9n2f8mdkl.fsf@nym.sc.philips.com>
Hey!
The magic is, that numbers in computers are represented with finite
precision. There exist many many ways to do this. Useful keywords for
you to start your journey on the WWW are:
number system
twoscomplement
radix
IEEE 754, especially if you use an Intel processor
A good place to enter the keywords is:
http://altavista.digital.com
Or you could read standards like:
The Art of Computer Programming, by Donald E. Knuth
regards
Frank
------------------------------
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 2007
**************************************