[8357] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1974 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 25 18:17:28 1998

Date: Wed, 25 Feb 98 15:00:27 -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: 1974

Today's topics:
        [Fwd: Regex substitutions] <joneil@cks.ssd.k12.wa.us>
        convert a string to a number (Maxine G.)
    Re: convert a string to a number (Kevin B Cohen)
    Re: Cookies Too many clowns   heres your answer (steve)
    Re: CyberCash and Custom Script (Douglas Wilson)
    Re: Easy way to "clean" an array <stvhoof@netvision.net.il>
    Re: file test inside grep() (Andrew M. Langmead)
    Re: Help with access , CGI &  Java needed T.I.A (steve)
    Re: Help with SYSTEM command? <jim.michael@gecm.com>
    Re: HELP! exec doesn't work properly! <Y_Hu@fccc.edu>
    Re: How does the Perl-Interpreter works? (steve)
    Re: HP-UX compile failure (Paul J. Schinder)
    Re: IP-Address in Perlscripts (steve)
    Re: Need some advice,  why dont you just do this (steve)
    Re: No. of days?? <stvhoof@netvision.net.il>
        overload.pm <nospamfabian.tiburce@cgi.ca>
    Re: Philisophical Response? Perl5/oop (Elf Sternberg)
    Re: Prisoners of the evil empire <jdporter@min.net>
        Regex substitutions <joneil@cks.ssd.k12.wa.us>
    Re: Regex substitutions <joneil@cks.ssd.k12.wa.us>
    Re: Regex substitutions (Jack Ostroff)
    Re: Regex substitutions <dboorstein@shopcfn.com>
        Replacement of characters <xieyum@nortel.ca>
        Script error need help please.... (Corey)
    Re: sorting array (Andrew M. Langmead)
    Re: Splitting on 2 line feeds? <dboorstein@shopcfn.com>
    Re: substitution - control characters (Andrew M. Langmead)
    Re: The Ineffable Tom C. (Billy Chambless)
    Re: Unwanted Character Displays <jason@primal.ucdavis.edu>
    Re: Why install perl? (steve)
    Re: Why install perl? (Craig Berry)
        XS dynamic loader: how to push C args? <sfink@cs.berkeley.edu>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 25 Feb 1998 14:10:19 -0800
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
Subject: [Fwd: Regex substitutions]
Message-Id: <34F496CB.805192E5@cks.ssd.k12.wa.us>

This is a multi-part message in MIME format.
--------------00AB35D04563E92902AC8A81
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit



--------------00AB35D04563E92902AC8A81
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Message-ID: <34F496A1.54A2E330@cks.ssd.k12.wa.us>
Date: Wed, 25 Feb 1998 14:09:37 -0800
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
X-Mailer: Mozilla 4.04 [en] (Win95; I)
MIME-Version: 1.0
To: Jack Ostroff <jack_h_ostroff@groton.pfizer.com>
Subject: Re: Regex substitutions
References: <34F48830.E6D72D5D@cks.ssd.k12.wa.us> <199802252152.QAA15090@gsun150.Clinical>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit



Jack Ostroff wrote:

> You forgot that the first match (.+) is greedy, and is matching
> everything it can and still allow the second part to match.
> What you probably want is to limit the first part of the match
>
> > $schlnm =~ s/(.+?)(\(.\)){0,2}/$1 Half Day K $2/x
>
> note the "?" after the .+

That is exactly it.  Thanks for the help.  I can go back to looking busy
now.

> A very quick search found references to this in perlfaq6
> and perlre.  It's also on pages 29 and 63 of the blue camel
> and 80/81 of the blue llama.

I own them all.  I just wasn't quite sure what to look for.

Thanks again!

Jerome "Gordon Gekko" O'Neil


--------------00AB35D04563E92902AC8A81--



------------------------------

Date: Wed, 25 Feb 98 20:47:29 GMT
From: *nospam*mg*nospam*@*nospam*pcg*nospam.net (Maxine G.)
Subject: convert a string to a number
Message-Id: <6d2039$hbe$2@usenet53.supernews.com>

I'm afraid this may be one of those really obvious beginner questions, but 
here goes:
How do I convert a string containing numeric data to a numeric variable? In 
other words, if I have $x = "0123", I want $y = 123. 
tia!

 
*********************************************************
return address changed to prevent spamming
Remove "NOSPAM" in the return address
Maxine Gerber
PCG Systems
*********************************************************


------------------------------

Date: 25 Feb 1998 16:07:43 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: convert a string to a number
Message-Id: <6d216v$can@julius.ling.ohio-state.edu>

In article <6d2039$hbe$2@usenet53.supernews.com>,
Maxine G. <*nospam*mg*nospam*@*nospam*pcg*nospam.net> wrote:
>other words, if I have $x = "0123", I want $y = 123. 


the answer to your question is related to chipmunk's answer to dan's
question about why a variable appeared to trigger a warning when
evaluated by one comparator, but not by the next.

