[11750] in Perl-Users-Digest
Perl-Users Digest, Issue: 5350 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 10 21:07:28 1999
Date: Sat, 10 Apr 99 18:00:19 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 10 Apr 1999 Volume: 8 Number: 5350
Today's topics:
Count Linenumber <debot@xs4all.nl>
Re: Couple of Questions <robsmith@yahoo.com>
Re: dir list utility <ebohlman@netcom.com>
Re: dir list utility (Tad McClellan)
Dynamically loading perl modules <johnnyb@shawneeok.com>
Help my with cookie, pls. <beton@topnet.pl>
Re: HELP-shopping cart help (EME888)
Re: How do i write a program that will spell a word eve (Scott Porter)
how to read multipart HTML mail kidkaboom@my-dejanews.com
Re: How to Restrict CGI access? multilinks@my-dejanews.com
Just another flocking question (Bill Moseley)
Re: Just another flocking question <gabriele@lachesis.clotho.com>
Re: No clues to Win32::NetResource problem? <CharlieL3@netscape.net>
On installing ActivePerl - Build 514 ... does not compl <bobtall@eweb.net>
Re: On installing ActivePerl - Build 514 ... does not c <ffchopin@worldnet.att.net>
passing variables from PERL to JavaScript <cyberjeff@sprintmail.com>
Re: PPM has created a new dir. <greg2@surfaid.org>
Re: pragma - relevant? (Tad McClellan)
Re: strcmpi() and toupper() in Perl (Tad McClellan)
Stripping the leading character <mtb@velorevolution.tzo.org>
Re: Stripping the leading character (Mike Stok)
Re: Stripping the leading character <jeffp@crusoe.net>
Re: Stripping the leading character <ffchopin@worldnet.att.net>
Re: Text Search Program <Klaus.Schilling@home.ivm.de>
Writers wanted for zine articles. (Port Lord)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 11 Apr 1999 00:53:24 +0200
From: Frank de Bot <debot@xs4all.nl>
Subject: Count Linenumber
Message-Id: <370FD664.4B6F484A@xs4all.nl>
How can I count the number of lines WITHOUT a loop in a file?
and how can I count the number of lines WITHOUT a loop that are
containing something in a file?
Thanks.
--
\\\|///
\\ - - //
( @ @ )
/----------------------oOOo-(_)-oOOo--------------------\
| |
| |
| My Email: debot@xs4all.nl |
| Homepages: http://www.searchy.net/ |
| http://www.debot.nl/ppi/ |
| |
| |
\-------------------------------Oooo--------------------/
oooO ( )
( ) ) /
\ ( (_/
\_)
------------------------------
Date: Sat, 10 Apr 1999 15:42:46 -0500
From: Robert Smith <robsmith@yahoo.com>
Subject: Re: Couple of Questions
Message-Id: <370FB7C6.19AEC302@yahoo.com>
Hi
Thanks for your help I used do "banner.pl"; or use "banner.pl"; But it
puts Content-type: text/html in the .pl file and is it possible to include
more that one .pl file in there???
Jason Simms wrote:
> > You sent me a stealth CC. *BAD*! Look at my header line
> > above. Go thou and do likewise.
>
> Yes, yes... Sorry about that - the wrong reply option was inadvertantly
> selected from the menu...
>
> Jason Simms
------------------------------
Date: Sat, 10 Apr 1999 19:23:47 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: dir list utility
Message-Id: <ebohlmanF9zn7n.E39@netcom.com>
BLUESRIFT <bluesrift@aol.com> wrote:
: > Jonathan Feinberg suggests using something like:
: >use LWP::Simple;
: > $content = get('http://www.foo.com');
: This captures the contents of an individual file which would be the index or
: default html file for the given http address. My goal is to capture the names
: of files contained in a directory. The purpose is to allow users to choose
: among these files (even if those files are not referenced by an index or
: default html file).
Unfortunately, that's impossible to do. HTTP provides no facilities for
listing directories (it doesn't even know what a "directory" is). All it
does is let you ask a server for a resource with a specific name; it's
entirely up to the server what to return in response to such a request.
There's no standard convention for saying that a particular sort of
resource name should be considered a request for a directory listing, or
how such a listing should be formatted.
Of course, if you have control over the server as well as the client
application, you could certainly make up such a convention, and write
code to implement it on the server side. But for listing directories on
arbirtrary servers, there's no solution.
------------------------------
Date: Sat, 10 Apr 1999 12:24:05 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: dir list utility
Message-Id: <5vtne7.k81.ln@magna.metronet.com>
[ please limit your line lengths to the customary 70-72 characters ]
BLUESRIFT (bluesrift@aol.com) wrote:
: >What about just using opendir/readdir?
: Actually, I have already tried that and am able to get a listing when I supply
: an absolute path eg /absolutepath/ but when I substitute a valid http:// path
: no listing is produced.
: What am I doing wrong?
Confusing a file specification with a URL.
How to translate a URL to a file spec (which is what you need
to do to open() it) is not a Perl thing, and is therefore
off-topic for this newsgroup.
It is an HTTP/CGI/server thing. Try asking in a newsgroup
where such things are discussed, such as:
comp.infosystems.www.authoring.cgi
comp.infosystems.www.servers.mac
comp.infosystems.www.servers.misc
comp.infosystems.www.servers.ms-windows
comp.infosystems.www.servers.unix
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 Apr 1999 15:56:26 -0400
From: Jonathan Bartlett <johnnyb@shawneeok.com>
Subject: Dynamically loading perl modules
Message-Id: <370FACEA.DC6C147F@shawneeok.com>
How do you dynamically load Perl modules at run time? Specifically, I'm
wanting to create a pluggable system like DBI/DBD where, a program has
access to any subclass of a specific package. I've looked at the
DBI/DBD code a little bit, but can't make any sense of it. Anyway, for
example, lets say I had a package like this:
package BaseExtensionClass;
sub new
{}
sub doSomethingReallySpecial
{}
Then, I let other people write subclasses that override sub
doSomethingReallySpecial that put BaseExtensionClass in the @ISA. Then,
I want my program to be able to find all of the installed subclasses of
BaseExtensionClass at runtime, query their interface, and load the
applicable class, and then create instances. Does anyone know how to do
this, or can point me to a tutorial on it? I suspect DynaLoader has to
do with the answer, but the perldocs on it didn't help. Thanks in
advance,
Jonathan Bartlett
------------------------------
Date: Sat, 10 Apr 1999 23:40:04 +0200
From: "Robert" <beton@topnet.pl>
Subject: Help my with cookie, pls.
Message-Id: <pyPP2.2878$lN.49976@news.tpnet.pl>
Hi,
There are 2 pages in ASP. First serve to login
to the second. When I post to the first I got
cookie in HTTP header from server, for example:
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Fri, 09 Apr 1999 22:36:44 GMT
Content-type: text/html
Set-Cookie: ASPSESSIONID=IOKGKQQZLBSJWXVB; path=/home
Cache-control: private
Connection: close
What should I repost to the server to get to the
second page ?
I tried to post that:
Cookie: $Version="0"; ASPSESSIONID=IOKGKQQZLBSJWXVB; $Path="/home";
browserName=&browserVersion=&login=mylogin&password=mypassword
But it didn't work. I received this, in place of real second
page:
<head><title>Object moved</title></head>
<body><h1>Object Moved</h1>This object may be found <a
HREF="second.asp">here</a>.</body>
The same effect is when I post only login parameters:
browserName=&browserVersion=&login=mylogin&password=mypassword
without cookie. I think that server didn't accept
my cookie because of somewhat misspelling
problem. Am I right ? Is there a way to check that ?
Maybe I don't understand something and $ and "
signs are unnecessary. I used to use HTTPPost
from http-lib.pl, so my cookie is posted via this
function, and maybe it is doing split or something
else with its parameters. Please, tell me what is
the correct, raw format of cookie's posted to the
server and what code you are using to post it ?
Regards,
Robert
------------------------------
Date: 10 Apr 1999 20:03:27 GMT
From: eme888@aol.com (EME888)
Subject: Re: HELP-shopping cart help
Message-Id: <19990410160327.28894.00001872@ng-cg1.aol.com>
Hello
I am not an expert in perl but I use perlshop in my site. I may not answer you
right away but you can send your question to
Randy@edps-nj.com
I would really like to see a perlshop newsgroup because alot of people use it.
------------------------------
Date: Sun, 11 Apr 1999 00:30:06 GMT
From: scott@quick-silver.demon.co.uk (Scott Porter)
Subject: Re: How do i write a program that will spell a word every way possible?
Message-Id: <370feb57.311017@news.demon.co.uk>
On Sat, 10 Apr 1999 12:31:39 -0600, Collin Starkweather <collin.starkweather@colorado.edu> wrote:
[...]
>The trick is to write a perl script that will write the above logic in
>the form of a perl script for a string of arbitrary length.
Yes, I can see how the logic works in that example. As you say
though, the method for handling randomly sized words would
differ from the above. For instance, building a function that
could be passed a string, and output every possible mixture
of characters into an array. I'm sure some clever sod will come
up with a 3 line script to handle anything though :)
Could be an interesting project for setting/solving puzzles etc...
--
Scott <http://www.javascript-games.org/ >
< Homepage: http://www.quick-silver.demon.co.uk/ >
Dynamic site: DHTML games/music/general eye candy!
------------------------------
Date: Sat, 10 Apr 1999 23:25:39 GMT
From: kidkaboom@my-dejanews.com
Subject: how to read multipart HTML mail
Message-Id: <7eomlg$c1v$1@nnrp1.dejanews.com>
I am writing a program that will retrieve mail from a pop server, then when
you select a message it will display the To, From, Subject, and Date headers.
Then it will display the message below. This is all fine and dandy, I didn't
have any problems with this, but when this address recieves a multi-part
email it displays it straight as it is, which looks like this:
This is a multi-part message in MIME format.
------=_NextPart_000_001F_01BE8063.154DF220
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
test......................From Theodore
------=_NextPart_000_001F_01BE8063.154DF220
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 =
size=3D2>test......................</FONT><FONT=20
color=3D#000000 size=3D2>From Theodore</FONT></DIV></BODY></HTML>
------=_NextPart_000_001F_01BE8063.154DF220--
>>end the crap that is outputted
This is displayed in the browser, so the HTML tags don't show up, but it still
has some parts showing up twice...
ANyways, to the point. I was wondering if anyone else has come across this
and how they solved it. I couldn't find any modules that work with HTML mail
(or else I missed it if there are any)
>From Theodore
PS, you can email me a copy of your reply, I don't mind at all...
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 10 Apr 1999 23:28:29 GMT
From: multilinks@my-dejanews.com
Subject: Re: How to Restrict CGI access?
Message-Id: <7eomqp$c2n$1@nnrp1.dejanews.com>
In article <m1hfqotm44.fsf@halfdome.holdit.com>,
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "global3" == global3 <global3@my-dejanews.com> writes:
>
> global3> I am trying to modify the access.conf server configuration file to
> global3> restrict CGI access from remote hosts to CGI files in a particular
> global3> directory yet allow CGI access in the same directory for visitors to
my
> global3> web site (i.e., people who come using their browsers). I have been
trying
> global3> this code:
>
> Hmm. I missing something here, or perhaps you are.
>
> What is the difference between "access from remote hosts" and "access
> in the same directory for visitors"? How does it look any different
> to the web server?
>
> I suspect it doesn't, and hence, your problem is unsolveable.
>
> And, for the record, this is *not* a Perl question. You would have
> gotten much more precise response posting in
> comp.infosystems.www.authoring.cgi.
>
> --
> Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
> Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
> Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger
merlyn@teleport.com)
> Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
> Quote: "I'm telling you, if I could have five lines in my .sig, I would!" --
me
>
I am following up for Agni. I will try the group you mentioned. I can do
what is described here using PERL but I cannot from the web server level. If
I use the PERL code:
$remote = $ENV{'REMOTE_ADDR'};
$refer = $ENV{'HTTP_REFERER'};
unless ($refer =~ /mydomain\.net/ || $refer =~ /365\.1\.14\.97/ || $remote =~
/365\.1\.14\.97/) {
exit;
}
This allows me to restrict all remote hosts from accessing my CGI script yet
anyone that actually visits my web site with a browser will be able to access
my CGI scripts. The problem here is that PERL must still be called to
enforce this restriction. I want to block remote hosts before they get to
PERL and costs me server resources.
Hope this is clearer and that you can help. Thanks for your time.
Vladimir
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 10 Apr 1999 14:25:35 -0700
From: moseley@best.com (Bill Moseley)
Subject: Just another flocking question
Message-Id: <MPG.117961a577d0f2e3989725@206.184.139.132>
This is really more of a general programming question.
I have a perl CGI script that logs all 404 errors at a site. It locks
the log file, as it should.
I have another CGI program that creates a report from the log file. I
used to use a shared lock when reading, but as the reports took longer to
generate the 404 script started timing out waiting for the exclusive
lock. So, I removed the lock from the reporting part.
What I want to know is how to deal with reading from the file which may
be in the middle of an write operation. The log file is one line per
record, so would it be safe enough in my reporting program to just ignore
the (last) line if chomp returned zero? (Assuming that if chomp returned
zero there wasn't a new line, and thus the other program is in the middle
of writing to the file.) Of course, the write buffer is probably larger
than my line length.
Anyway, does checking chomp for a zero return seem safe enough?
Oh, I almost forgot to add some perl code to this post:
last unless chomp;
BTW -- where's a good place to ask general programming questions? For
example, general questions about building a perl DBM application
that uses Berkeley DB? I'm not having problems with the perl or using
Berkeley DB, but general questions about transaction control, maintaining
data-base integrity, and so on.
--
Bill Moseley mailto:moseley@best.com
------------------------------
Date: Sat, 10 Apr 1999 19:45:30 -0500
From: "Gabriele R. Fariello" <gabriele@lachesis.clotho.com>
Subject: Re: Just another flocking question
Message-Id: <7eorbc$1ap@newsops.execpc.com>
On Sat, 10 Apr 1999, Bill Moseley wrote:
> What I want to know is how to deal with reading from the file which may
> be in the middle of an write operation. The log file is one line per
> record, so would it be safe enough in my reporting program to just ignore
> the (last) line if chomp returned zero? (Assuming that if chomp returned
> zero there wasn't a new line, and thus the other program is in the middle
> of writing to the file.)
Be sure that $/ ($INPUT_RECORD_SEPARATOR if you are using English) is
set to "\n". This is the default.
> Of course, the write buffer is probably larger
> than my line length.
>
> Anyway, does checking chomp for a zero return seem safe enough?
>
> Oh, I almost forgot to add some perl code to this post:
>
> last unless chomp;
Yup that should work fine.
>
> BTW -- where's a good place to ask general programming questions? For
> example, general questions about building a perl DBM application
> that uses Berkeley DB? I'm not having problems with the perl or using
> Berkeley DB, but general questions about transaction control, maintaining
> data-base integrity, and so on.
Misc perl programming questions should be posted here. If you have a
specific programming question, check the comp.lag.perl.* newgroups
to see if there is one that fits what you are asking.
>
> --
> Bill Moseley mailto:moseley@best.com
>
>
-Gabriele
Gabriele R. Fariello | Clotho Internet Consulting
Senior Partner | Chief Application Developer
gabriele@clotho.com | 33 University Square No. 251
608 516-8822 or 608 294-7900 | Madison, WI 53715
------------------------------
Date: Sat, 10 Apr 1999 19:44:26 -0400
From: Chuck <CharlieL3@netscape.net>
To: Dave Roth <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
Subject: Re: No clues to Win32::NetResource problem?
Message-Id: <370FE25A.25B9E767@netscape.net>
Dave Roth wrote:
> Ahhh. For some reason Win32::NetResource::NetShareGetInfo() requires
> that the second parameter be a scalar, not a hash reference. If the
> function is successful then the scalar will be set as a hash reference.
> Try this:
> Win32::NetResource::NetShareGetInfo( $myshare, $share_info, $server );
> print "The Share path is: $share_info->{remark}.
It will also give a runtime exception if $myshare points to a share point that
doesn't exist. I'm looking for a way to test the existence of a share before I
try to go there and pull up its information. I was hoping a 0 return upon
failure of this function would work, but it chokes completely unless the share
already exists.
Is there another way to do this? Win32::NetResource::NetShareCheck would be
perfect for this if it worked, and Dave says not to use it in his book. ;-)
--Chuck
------------------------------
Date: Sat, 10 Apr 1999 20:13:29 -0400
From: bob <bobtall@eweb.net>
Subject: On installing ActivePerl - Build 514 ... does not complete.
Message-Id: <370FE929.42E55F3C@eweb.net>
On installing ActivePerl - Build 514 ... does not complete.
(ny system is NT, Service pak 3)
at 80% completion
i get a "warning" error
... "Error using perlez.dll"
and
i get a "severe" error
... 'Could not initialize PerlEz module"
then installation stops ... when inspecting the setup(trying to use
modules), the
modules are not all installed.
have done this several times, starting over from scratch ... still does
not work
what am i doing wrong.
------------------------------
Date: Sat, 10 Apr 1999 20:27:51 -0400
From: "Jason Simms" <ffchopin@worldnet.att.net>
Subject: Re: On installing ActivePerl - Build 514 ... does not complete.
Message-Id: <7eoqag$7dq$1@bgtnsc01.worldnet.att.net>
> On installing ActivePerl - Build 514 ... does not complete.
> (ny system is NT, Service pak 3)
>
> at 80% completion
> i get a "warning" error
> ... "Error using perlez.dll"
>
> and
> i get a "severe" error
> ... 'Could not initialize PerlEz module"
>
> then installation stops ... when inspecting the setup(trying to use
> modules), the
> modules are not all installed.
>
> have done this several times, starting over from scratch ... still does
> not work
> what am i doing wrong.
Switch to Unix, note that Perl magically works with the first try, throw
your NT box out the window, and have a nice day... Seriously, though, we
would be hard pressed to guess what is wrong from the spartan information at
hand. I have built ActiveState Perl successfully on NT several times, as
well as 98. It is probably something in either your hardware configuration
(for some REALLY strange reason...) or your OS build. Who knows what weird
software or registry settings may be causing this to fail...
Jason Simms
------------------------------
Date: Sat, 10 Apr 1999 15:23:08 -0400
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: passing variables from PERL to JavaScript
Message-Id: <370FA51B.32970531@sprintmail.com>
How do you pass a variable from Perl to JavaScript?
Jeff
------------------------------
Date: Sat, 10 Apr 1999 20:04:44 +0100
From: Greg Griffiths <greg2@surfaid.org>
To: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: PPM has created a new dir.
Message-Id: <370FA0CC.443E1729@surfaid.org>
The contents of the \site directory looks like that of my \lib
directory, should I just leave them as two dir's or copy the \site into
my \lib ?
Jonathan Stowe wrote:
>
> In comp.lang.perl.misc Greg Griffiths <greg2@surfaid.org> wrote:
> > I've just started using PPM to update my packages and have noted that it
> > has created 3 new dir in my PERL directory :
> >
> > \html
> > \htmlhelp
> > \site
> >
> > what can I/ Should I do with them ?
>
> Er nothing.
>
> They're supposed to be there.
>
> /J\
> --
> Jonathan Stowe <jns@gellyfish.com>
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
> Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 10 Apr 1999 12:19:32 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: pragma - relevant?
Message-Id: <kmtne7.k81.ln@magna.metronet.com>
JTJ (elssa09@callisto.si.usherb.ca) wrote:
: We all use "Content-Type: text/html" from time to time, don't we?
No.
People who are not doing WWW stuff with Perl (over half)
*never* use HTTP headers.
That should be a hint that you've landed in the wrong
newgroup.
The folks who have all used "Content-Type: text/html from
time to time" hangout somewhere else, in a newsgroup connected
in some way to the WWW (clpmisc in not such a newsgroup).
You are much more likely to get an answer to things specific
to the WWW environment in a newsgroup specific to the WWW,
such as:
comp.infosystems.www.authoring.cgi
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 Apr 1999 12:09:26 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: strcmpi() and toupper() in Perl
Message-Id: <m3tne7.k81.ln@magna.metronet.com>
Glenn T. Jayaputera (gtj@tesla.net.au) wrote:
: As a really really really newbie in Perl, I am having a difficulty
: in finding the equivalent functions of strcmp() and toupper() in Perl.
: Any pointers..?
strcmp ==> cmp ("Equality Operators" section in perlop.pod)
toupper ==> uc/ucfirst (perlfunc.pod)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 11 Apr 1999 00:33:57 +0000
From: Brad <mtb@velorevolution.tzo.org>
Subject: Stripping the leading character
Message-Id: <370FEDF5.6F8CBA24@velorevolution.tzo.org>
Hi
I am relatively new to Perl and hopefully have a simple problem.
I have data that looks something like this : $123.45
I would like to remove the dollar sign and just have the number
(123.45).
It appears I need to use a regular expression operation to remove the
dollar sign.
$data="$123.45"
$data=~s/??????????????
Can anyone help me remove that dollar sign or is it more difficult than
this?
Thanks alot
------------------------------
Date: Sun, 11 Apr 1999 00:12:33 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Stripping the leading character
Message-Id: <RNRP2.770$87.83405@typhoon.austin.rr.com>
In article <370FEDF5.6F8CBA24@velorevolution.tzo.org>,
Brad <mtb@velorevolution.tzo.org> wrote:
>I am relatively new to Perl and hopefully have a simple problem.
>I have data that looks something like this : $123.45
>I would like to remove the dollar sign and just have the number
>(123.45).
>It appears I need to use a regular expression operation to remove the
>dollar sign.
>$data="$123.45"
>$data=~s/??????????????
>Can anyone help me remove that dollar sign or is it more difficult than
>this?
You don't have to use a regular expression, if you always want to remove
the first character of a string then you could say
$data = '$123.45'; # does "$123.45" do what you expect?
substr($data, 0, 1) = ''; # replace offset 0 for 1 character with ''
As usual with perl there's more than one way to do it - you might consider
running something like
#!/usr/local/bin/perl
use Benchmark;
timethese(1_000_000, {
'empty' => sub { my $data = '$123.45'; },
'substr' => sub { my $data = '$123.45'; substr($data, 0, 1) = ''; },
'regex' => sub { my $data = '$123.45'; $data =~ s/^\$//; },
'tr' => sub { my $data = '$123.45'; $data =~ tr/0-9.//cd; },
});
to see which goes fastest. Reading the supplied documentation might help
uou decide whether any of them are unsuitable for the data you're
processing as they all go about reducing $123.45 to 123.45 in different
ways.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
| 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Sat, 10 Apr 1999 20:17:11 -0400
From: evil Japh <jeffp@crusoe.net>
Subject: Re: Stripping the leading character
Message-Id: <Pine.GSO.3.96.990410201420.20801J-100000@crusoe.crusoe.net>
> $data="$123.45"
> $data=~s/??????????????
This appears to be a common problem to inexperienced Perl programmers.
When in double quotish context, the $ character, unless escaped by a
backslash \$, is introduced a scalar value.
Examples:
print "$name is $age years old";
$phrase = "Watch out for $something";
When you say: $data = "$123.45", Perl is expecting you to have a variable,
$123, proceeded by a ".45". The variable $123 is not easily set (is not
ordinarily writable). Therefore, try single quotish context, like so:
$price = '$123.45';
Or backslash the $:
$price = "\$123.45";
--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp
Crusoe Communications, Inc.
732-728-9800
www.crusoe.net
------------------------------
Date: Sat, 10 Apr 1999 20:19:57 -0400
From: "Jason Simms" <ffchopin@worldnet.att.net>
Subject: Re: Stripping the leading character
Message-Id: <7eoprm$3sf$1@bgtnsc01.worldnet.att.net>
> I am relatively new to Perl and hopefully have a simple problem.
> I have data that looks something like this : $123.45
> I would like to remove the dollar sign and just have the number
> (123.45).
> It appears I need to use a regular expression operation to remove the
> dollar sign.
> $data="$123.45"
> $data=~s/??????????????
> Can anyone help me remove that dollar sign or is it more difficult than
> this?
As Mike said, there often is more then one way to do it. Here is the
specific RegEx for the $ and a more generic one for any first character:
#!usr/bin/perl -w
$string = '$123.45';
$string2 = '$123.45';
# In both of the following RegEx's, the ^ indicates that you want the
# match to occur at the beginning of the string. The first matches
# the leading $ explicitly and the second matches any first
# character (indicated by the .).
$string =~ s/^\$//;
$string2 =~ s/^.//;
print "$string\n";
print "$string2";
# END
Jason Simms
------------------------------
Date: 10 Apr 1999 20:58:07 +0200
From: Klaus Schilling <Klaus.Schilling@home.ivm.de>
Subject: Re: Text Search Program
Message-Id: <876774gv5s.fsf@home.ivm.de>
"Michael O'Connor" <mfo@home.com> writes:
> Hello,
>
> I'm working on a project that is to have a user input a text string and then
> search for that text string in a bunch of text files. Then I am to display
> those text files that have that text string in it. I would like to use
> windows or an internet browser to ask for the input and to display the
> output. I am using Windows 98 on a stand alone machine. I have been
> investigating Perl for doing the text searching. I have had difficulty
> using Perl to drive my internet browser. Perl is designed for a Unix
> environment not for a windows environment. Perl wants to only open up a
> text window. Does anyone know drivers for windows or internet browsers
> using Perl? Should I be using a different programming language? Any
> suggestions?
There's Perl/Tk , so it's possible to write GUI programs in perl.
Klaus Schilling
------------------------------
Date: 10 Apr 1999 19:25:41 GMT
From: portlord@aol.com (Port Lord)
Subject: Writers wanted for zine articles.
Message-Id: <19990410152541.25780.00001127@ng42.aol.com>
Columbia 2032 (C2032) is looking for individuals who would like to write
articles for our zine. Topics include: Phone systems (cellular/normal),
Cryptography, IRC, TCP/IP, Programmiung,Information Warfare, Computer Security
and just about anything pertaining to computers /or phones. We have been around
approximately 10 months. We just released our biggest (93.4k) and best edition
yet, which can be downloaded under 'library at www.homestead.com/c2032 . In our
effort to expand our distribution, quality, and quantity of the zine, we are
looking for more writers and or willing people to distribute the zine. Our
subscribers and writers consist of people from within the hack/phreak community
and professional individuals alike. Please send all responses to
C2032@theglobe.com . We are a freelance zine so if it is money you want please
dont respond.
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 5350
**************************************