[8352] in Perl-Users-Digest
Perl-Users Digest, Issue: 1969 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 25 03:07:37 1998
Date: Wed, 25 Feb 98 00:00:30 -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 Wed, 25 Feb 1998 Volume: 8 Number: 1969
Today's topics:
Re: Cacheing and Back Button question. <webmaster@fccj.cc.fl.us>
Re: calling C++ from Perl <reiper@rsv.se>
Re: factorial function? (Craig Berry)
Re: freshly installed perl...now it won't run <shimpei+usenet+.mil+.gov@BOFH.patnet.caltech.edu>
Re: HELP array stuff <rjk@coos.dartmouth.edu>
Help! How can i show image from HTML files that is read <feri@unitel.co.kr>
Re: if (-d $filename) in Win32 <webmaster@fccj.cc.fl.us>
Re: if (-d $filename) in Win32 <webmaster@fccj.cc.fl.us>
Re: lwp-mirror: at vs cron <webmaster@fccj.cc.fl.us>
Multiple Sort on Array of Arrays? (Jason Hellwege)
Re: musings on autoincrement <rjk@coos.dartmouth.edu>
Need news2HTML tool (Markus Wannemacher)
No. of days?? <s027119@income.com.sg>
Re: Off-topic (Sorry, but I need your help) <webmaster@fccj.cc.fl.us>
ORAPERL (Anton Makeev)
Re: Pattern Match (Martin Vorlaender)
Re: Pattern Match <rjk@coos.dartmouth.edu>
Re: Pattern Matching for parsing tags (Martin Vorlaender)
Re: Perl 4/5 - Part 2 <Dave.Cross@gb.swissbank.com>
Re: perl5.004_04 fails on make (Nathan V. Patwardhan)
Re: Piping Eudora? (Troy Denkinger)
Re: reg expression help.. <rjk@coos.dartmouth.edu>
Split and extracting substrings <reilly@ozy.dec.com>
Re: Split and extracting substrings (Craig Berry)
Re: why no Case statment? (Greg Andrews)
Re: y2k UNIX laundry list (David Adler)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 25 Feb 1998 05:08:34 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: Cacheing and Back Button question.
Message-Id: <34F3A62C.DCCA7FD4@fccj.cc.fl.us>
Hmmm, my JavaScript must be out of date...
History and Location are both window and frame specific, so care
would still need to be taken - I would still hazard a guess that it
would be difficult...
Bill :-)
susan cassidy wrote:
> In article <34EF9EA3.6569CFD9@fccj.cc.fl.us>,
> Bill Jones <bill@astro.fccj.cc.fl.us> wrote:
> >[courtesy cc of this posting WAS NOT sent to cited author via email]
> >
> >You're basically stuck. I do not know of a way to accomplish what
> >you are trying to do...
> >
> >I would suggest you keep track of it internally to the Perl code itself
> >and
> >stay away from cookies; or research the CGI.pm module closely.
> >It will give you hints on how to approximate what you want...
> >
> >HTH,
> >Bill
> >
> >
> >Remove NOSPAM to reply wrote:
> >
> >> Hello. I've been trying without luck to figure out how to prevent the
> >> user from using the back button from a certain page.
> >>
> >> My problem is that I have form that is used for editing the
> >> state of something. A perl script handles the POST method
> >> and generates a new version of the form with each interaction.
> >> If I allow the user to use the back button, then they will be
> >> able to step back to a previous version of the form, which
> >> will contain out of date state information.
> >>
> >> I have tried using Pragma: no-cache, and also using the
> >> Expired header with both "0" and an old date as
> >> Content. They only work intermittently in Netscape 4.04.
> >>
> >> I would like to write a Java applet to handle this
> >> situation, but unfortunately the client doesn't like
> >> Java. Any suggestions would be appreciated.
> >>
> >> Thank you,
> >> Lee Nelson
> >
> >
> >
>
> Maybe you could use the JavaScript (not Java) Location.replace() method
> in the updated page to cause the URL in the history to be replaced with
> a new one.
>
> This means that if they hit the Back button, it goes to the page
> before the last page accessed.
> --
> Susan Cassidy
> Remove xxx in replyto address when replying.
------------------------------
Date: Wed, 25 Feb 1998 07:58:35 +0100
From: Reine Persson <reiper@rsv.se>
To: Locatelli A <bg250@city.ac.uk>
Subject: Re: calling C++ from Perl
Message-Id: <Pine.HPP.3.95.980225075058.10348C-100000@u30045.rsv.svskt.se>
On Tue, 24 Feb 1998, Locatelli A wrote:
> Hi all I have got this problem:
>
> I am trying to call a C++ program from a perl script and want to use the
> output of this program in the script.
> I use the following statement to call the program and catch its output:
>
> $whatever = `programpath | parameters`;
>
> What I can`t do is :
>
> 1) use values stored in perl variables as parameters to call the C++
> programs (don`t know how to bring them into the above statement)
>
> 2) Catching the output of the C++ program in a different way then
> through its standard output --> If I make the C++ program return
> some values I don`t get them, it works only if I send them to std
> output.
>
> Any help is appreciated
>
> thanks
>
> Andrea Locatelli
>
> bg250@city.ac.uk
>
>
Hello !
Try this:
$prog="/usr/bin/bdf";
$param="-l";
open(PIPE,"$prog $param |") || die "cannot open PIPE: $!";
while(<PIPE>) {
print; # Do anything with the output of $prog
}
close(PIPE) || die "cannot close PIPE: $!";
This is just an example !
//Reine
------------------------------------------------------------
Reine Persson Tel: 08-7648280,08-6944431
RSV Dataservice DS/PX Mobil: 0708-189832
171 94 Solna Email: reiper@rsv.se
------------------------------------------------------------
------------------------------
Date: 25 Feb 1998 06:40:39 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: factorial function?
Message-Id: <6d0ed7$8bk$1@marina.cinenet.net>
Paulo Dutra (paulo@xilinx.com) wrote:
: Is there a recommended library to handle factorial implementations?
For ordinary purposes, a simple iterative factorial function like this
should serve well (untested):
sub factorial
{
my $val = shift;
my $acc = $val;
$acc *= $val while --$val > 1;
return $acc;
}
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 25 Feb 1998 07:37:50 GMT
From: Shimpei Yamashita <shimpei+usenet+.mil+.gov@BOFH.patnet.caltech.edu>
Subject: Re: freshly installed perl...now it won't run
Message-Id: <6d0hoe$bpu@gap.cco.caltech.edu>
MICHELLE MARIE HANKINS <mmhankin@ouray.cudenver.edu> writes:
>
>I just installed perl 5.003 on my DEC Alpha (OSF/1). Ran the configure
>program & pretty much acccepted the defaults.
That's old. You should install 5.004_04 (should be available from
wherever you got 5.003) instead.
>The bad news is that I put in the very first program in the very first
>camel book, (the "Hello, World" thingy on page 5) and nothing happens.
>
>Tried the one on page 7 and nothing. My syntax is correct, tried sticking
>white space in everywhere, nothing. I must not have installed it correclty.
>I type: perl at my ksh, and it hangs.
That's perfectly normal behavior. perl is expecting perl code to be
typed into stdin, so it will look hung until you have typed in enough
code to execute.
> I type in print commands, and it will
>tell me when I make an error mesage, but nothing happens when I don't.
>
>Did I not install something right? (Forgive me, I'm used to shell scripts
>with immediate responses.)
Instead of typing 'perl' and typing in the program, make a file
beginning with
#! /usr/local/bin/perl -w
(or wherever you put perl), type in the commands, chmod 755 and
run it like a shell script. If you really want to run perl commands
from the command line, do something like
perl -e 'print "hello world\n";'
instead.
--
Shimpei Yamashita <http://www.patnet.caltech.edu/%7Eshimpei/>
perl -w -e '$_="not a perl hacker\n";$q=qq;(.);x9;$qq=qq;345123h896789,;;;$s=
pack(qq;H6;,q;6a7573;);$qq=qq;s,^$q,$s$qq;;$qq=~s;(\d);\$$1;g;eval$qq;print;'
------------------------------
Date: Wed, 25 Feb 1998 01:39:09 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Douglas Cordero <dcordero@giss.nasa.gov>
Subject: Re: HELP array stuff
Message-Id: <34F3BCA0.47B995C6@coos.dartmouth.edu>
[posted and mailed]
Douglas Cordero wrote:
>
> I came up with this, but it doesn't work:
Is this your real code?
> foreach $A1 (@array1) {
^^^
> $found = 0;
> foreach (@prodata) {
> if (m/$A/) {
^^
> $found = 1;
> last;
> }
> }
> if( $found == 0 )
> { die "MISSING DATA\n" }
> }
You have two different variables there. The -w switch would have alerted you
to this.
--
_ / ' _ / rjk@coos.dartmouth.edu
( /)//)//)(//)/( chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
It's funny 'cause it's true ... and vice versa.
------------------------------
Date: Wed, 25 Feb 1998 00:13:23 +0900
From: "feri" <feri@unitel.co.kr>
Subject: Help! How can i show image from HTML files that is read in a cgi script ?
Message-Id: <6cun8i$rqj$1@news.att.co.kr>
I have a question in a cgi script..
I wrote a cgi script like this.
CGI script reads a plain html file, and then showing that result.
But html file includes tags like IMG, BACKGROUND, so called image file tags.
(<img src="hello.gif">) and then browser doesn't show images, just showing
empty space . ( no problems in image file path)
As a result, I wrote another CGI script - image_loader.cgi like this
( <img src="/cgi-bin/image_loader.cgi?img=hello&type=gif"> )
Is there a method solving this more easily?
For example,
## cgi script example
print "Content-type: text/html\n\n";
read HTML file and print it.
## HTML file
... ellipses ..
<imgBODY BACKGROUND="/cgi-bin/image_loader?img=hello&type=gif">
... ellipses ...
## image_loader.cgi
... ellipses ...
$img contains the value - hello
$type contains the value - gif
print "Content-type: image/$type\n\n";
read graphics and print it.
Thanks in advance... :-)
------------------------------
Date: Wed, 25 Feb 1998 05:14:22 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: if (-d $filename) in Win32
Message-Id: <34F3A788.6146098F@fccj.cc.fl.us>
Which a true statement -
I am still learning as well :-)
Bill
Martien Verbruggen wrote:
> In article <34F2204B.33F83013@coos.dartmouth.edu>,
> Chipmunk <rjk@coos.dartmouth.edu> writes:
> > Jonathan Feinberg wrote:
> >>
> >> webmaster@fccj.cc.fl.us said...
> >> : print 'Still there as C:\Temp...' if (-d "c:\Temp");
> >>
> >> You really have a folder called "c:Temp" ? (You didn't escape your backslash!)
> >
> > Hmm... That's cause he doesn't need to, in a single quoted string:
>
> The single quotes are just the print statement. He's got double quotes
> where it really matters.
>
> Martien
> --
> Martien Verbruggen |
> Webmaster www.tradingpost.com.au | In a world without fences, who needs
> Commercial Dynamics Pty. Ltd. | Gates?
> NSW, Australia |
------------------------------
Date: Wed, 25 Feb 1998 05:27:31 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
To: "Andrew M. Langmead" <aml@world.std.com>
Subject: Re: if (-d $filename) in Win32
Message-Id: <34F3AA9D.DFC099F1@fccj.cc.fl.us>
Sorry this is late in responding, but I was tied up...
I would say in my defense that I may have obviously
read the original postings and responses to
hastily :-)
In your defense I would say that what I wrote
(yes I know I bugged it :-) Would have
probably sufficed for the DOS (and related)
platforms because even with the error the code
was sound in proving either / \ would work :-)
I really didn't mean to start
a misunderstanding,
Bill :-)
Andrew M. Langmead wrote:
> Yes, both Jonothan and myself were agreeing that it would work.
> I'm sorry that my message did not do a good job of explaining my
> point. If you have a moment, could you point out where in my post I
> give the mistaken impression that only forward slashes (or only
> backslashes I'm not sure which one you though I was arguing for) would
> work. If I see where my writing was unclear, it may help me to avoid
> similar mistakes in the future.
>
No mistake, I need to read slower :-)
------------------------------
Date: Wed, 25 Feb 1998 04:59:21 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
To: Paul Joslin <paul.joslin@sdrc.com>
Subject: Re: lwp-mirror: at vs cron
Message-Id: <34F3A403.E178AE3C@fccj.cc.fl.us>
Sorry this is late, but I've been tied up...
In my experience cron logs are not very reliable. What I would do
is place some 'output' points along the code and see what is 'mailed' to
root - that way you could 'debug' by process elimination.
HTH,
Bill
Paul Joslin wrote:
> >>>>> "Bill" == Bill Jones <webmaster@fccj.cc.fl.us> writes:
>
> Bill> [courtesy cc of this posting sent to cited author via email]
> Bill> If 'cron' is dying because it wants input - I would look at
> Bill> where the 'input' is supposed to come from...
>
> Bill> Other than that, are there any other messages?
>
> cron is not dying because it wants input, nor is it expecting
> arguments. The cron log file indicates the command completes successfully.
> For both "at" and "cron", the script is called as "/x/y/z/do_mirror", where
> /x/y/z is the full path name to the command. The filesystem is not
> automounted, and there are no ENV variables in the path.
> --
> Paul R. Joslin I do quarrel with logic that says,
> paul.joslin@sdrc.com `Stupid people are associated with X,
> +1 513 576 2012 therefore X is stupid.' Stupid people
> are associated with everything.'
> --Larry Wall in
> <1992Dec31.203724.26018@netlabs.com>
------------------------------
Date: 25 Feb 1998 05:17:35 GMT
From: glecjh@luff.latrobe.edu.au (Jason Hellwege)
Subject: Multiple Sort on Array of Arrays?
Message-Id: <4134.1323698977.77890@news.latrobe.edu.au>
OK....time to admit defeat and grovel for help... <grovel, grovel>
I've been through the Llama and Camel books and the Perl FAQs,
and I can't seem to resolve this references/sorting problem:
I have an array-of-arrays and I want to sort it. In fact, I want to
perform 3 sorts on the data. My code runs like this:
...blah blah blah ...
push (@$list, @fields);
@$sorted = sort by_magic @$list;
sub by_magic {
$a->[3] cmp $b->[3]
or
$a->[1] cmp $b->[1]
or
$a->[5] cmp $b->[5]
}
The basic recipe is from the Camel book, but my attempt to
transpose it for an array-of-arrays seems to fail. Printing
out the array-of-arrays shows that @$list is populated as I
expect it to be.
Any and all assistance gratefully received!
________________________________________________________________________
Jason Hellwege "Vince would go seriously mad
about
La Trobe University, Melbourne, once a month....and less
seriously
Australia. Jason.H@latrobe.edu.au mad, about three times a
month..."
________________________________________________________________________
------------------------------
Date: Wed, 25 Feb 1998 01:01:29 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: musings on autoincrement
Message-Id: <34F3B3CA.9762C26E@coos.dartmouth.edu>
Dan Boorstein wrote:
>
> Kevin B Cohen wrote:
>
> [...]
> > $scalar = "5-year-old male asthmatic"
> >
> > and if you then evaluate it in a conditional, e.g.
> >
> > if ($scalar < 18) { $age = "pediatric"}
> > elsif ($scalar >= 18) {$age = "adult"}
> [...]
> out of curiosity, why does the above code (once compilable) only
> generate a single warning (for 'lt' but not 'ge')? can only a single
> comparison operator warn at any given time?
Short answer: because only the first conditional is being evaluated. :-)
Real answer: because Perl caches the string and numeric values of variables.
At the first conditional, $scalar has a string of "5-year-old...", and no
numeric value at all, because it has never been used in a numeric context.
So, Perl converts $scalar to a number, and stores the result. Now $scalar
has the same string value, and a numeric value of 5.
At the second conditional, Perl sees that $scalar has a numeric value of
5, so it doesn't bother to do the conversion again and just uses that value.
--
_ / ' _ / rjk@coos.dartmouth.edu
( /)//)//)(//)/( chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
It's funny 'cause it's true ... and vice versa.
------------------------------
Date: 25 Feb 1998 07:04:55 GMT
From: Markus.Wannemacher@FernUni-Hagen.De (Markus Wannemacher)
Subject: Need news2HTML tool
Message-Id: <6d0fqn$8o9$2@dogwood.fernuni-hagen.de>
Hi,
I am loooking for a tool that converts automaticaly an
archive of news messages to html files. It should
generate a html page with links to all threads,
thrads pages with links to all articels in the thread
and article pages with links to the thread page, the
previous and the next article, ...
In summary: It should be possible to read news
with a HTML browser as easy as with a news reader.
The reason I do need this is to make an archive of
news article available via WWW.
Thanks,
Markus
------------------------------
Date: 25 Feb 1998 07:07:04 GMT
From: "S. Sarkar" <s027119@income.com.sg>
Subject: No. of days??
Message-Id: <01bd224a$36f51e80$2d1809a8@sarkar.income.com.sg>
I am unable to find a way to calculate the nos. of days from today from any
particular day in the past or the future. can any kind soul please help.
the input format is yy/dd/mm or dd/mm/yy or mm/dd/yy
need this done ASAP.
------------------------------
Date: Wed, 25 Feb 1998 05:11:10 GMT
From: Bill Jones <webmaster@fccj.cc.fl.us>
To: Paul Makepeace <Paul.Makepeace@POBox.com>
Subject: Re: Off-topic (Sorry, but I need your help)
Message-Id: <34F3A6C8.F596B6D8@fccj.cc.fl.us>
[Mailed & Posted ]
Yes, :-) I will admit to IE4 on Solaris and maybe FrontPage 98
Extensions,
but neither counts - do they?
Bill :-)
Paul Makepeace wrote:
> Bill Jones wrote in message <34F05161.DE87BE44@fccj.cc.fl.us>...
> >Unix kicks asss,
> >Unix is the standard,
> >MS does not run on Unix,
>
> Rumours I've heard, http://www.microsoft.com/ does run on Unix :-)
>
> Paul
------------------------------
Date: 25 Feb 1998 10:14:41 +0300
From: mant@simcb.ru (Anton Makeev)
Subject: ORAPERL
Message-Id: <6d0gd1$loe$1@julia.simcb.ru>
> Please ask me whan i find ORAPERL & documentation for Oracle 7.3.3
I don't know for sure ... I suggest you ask on comp.lang.perl.misc.
--
Please help me.
/MANT/
------------------------------
Date: Wed, 25 Feb 1998 05:07:52 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Pattern Match
Message-Id: <34f39918.524144494f47414741@radiogaga.harz.de>
bp@bp.com wrote:
: I have a series of lines of data that start with
: " D-01 1456"
: " D-02 1500"
: " D-04 1400"
: I want to keep the D-01 as one word. How would I match this or parse it in
: perl?
The lines are built like
"<start of line><one whitespace>D-<two digits><several whitespace>
<several digits><end of line>".
In perl regexp notation, this is:
$line =~ /^\s(D-\d{2})\s+\d+$/;
The () here isolate D-<two digits> from the rest, and put it in $1 .
Read all about it in the perlre POD, and the =~ and m// entries in the
perlop POD.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: Wed, 25 Feb 1998 01:33:03 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: bp@bp.com
Subject: Re: Pattern Match
Message-Id: <34F3BB32.B50E99E7@coos.dartmouth.edu>
[posted and mailed]
bp@bp.com wrote:
>
> I have a series of lines of data that start with
>
> " D-01 1456"
> " D-02 1500"
> " D-04 1400"
>
> I want to keep the D-01 as one word. How would I match this or parse it in
> perl?
The split() function might do what you want. Take a look at the documentation
for perlfunc.
--
_ / ' _ / rjk@coos.dartmouth.edu
( /)//)//)(//)/( chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
It's funny 'cause it's true ... and vice versa.
------------------------------
Date: Wed, 25 Feb 1998 05:18:01 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Pattern Matching for parsing tags
Message-Id: <34f39b79.524144494f47414741@radiogaga.harz.de>
Manhattan5 (mike@vitamins.net) wrote:
: Sometimes they pattern matching works, sometimes it doesn't. For example this
: worked:
: $myfile =~ s/<HR>/<hr size=1 noshade>/g;
: This didn't:
: $myfile =~ s/<[BODY bgcolor=\"FFFFFF\"]>/ /g;
What do you think the [] are doing? Find out all about character classes
and why you wouldn't want to use them here by reading the perlre POD.
Also, what happens if a tag spans multiple lines? Have a look at the '/s'
modifier in the perlre POD.
: Any ideas how to parse a specific tag? I know general tags by <[^>]*> but am
: having trouble with specific.
Have a look at the HTML::Parser module in the libwww package for a cleaner
way to parse HTML.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: Tue, 24 Feb 1998 09:22:25 GMT
From: David Cross <Dave.Cross@gb.swissbank.com>
Subject: Re: Perl 4/5 - Part 2
Message-Id: <y4du39ppdbi.fsf@gb.swissbank.com>
Geert Roovers <Geert.Roovers@POBoxes.com> writes:
> What facts can I use to make my system manager upgrade to Perl 5?
'There are no plans to make Perl 4 Y2K compliant.'
--
"...but Man created all gods equal."
Dave.Cross@gb.swissbank.com
------------------------------
Date: 25 Feb 1998 04:54:42 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: perl5.004_04 fails on make
Message-Id: <6d086i$6ci@fridge.shore.net>
Hoang Nguyen (harryn@cerf.net) wrote:
: I was trying to compile perl5.0004, when I do 'make'
: it ran for a while then gave me this error:
You're not linking against all the libraries that you need to. In
this case I think that you're missing -lm, the math library.
--
Nathan V. Patwardhan
------------------------------
Date: Tue, 24 Feb 1998 06:29:30 GMT
From: troy@whadda.com (Troy Denkinger)
Subject: Re: Piping Eudora?
Message-Id: <6d0du8$5gn$1@hirame.wwa.com>
[original author cc'd via email]
In article <6cvq3d$pl2$1@nnrp1.dejanews.com>,
rshannon@ptinet.net wrote:
>I don't think Eudora will pipe to a CGI script...Does anyone know a way to do
>it via email? I know Pine does it but Pine requires SHELL and I am trying to
>avoid SHELL...So...I want to post a message via Eudora to myslef and have it
>piped to a mailing script I re-wrote..Any help?
It's entirely possible I'm misunderstanding what you're
trying to do. But...Eudora 3.0, look at Filters and check
out the "Notify Application" option. This will run an
external app with parameters passed.
Now, back to Perl.
Regards,
Troy Denkinger
------------------------------
Date: Wed, 25 Feb 1998 01:30:57 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Alex Krohn <alex@gossamer-threads.com>
Subject: Re: reg expression help..
Message-Id: <34F3BAB3.CB917D68@coos.dartmouth.edu>
[posted and mailed]
Alex Krohn wrote:
>
> I have the following options:
>
> whole word searching: add a \b \b around the search term.
> case sensitive: add a /i to the reg expression
You have your terms backwards: /i means case *in*sensitive: that's why it's /i.
> [...]
>
> my ($regexp) = "word";
> $regexp = "\Q$regexp\E" if (!$in{'re'});
Yes. Or:
$regexp = quotemeta($regexp) unless($in{'re'});
> $regexp = "\b$regexp\b" if ($in{'ww'});
You need double backslashes there, or the \b's will be taken as backspace
characters before they make it into the regex.
> $regexp = "(?i)$regexp" if ($in{'cs'});
Yes. Except that key should be called 'ci', because you have case sensitive
and case insensitive mixed up.
> and then in the for loop:
>
> $expr = $regexp;
> $expr = s/word/$term/;
You just assigned to $expr twice. Why?
> eval { $match = ($values[$field] =~ /$expr/) };
>
> Does that make sense? Does putting an eval in there every time make
> things worse then before?
I believe that will work. Note that with the eval BLOCK syntax, which you're
using, the BLOCK is compiled only once, so you shouldn't see a performance
penalty. If the value of $expr doesn't change while you're using it as a
regex, you can also add a /o to the regex so it too is only compiled once.
Since you're allowing full regexes, you should make sure the eval succeeded by
the checking the value of $@.
Hope that helps.
--
_ / ' _ / rjk@coos.dartmouth.edu
( /)//)//)(//)/( chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
It's funny 'cause it's true ... and vice versa.
------------------------------
Date: Wed, 25 Feb 1998 16:57:46 +1100
From: David Reilly <reilly@ozy.dec.com>
Subject: Split and extracting substrings
Message-Id: <34F3B2DA.46D011E6@ozy.dec.com>
Hello. I need to extract a paramater from a configuration file (which
is a set of key-value pairs each on a separate line). The key, and the
value
are surrounded by whitespace. I can do a test for the existance of the
param
if (/$param_name/)
{
# Get value
$value = ????
}
but I don't know how to extract the value, and assign it to $value.
Any suggestions would be greatly appreciated
------------------------------
Date: 25 Feb 1998 07:14:38 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Split and extracting substrings
Message-Id: <6d0gcu$8bk$2@marina.cinenet.net>
David Reilly (reilly@ozy.dec.com) wrote:
: Hello. I need to extract a paramater from a configuration file (which
: is a set of key-value pairs each on a separate line). The key, and the value
: are surrounded by whitespace. I can do a test for the existance of the
: param
:
: if (/$param_name/)
: {
: # Get value
: $value = ????
: }
:
: but I don't know how to extract the value, and assign it to $value.
Easier (and less prone to false positives if param names can also appear
as values, and far more convenient if you need to deal with many param
names) would be (untested):
my %params = ();
while (<>) { # Or wherever config lines come from...
my ($name, $value) = split;
$params{$name} = $value;
}
Then you can test for the existence of a parameter named 'param_name' using
exists $params{param_name}
HTH!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 25 Feb 1998 06:36:23 GMT
From: gerg@shell. (Greg Andrews)
Subject: Re: why no Case statment?
Message-Id: <6d0e57$1ac$2@news.ncal.verio.com>
aml@world.std.com (Andrew M. Langmead) writes:
>Tzadik Vanderhoof <stvhoof@netvision.net.il> writes:
>>
>>Why doesn't Perl have a real Case statement?
>>
>
>Now in perl, there used to be an optimization in which an
>if-elsif-else chain would be optimized to a case statement if
>appropriate. It doesn't help you if you think of a case statement as
>an aesthetic construct, but it does if you think of it as a different
>function (and perl will decide for you which one is better.) Also,
>without the dangling else problem if-elsif-else chains aren't that bad
>anyway.
>
While I recognize that in Perl the different constructs will be
compiled down to a real case structure, I still feel it would be
a good idea to add an explicit case statement.
The reason is, I can't always tell that I've written the construct
properly. About a year ago I wrote a fairly large text parsing
script with several case constructs. As I was debugging my first
draft of the script, I discovered that I'd written three of the
constructs wrong, and they weren't behaving as a true case statement.
So the reason I would ask for an explicit case statment in Perl is
to make it easier for Perl programmers to get it right. In my own
experience, it's not hard to blow it, particularly when you're not
real familiar with Perl's loop constructs in the first place.
However, a good alternative would be a way to find out whether
a piece of code I've written compiles into a real case statement.
Perhaps in the debugger?
-Greg
------------------------------
Date: 25 Feb 1998 06:16:41 GMT
From: dha@panix.com (David Adler)
Subject: Re: y2k UNIX laundry list
Message-Id: <slrn6f7dq9.n4o.dha@panix.com>
On 24 Feb 1998 00:29:13 -0600, Peter Samuelson <psamuels@sampo.REMOVETHIS.creighton.edu> wrote:
>[Steve Dover <swd@strata-group.Xcom>]
>> I'm curious as to why some of the perl maintainers think
>> Perl 4 has different Y2k issues than Perl 5.
>
>I've always assumed it's a clever little red herring.
Give that man a cigar! :-)
Nevertheless, don't tell the pointy-haired ones about this.
It *is* true that there are no plans to make perl4 Y2K compliant (and
I certainly don't know of any plans to make perl4 *programs* so).
Then there are the security issues, which are on rather firm ground.
Use the latest perl for a happier world.
If the management types want to know the *whole* truth, they can read
the documentation. I think we're safe. ;-)
--
David H. Adler - <dha@panix.com>
"The perversity of the Universe tends towards a maximum."
------------------------------
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 1969
**************************************