to make your variable look/be the way you want, do this:

$x *= 1;

this forces $x into numeric... context?  not sure what the term is.

hth--- kevin



------------------------------

Date: Wed, 25 Feb 1998 21:50:18 GMT
From: me@here.com (steve)
Subject: Re: Cookies Too many clowns   heres your answer
Message-Id: <3500917e.111121053@news.cent.com>

first, you need to set your cookie with an expiration date in the
future, no expiration date = cookie lost when browser closed.
then, script asks if the cookie exists when they next enter the
script.  cookies are set in the server headers before the text/html
header.  goto netscape.com, they have a good example/s of setting
cookies.


On Sun, 22 Feb 1998 09:46:49 GMT, dutchie@dutch.nl (Dutchie) wrote:

>I'am searching how to make a cookie into a shopping programm, if the
>visiter leaves the site (after making a order but canceled it) and
>comes back in lets say 8 hours he/she becomes a cookie with the
>question :
>Would you like to continue your order yes or no.
>
>I'am willing to pat for it
>With kind regards 
>Jan



------------------------------

Date: Wed, 25 Feb 1998 22:24:46 GMT
From: dgwilson@gte.net (Douglas Wilson)
Subject: Re: CyberCash and Custom Script
Message-Id: <6d25ji$35k$1@gte2.gte.net>

On Wed, 25 Feb 1998 07:48:41 -0600, accuware@telerama.lm.com wrote:
>My friends and I a trying to sell few files over the Net, using CyberCash for
>on-line transaction processing. We do not have a lot of expirience with PERL
>scripting, and we are trying to set it up so we can connect to CyberCash, and
>process the requests, and release the files based upon the results. We are at
>the point were we need to make test transactions with CyberCash, and go live.
>We were unable to obtain sample scripts, or cart applications to connect.

cybercash comes with a couple of sample scripts,  and has
documentation on all their functions in a directory called 'doc' or
something like that. Once you understand the sample scripts inside and
out, and the other docs, then you ought to be able to write your own
app.

>Both CyberCash and our ISP were extremely uncooperative, and tried to push
>toward some pretty expensive off-the shelf solutions. If anyone can help,
>we'd really appreciate it.

Well, its not really their job to write your app for you. I've found
cybercash support to be helpful in other areas.



------------------------------

Date: Wed, 25 Feb 1998 22:47:25 +0200
From: Tzadik Vanderhoof <stvhoof@netvision.net.il>
Subject: Re: Easy way to "clean" an array
Message-Id: <34F4835D.469B@netvision.net.il>

To add my 2 cents...you might want to consider storing the numbers as
keys in a hash instead of an array...since a hash is incapable of
storing duplicate keys, when you're done storing your numbers, you can
just use the "keys" function to get a list of all the keys, and this
list is guaranteed not to have any duplicates.  (The "value" of each key
is not important so it could be "1" or anything you want).

Schwitter Ruedi wrote:
> Witch is the easiest way to check out the duplicated entrys ?




------------------------------

Date: Wed, 25 Feb 1998 21:59:21 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: file test inside grep()
Message-Id: <EoyFqy.52r@world.std.com>

Franklin Brodsky <fbrodsky@sedona.intel.com> writes:
[code deleted]
>Why is '-e' behaving the way '!(-f)' should?
[etc.]

Most of your problems seem to stem from the fact that readdir does not
return a full path to the file, just the filenames. So when you
readdir() a directory other than the current directory, you need to
prepend the directory name to the file to access it.

  @testfiles = grep ( /^$dir\/$dir/ , grep ( -f "$dir/$_", readdir(SUBDIR)));


And as an unsolicted helpful hint, maybe for some of your nested
grep()s, you can perform more than one comarison inside the grep
expression. For example:

@subdirs = grep { -d $_ and not /^\./ and /\./ } readdir WORKDIR;
and
@testfiles = grep { -f "$dir/$_" and m#^$dir/$dir# } readdir(SUBDIR);

-- 
Andrew Langmead


------------------------------

Date: Wed, 25 Feb 1998 20:48:35 GMT
From: me@here.com (steve)
Subject: Re: Help with access , CGI &  Java needed T.I.A
Message-Id: <34f97eef.106369409@news.cent.com>

if you are returning the values from the script to the Web site
visitor using java you have a problem, possibly,  and your explanation
is not thorough enough.
are you intending to use an application or an applet and does your
server have a java compiler ?
using an applet you want to set the parameters on the fly, based on
the clients query, unless you want to compile a new applet every time,
which would be silly, or unless you want the applet to communicate
with the script. your explanation of "..a java based web veiwer." is
not descriptive enough. Do you want the client to use their regular
Netscape or Microslosh browser to view this "java based " thing ?
or do you have a Java Browser (an application) that you want the
client to use instead ?

You say "let the client qurey the database via a CGI-script and return
the values into a java webpage template". If you mean that they will
use their regular browser, that conatins a java applet (it must be an
applet if they are using their regular browser) and that you want to
manipulate the applet based on the result of the CGI query, so that
the applet does something different depending on the results of the
query then you must use an applet with external paramaters set in the
html coding. the only other option would be to compile a new applet on
the fly which would be silly.

post more info on what you are trying to do.


On Wed, 25 Feb 1998 13:00:06 GMT, steve@pixieefc.demon.co.uk (pixie)
wrote:

>We have setup a unix web server and are trying to implement a client side database query with a return to a java based
>web veiwer.
>Ie our ultimate aim is to enter a clients details in Ms Acess, upload the .MDB file to the server , let the client qurey
>the database via a CGI-script and return the values into a java webpage template.
>
>If ANYBODY could point or show us what can/can't be done it would be Most helpfull.
>
> Thanks
>
>Bruce
> 



------------------------------

Date: Wed, 25 Feb 1998 15:58:13 -0500
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: Help with SYSTEM command?
Message-Id: <34F485E5.1CF5@gecm.com>

James R. McDonald wrote:
> 
> I'm working on a PERL program on VMS and one of the things
> I'd like the program to be capable of is to copy a file.
> I have the new file name as a variable, ie $newfile and
> I figured on using the system command to do it, but instead
> the program is copying the file and naming it $newfile.
> 
> ie:
> 
> $newfile=newdata.txt;
> system('copy oldfile.txt $newfile');
> 
> How can I get PERL (or VMS) to interpret the string $newfile
> when doing the copy command?

Try double quoting rather than single quoteing:


$newfile=newdata.txt;
system("copy oldfile.txt $newfile");

Cheers,

Jim




--


------------------------------

Date: Wed, 25 Feb 1998 17:01:22 -0500
From: Ying Hu <Y_Hu@fccc.edu>
Subject: Re: HELP! exec doesn't work properly!
Message-Id: <34F494B2.3F54@fccc.edu>

Lance wrote:
> 
> Hi,
> 
>     I have the following lines in a perl script on a HP-UX:
> 
>     open(jj,">junk") || die "Couldn't open junk: $!\n";
>     print jj <<EOF;                # line A
> 1
> 1
> 0
> 4
> 0
> 5
> 0
> 0
> EOF

close jj;	#try after close jj :)

> exec "trans.x < junk";        # line B
> 
> Note: "trans.x" is a Fortran executable file which uses "junk" as a
> redirected input file
> 
> But it just doesn't work! line A does generate the file "junk", but line B
> not only doesn't recognize "junk" but also makes it null.
> 
> If I comment line B and run the rest.  It generates  "junk". And then I
> uncomment line B and comment the rest of it. (so "junk" already exits)  and
> run it.   Line B works!  I don't understand why they can't work together.
> 
> Any advice will be greatly appreciated!
> 
> --
> Regards,
> Lance
> lsjATbnl.gov


------------------------------

Date: Wed, 25 Feb 1998 21:58:37 GMT
From: me@here.com (steve)
Subject: Re: How does the Perl-Interpreter works?
Message-Id: <350393f8.111755662@news.cent.com>

it interprets, maybe it was just a little horny on the first run ?



On Sat, 21 Feb 1998 12:46:04 +0100, Ingo Ruth
<ingo.ruth@stud.uni-erlangen.de> wrote:

>Hallo!
>
>I just coded a little perl-program and started it using the
>timex-command to measure time for executing it.
>
>I found out, that the first time the program took more time
>for executing than any further time. I think its because of the 
>interpreter.
>
>Can anybody explain, how the interpreter works?
>
>Thanks.
>Ingo Ruth



------------------------------

Date: Wed, 25 Feb 1998 17:22:54 -0500
From: schinder@leprss.gsfc.nasa.gov (Paul J. Schinder)
Subject: Re: HP-UX compile failure
Message-Id: <schinder-2502981722540001@ip187.state-college3.pa.pub-ip.psi.net>

In article <34F42F96.E6B@sdl.ug.eds.com>, Andrew Maguire
<andrewm@sdl.ug.eds.com> wrote:

} Micheal Mc Evoy wrote:
} > 
} > >> I'm trying to build perl 5.004_04 on a HP-UX 10.20 server, using the same
} > >> source as I used to build it on a Linux box and on an AIX server.
} > >>
} > >> Configure worked and didn't show any problems, make depend also
worked with no
} > >> errors or problems.
} > >Did you do a make realclean and delete your old config.sh
} > >before running Configure?
} > 
} I've just noticed that you're using gcc. I've been using HP's own
} compiler which works straight off (except the DBM stufff I aluded to :(
} )
} However I guess that as a server you don't have HP's cc
} -you could try dropping the optimisation down and see if it is
} a bug in gcc.

I'm sorry I missed the beginning of this to see what the actual error
messages were, but I may know the problem.  There's a bug in the Configure
script that been there for a few years at least (I really ought to perlbug
it some day) that screws things up if you try building Perl using gcc
under HP-UX.  It's been awhile since I last built perl, but as I recall,
the CFLAGS get set so that they include a flag that gcc interprets in a
way different from cc.  I think it's +Aa (or is it -Aa), which gcc
interprets as an (failing) assertion and cc interprets some other, benign,
way.  You've got to be careful to remove it at the appropriate prompt, and
then Perl will build cleanly:

cirsrss% perl -V
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
  Platform:
    osname=hpux, osvers=10, archname=PA-RISC1.1
    uname='hp-ux cirsrss b.10.20 a 9000735 2016483812 two-user license '
    hint=previous, useposix=true, d_sigaction=define
    bincompat3=y useperlio=undef d_sfio=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.7.2.2




} 
} Andrew

-- 
Paul J. Schinder
NASA Goddard Space Flight Center
schinder@leprss.gsfc.nasa.gov


------------------------------

Date: Wed, 25 Feb 1998 21:43:56 GMT
From: me@here.com (steve)
Subject: Re: IP-Address in Perlscripts
Message-Id: <34ff906e.110849708@news.cent.com>

$ENV{'REMOTE_ADDR'}   as in        $callers_ip = $ENV{'REMOTE_ADDR'} ;


On Mon, 23 Feb 1998 05:10:04 -0600, 100.191995@germanynet.de wrote:

>If a Perlscript is called on a WWW-Server, is there any way to get the
>IP-Address of the caller?
>
>If there are any ideas please send me an eMail to: 100.191995@germanynet.de.
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/   Now offering spam-free web-based newsreading



------------------------------

Date: Wed, 25 Feb 1998 21:40:15 GMT
From: me@here.com (steve)
Subject: Re: Need some advice,  why dont you just do this
Message-Id: <34fe8f72.110597851@news.cent.com>

2 ways:
add you own email address as the last address, if it gets that far
you'll know about it.  or.. set the script to return the response
first to the browser,  not a good idea.


On Tue, 24 Feb 1998 11:45:15 +1000, "Brad Grove"
<pyefinch@b130.aone.net.au> wrote:

>Hi all
>
>I am reasonably new to PERL and have managed to develop some rather useful
>scripts for our company web site. We do not have our own server, but use an
>ISP (virtiual server) which probably makes things a little more difficult
>when debugging.
>
>My problem is this:
>
>I have developed a bulk emailing script which will read our web database and
>email each of our customers in the database. For each record in the
>database, it simply checks for a valid email address etc and passes the data
>with the results of the form (passed from a browser) to the ISP's mail
>program. It seems to work well except it does not send any response back to
>the browser until the script has completed. If the email list is long, then
>the browser times out and seems to end the script without me knowing just
>what was sent.
>
>Is there a way of controlling server processes whereby the server can pass
>back an acknowledgement to the browser and continue on it's mary way
>processing the emial. At least then the browser wouldn't just sit there
>after pressing the submit button on the form until it times out with an
>error message. The last emial address in the database could simply be a
>confirmation of the completed task which is sent to me.
>
>Anybody got any ideas?
>
>Regards
>
>Brad Grove.
>
>



------------------------------

Date: Wed, 25 Feb 1998 22:51:11 +0200
From: Tzadik Vanderhoof <stvhoof@netvision.net.il>
Subject: Re: No. of days??
Message-Id: <34F4843F.48B4@netvision.net.il>

Watch out for that year2000 problem lurking in your code!!!  That's
probably more important than what you're trying to do... :)

S. Sarkar wrote:
> the input format is yy/dd/mm or dd/mm/yy or mm/dd/yy



------------------------------

Date: Wed, 25 Feb 1998 16:06:43 -0500
From: "Fabian Tiburce" <nospamfabian.tiburce@cgi.ca>
Subject: overload.pm
Message-Id: <6d21aj$rtc$1@newsbell.bellglobal.com>

I am really struggling with this one.  Anyone's insight into a solution
would be greatly appreciated...

Environment:
==========
NT Server 4.0 and have installed Perl 5.001
I have also installed an OBDC module.
Downloaded and installed cgi.pm

What I can do:
============
I am able to run a script that queries a database (using a static SQL
statement) using the DSN I have defined and write the results to screen.
Example:
$sql_statement = "select * from $table where field1 = 'test' and field2 =
'test'";

What I can't do:
==============
Request the values of a form post and plug that into my SQL statement in
Perl so it is dynamic.
Example:
$sql_statement = "select % from $table where field1 = $field1 and field2 =
$field2"; where "field1" and "field2" are the form fields filled in the
previous step.

My scripts reads:
===============
use CGI;
$area = $query->param('field1');
$nxx = $query->param('field2');

I get the following error:
===================
Can't locate overload.pm in @INC at C:\InetPub\Perl\perl5\lib/CGI.pm line
2755. BEGIN failed--compilation aborted at C:\InetPub\Perl\perl5\lib/CGI.pm
line 2755. BEGIN failed--compilation aborted at
C:\InetPub\wwwroot\Bell\scripts\numbersearch.pl line 17.

I am going nuts after having tried so many things.  Any ideas?

Fabian T.





------------------------------

Date: 25 Feb 1998 21:26:29 GMT
From: elf@halcyon.com (Elf Sternberg)
Subject: Re: Philisophical Response? Perl5/oop
Message-Id: <6d22a5$9uh$1@brokaw.wa.com>

In article <autopen-2202981053190001@dynamic58.pm07.mv.best.com> 
    autopen@autopen.com (Laurel Shimer) writes:

>When we talk he always says 'you are going to need to write this (new
>code) in Perl 5'. It seems to me that since I invoke the Perl5 interpreter
>and use functions that are new to Perl 5 (chomp, newer version of
>subroutine calls, etc.) that I am 'writing in Perl 5'. He, of course,
>feels that to write in Perl 5 is to write object oriented only.

	You are writing in Perl 5.  The poor boy needs a small
clue upside the head.  I write OO Perl all the time (I even write
Internet servers in multi-threaded, object-oriented Perl/XS with
semantics from Design Patterns and naming conventions from Taligent--
I am totally buzzword-compliant) and I don't write _everything_ in
OO Perl.

	"Perl is a language for getting your job done."  So wrote 
Larry Wall and so it stays.  If you're getting your job done-- and 
remember that part of your job description includes making what you
write maintainable-- then you are using Perl correctly.

		Elf

--
It is forbidden to laugh again               Elf M. Sternberg
We maim our joys or hide them                www.halcyon.com/elf
Horses are made of chromium steel
And little fat men shall ride them.  - T.S. Eliot


------------------------------

Date: Wed, 25 Feb 1998 15:55:30 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Prisoners of the evil empire
Message-Id: <34F48542.53D1@min.net>

John Porter wrote:
> 
> Matthew Pryor wrote:
> >
> > Can someone tell me what a Prisoner of the Evil Empire actually is?
> 
> Why, none other than the empire ruled by Bill "Sauron" Gates.

(re-reading that, it looks wrong.) I meant to say:
  A Prisoner of the empire ruled by Bill "Sauron" Gates.


------------------------------

Date: Wed, 25 Feb 1998 13:08:00 -0800
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
Subject: Regex substitutions
Message-Id: <34F48830.E6D72D5D@cks.ssd.k12.wa.us>

I'm stuck on a regex.

I have a scalar consisting of a variable number of characters, followed
by zero, one or two sets of parens arround a single character.

Three examples are

Beacon Hill
Beacon Hill (B)
Beacon Hill (B)(D)

I need to concatenate another string between the parenthesis and the
text string.

So 'Beacon Hill (B)' becomes 'Beacon Hill Half Day K (B)'

However I can only get one set of parens to match for substitution.  If
some kind soul would look over my regex and tell me what I'm missing,
I'll drink an extra beer for you tonight!  (Gratitude is a Good Thing)

$schlnm =~ s/                               # Start a substitution regex

                    (.+)                          # Match all the text
from the begining of the string and assign it to $1
                   (\(.\))                        # Match a paretethis
surounding a character i.e. (G) and save it in $2
                    {0,2}                       # Match at least zero
but no more than two of the last group
                /$1 Half Day K $2/x;    # Substitute the match with this
and add some comments.

I have tried other variations with character classes like
s/(.+)([\(.\)]{0,2})/$1 Half Day K $2/;

which works as long as there is only one or no sets of parens.  If there
are two I ususaly I'll end up with 'Beacon Hill (B) Half Day K (D)'

Any tips, pointers (I've read perlre, the camel, llamma and owl, and
looked in the FAQs, so if the answer is in there, a page number would
help) or clues are much appreciated.

Jerome "Please God Don't Let It Be A FAQ" O'Neil
Seattle Public Schools
Information Services



------------------------------

Date: Wed, 25 Feb 1998 13:11:02 -0800
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
Subject: Re: Regex substitutions
Message-Id: <34F488E6.F7F4D3@cks.ssd.k12.wa.us>

And could you recomend a decent news reader, too.  Thanks

Jerome O'Neil wrote:

> $schlnm =~ s/                               # Start a substitution regex
>
>                     (.+)                          # Match all the text
> from the begining of the string and assign it to $1
>                    (\(.\))                        # Match a paretethis
> surounding a character i.e. (G) and save it in $2
>                     {0,2}                       # Match at least zero
> but no more than two of the last group
>                 /$1 Half Day K $2/x;    # Substitute the match with this
> and add some comments.






 .



------------------------------

Date: 25 Feb 1998 21:56:20 GMT
From: jack_h_ostroff@groton.pfizer.com (Jack Ostroff)
To: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
Subject: Re: Regex substitutions
Message-Id: <6d2424$30a1@mascagni.pfizer.com>

In article <34F48830.E6D72D5D@cks.ssd.k12.wa.us>, 
Jerome O'Neil <joneil@cks.ssd.k12.wa.us> is trying to turn:
> Beacon Hill (B)(D)
 into
> Beacon Hill Half Day K (B)(D)
 using
> $schlnm =~ s/(.+)(\(.\)){0,2}/$1 Half Day K $2/x

You forgot that the first match (.+) is greedy, and is matching
everything it can and still allow the second part to match.
What you probably want is to limit the first part of the match

> $schlnm =~ s/(.+?)(\(.\)){0,2}/$1 Half Day K $2/x

note the "?" after the .+

A very quick search found references to this in perlfaq6
and perlre.  It's also on pages 29 and 63 of the blue camel
and 80/81 of the blue llama.

Good luck

Jack Ostroff
jack_h_ostroff@groton.pfizer.com



------------------------------

Date: Wed, 25 Feb 1998 17:42:16 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: Regex substitutions
Message-Id: <34F49E48.DFE1215C@shopcfn.com>

Jerome O'Neil wrote:
> I have a scalar consisting of a variable number of characters, followed
> by zero, one or two sets of parens arround a single character.
> 
> Three examples are
> 
> Beacon Hill
> Beacon Hill (B)
> Beacon Hill (B)(D)
> 
> I need to concatenate another string between the parenthesis and the
> text string.
> 
> So 'Beacon Hill (B)' becomes 'Beacon Hill Half Day K (B)'
> 

my idea is to replace the end of the string, that is all the
parens and their possible leading space, with themselves
preceded by a space and the string to add.

#!/usr/bin/perl -w
$scalar0 = 'Beacon Hill';
$scalar1 = 'Beacon Hill (B)';
$scalar2 = 'Beacon Hill (B)(D)';
$add = 'Half Day K';

for ($scalar0, $scalar1, $scalar2) {
  # s/(\s*(?:\(.\)){0,2})?$/ $add$1/;
  s/(              # begin optional capture
     \s*           # 0 or more spaces
     (?:           # begin group
      \(.\)        # grab parenthesized letter
     ){0,2}        # between 0 and 2
    )?             # end optional capture
   $/ $add$1/x;    # tied to end of string
  print "$_\n";
}

-- 
dan boorstein <dboorstein@shopcfn.com>
#!/usr/bin/perl -w -- 2 for 1
# my first Just another Perl hacker,
seek DATA,0,0;{$_=<DATA>,/#!/&&redo}print join(' ',(split)[3..6])__END__
# my second Just another Perl hacker,


------------------------------

Date: Wed, 25 Feb 1998 16:09:40 -0500
From: Yu Xie <xieyum@nortel.ca>
Subject: Replacement of characters
Message-Id: <34F48893.C07C6FF5@nortel.ca>

Hi,

I have a question with regard to replacement of several character to one character in a string.
If I have a string as followes:

$buffer = "He%28Mike%29 is a good teacher.";

I want to replace %28 to ( and %29 to )
However, when I execute the following command:

$buffer =~ tr/%28/(/;
$buffer =~ tr/%29/)/;

the result is "He(((Mike))) is a good teacher.

I am wondering if there is another command that will replace multiple character with one
character, or multiple characters.

thanks for your help!

Xie, Yu
Email: xieyum@nortel.ca





------------------------------

Date: 25 Feb 1998 22:34:10 GMT
From: corey@carnivore.net (Corey)
Subject: Script error need help please....
Message-Id: <6d2693$pnq$1@yakuza.fc.net>

I'm trying to add a subroutine to this script that will add city shipping tax
if certain fields values are met..will someone tell me why this isn't working?

sub  calculate_tax  {

$tax = 0;

$tax_total = $discount_total;

if (lc $taxtype eq 'none')
	{return 0;}
else {  #### Calculate for the Default Tax Type

	#### Add Tax if tax should be added for the customer's State ####
	if (uc $country eq 'USA') {
		foreach $Tax_State_Rate (@Tax_States) {
			($Tax_State, $Tax_Rate) = split(/ /,$Tax_State_Rate);
			if ($state eq $Tax_State){
				$tax = $sub_total * ($Tax_Rate / 100);
				$tax = $sub_total * ($Tax_Rate / 100);
				$tax = sprintf("%.2f", $tax);
				$tax_currency = &Currency($tax);
				$tax_total = $discount_total + $tax;	
	
				$order_total += $tax;
				last;
			}	
		}
	}
{
		
		foreach $Tax_City_Rate (@Tax_City) {
			($Tax_City, $Tax_Rate) = split(/ /,$Tax_City_Rate);
			if ($city eq $Tax_city){
				$tax = $sub_total * ($Tax_Rate / 100);
				$tax = $sub_total * ($Tax_Rate / 100);
				$tax = sprintf("%.2f", $tax);
				$tax_currency = &Currency($tax);
				$tax_total = $discount_total + $tax;	
	
				$order_total += $tax;
				last;
			}	
		}
	}



	return $tax;
}
 


}#sub



------------------------------

Date: Wed, 25 Feb 1998 21:28:36 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: sorting array
Message-Id: <EoyEBp.9ny@world.std.com>

Brian Charles <charlesb@ccmail.orst.edu> writes:

>    I have a file with the following info that I would like to hash:
>lastname|firstname|email|code

>Right now I have a hash with a key and value and it sorts fine, but how
>do I have more than one value? Just point me in the right direction.

As the FAQ and the entry on sort in the perlfun man page suggests, the
best thing to do is to split up the data into separate sortable
elements, and compare each separately.

<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/
How_do_I_sort_an_aray_by_anyth.html>
<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfunc/sort.html>

while(<>) {
   chomp;
  ($lastname,$firstname,$email,$code) = split /\|/;
  $hash{$lastname} = {firstname => $firstname, email => $email, code =>$code};
}

for $lastname ( sort by_fullname keys %hash ) {
  print "$lastname $hash{$lastname}{firstname} $hash{$lastname}{email}", 
	"$hash{$lastname}{code}\n";
}

sub by_fullname {
  $hash{$a} cmp $hash{$b} or $hash{$a}{firstname} cmp $hash{$b}{firstname}
}
-- 
Andrew Langmead


------------------------------

Date: Wed, 25 Feb 1998 16:26:39 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: Splitting on 2 line feeds?
Message-Id: <34F48C8F.BFF1B9A2@shopcfn.com>

kperrier@neosoft.com wrote:
> 

[snip]

> What I want the script to do (btw perl 5.004_4 on AIX 4.1.4) is read in the
> output of the lsuser command (it gives output in the format above) and in each
> element of the array have each users information, i.e. I want to split on the
> two /n characters that separate the records.
> 

[snip]

what you are looking for is the 'input record separator' which you
can set by assigning the variable '$/'. in this case you want the
separator to be '', which puts the reading in 'paragraph' mode. once
you do this your data should fall neatly into' @DATA', and you can
do away with '@CHUNKS'.

good luck,

-- 
dan boorstein <dboorstein@shopcfn.com>
#!/usr/bin/perl -w -- 2 for 1
# my first Just another Perl hacker,
seek DATA,0,0;{$_=<DATA>,/#!/&&redo}print join(' ',(split)[3..6])__END__
# my second Just another Perl hacker,


------------------------------

Date: Wed, 25 Feb 1998 22:06:09 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: substitution - control characters
Message-Id: <EoyG2A.Eyt@world.std.com>

whitp@ci.winston-salem.nc.us writes:

>Can someone diagram the \cM portion of the following subtitution function?
>$body =~ s/\cM//g;

According to the perlop man page, the left hand side of the
substitution operator goes through and interpolation similar to double
quoted strings. Also according to the perlop man page, the "\c"
backslash sequence gives the control character of the following
character. Control-M is the carriage return character. The /g modifer
does the replacement globally throughout the scalar.

So this line deletes all control-M characters from the variable $body.

<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlop.html>
-- 
Andrew Langmead


------------------------------

Date: 25 Feb 1998 21:28:44 GMT
From: billy@cast.msstate.edu (Billy Chambless)
Subject: Re: The Ineffable Tom C.
Message-Id: <6d22ec$82q$1@nntp.msstate.edu>

In article <34f471f9.9584078@news.clara.net>, wrdcom@clara.net (Sean Ahern) writes:
|> On 25 Feb 1998 11:43:14 +0000, James Gillespie
|> <jim.gillespie@ssmb.com> wrote:


|> >    Hmmm, my copy doesn't have a page xxvii.  Page xv has a bit about
|> >usenet groups though.  Maybe you meant the bit which says: "Like Perl
|> >itself, comp.lang.perl.misc is meant to be useful, and no question is
|> >too silly to ask(*)."

|> 	I repeat, 2nd Edition.  Where the portion you mention is on
|> page xx.
 
 
|> >    The asterisk is a typesetting convention meaning, "look at the
|> >bottom of the page for a footnote."
	
|> 	Is it?  Oh silly me.  Gee, I should I have tried the
|> typesetters newsgroup?

Oh, how witty!! You sure puts him in his place!

I wonder why you didn't have a similar witty comeback for the passge you
quoted below -- the one that makes your original reference to _Learning
Perl_ seem a bit silly.

|>  In this case, the footnote reads:
|> >"(*) Of course, some questions are too silly to answer, especially
|> >those already answered in the FAQ."

-- 
* "And there _is_ a real world. In fact, some of you
*    are in it right now."  -- Gene Spafford


------------------------------

Date: Wed, 25 Feb 1998 14:31:50 -0800
From: Jason Christian <jason@primal.ucdavis.edu>
Subject: Re: Unwanted Character Displays
Message-Id: <Pine.OSF.3.95.980225142759.316N-100000@primal.ucdavis.edu>

On Wed, 25 Feb 1998 bfredett@sprynet.com wrote:

> Greetings group.
> 
> I'm extremely new to Perl so take it easy on me.  (~_^)  Thanks to everyone
> for their pointers to resources and FAQ's...they were a big help.
> 
> I have this code to read in a text file and store it in a variable:
> 
> my $headline = open IN, "headline.txt" || die $!;

$headline gets the return value for the open.  "1" if it worked...


> 	while (<IN>)  {
> 	$headline .= $_;

Concatenate onto the scalare $headline, which has the value "1" after
the successful open(),the lines coming from <IN>.

> 	}
> close(IN);
> 
> $foo{test} = $headline;
> 
> Then in an HTML template, $headline is printed with %%%test%%%.  What
> I want to happen does except for a number 1 appears in the html.
> 
> Any suggestions?

Use a variable other that $headline to receive the return from open().


---------------------------------------------------------------------------
Jason Christian                          University of California, Davis 
jason@primal.ucdavis.edu                  Agricultural and Resource Economics
Office:(530)752-1357 FAX:(530)752-5614   Davis, CA 95616



------------------------------

Date: Wed, 25 Feb 1998 21:14:04 GMT
From: me@here.com (steve)
Subject: Re: Why install perl?
Message-Id: <34fa83e8.107643141@news.cent.com>

As is, on your PC you can only run perl scripts from the command line,
DOS promt. If you program your scripts to work on your PC, then they
wont work on the Web server (from a browser) unless you modify them.
However, it is a good idea to install Perl on your PC anyway as it
will give you a better understanding of PERL in the long run and you
also get the benefit of using PERL on your PC, it can be very useful
some times.


On Wed, 25 Feb 1998 09:01:13 -0500, Hansen <defaultuser@domain.com>
wrote:

>Hello
>
>I am just beginning to learn perl.  I did not see in the text I've been
>using (Gundavaram's CGI Programming on the WWW) that I need to install
>perl on my system.  I find that the online tutorial that I'm going
>through says that I need to install it.
>
>I am trying to learn this cgi scripting tool in order to develop forms
>for several pages I've developed or maintain.  I work from my home PC
>and ftp my stuff to the campus server.
>
>The scripts I've been playing around with have been written on MSWord,
>saved as text, and ftp'd to the server.  I then test them with Netscape.
>
>Would installing it allow me to test the scripts without ftp-ing?
>
>Victoria
>



------------------------------

Date: 25 Feb 1998 22:30:46 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Why install perl?
Message-Id: <6d262m$f48$1@marina.cinenet.net>

steve (me@here.com) wrote:
: As is, on your PC you can only run perl scripts from the command line,
: DOS promt. If you program your scripts to work on your PC, then they
: wont work on the Web server (from a browser) unless you modify them.

Not sure what you mean by this...I develop and test scripts on my PC then
run them unmodified on a Unix webserver almost every day.  What makes you
think this is impossible?

---------------------------------------------------------------------
   |   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: Wed, 25 Feb 1998 14:31:26 -0800
From: Steve Fink <sfink@cs.berkeley.edu>
Subject: XS dynamic loader: how to push C args?
Message-Id: <34F49BBD.3ED8@cs.berkeley.edu>

Probably the wrong place to be asking, but...

I am trying to write an XS module that will allow something like:

load_function('sine', "/lib/libm.so", "sin", [ 'double' ]);
$x = sine(3.14);


It's all easy to do (in fact, the above works, and took me about 15
minutes to get working last night), except for passing the arguments to
the C function. For an arbitrary list of arguments, I don't see a
reliable way to push the arguments onto the stack using C's calling
conventions.

I can of course do a switch based on every possible type (actually,
size) of parameter and let the C compiler figure it out when it compiles
the XS routine, but that doesn't scale. Example:

if (strcmp(argsizes, "424") == 0) {
	double (*func)(int,short int,int) = func_ptr;
	int arg1 = *((int*) args)++;
	int arg2 = *((short int*) args)++;
	int arg3 = *((int*) args)++;
	RETVAL = func(arg1,arg2,arg3);
else if (strcmp(argsizes, "144") == 0) { ...

I could generate a small C program containing the appropriate sort of
function (e.g., dynamic_func_444_returning_double) and suck it in, but
that's kinda slow.

stdarg.h doesn't work for constructing calls to functions with variable
numbers of arguments.

gcc almost allows this with its __builtin_apply_args stuff, but not
quite. Although that could be hacked to work, perhaps.

Yes, I know that this is extremely brittle. It is sensitive to the
dynamic loading interface, the compiler used to compile the XS stuff,
and so on. But it would allow a lot of quick and dirty stuff with much
less pain and effort than XS programming (imagine a shared library
browser that lets you call any function in the lib), and I would really
like it to prototype possible XS functions whose interface may be
changing rapidly and for which I can't justify spending the time and
directory space to do a full XS module of just yet. Although from the
looks of SWIG, maybe I should just bite the bullet and use it for most
of this, it's quite nice...

Any comments/hints/suggestions are welcome, including telling me why I'm
an idiot for not using a completely different approach.

Thanks,
Steve


------------------------------

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 1974
**************************************

home help back first fref pref prev next nref lref last post