[7934] in Perl-Users-Digest
Perl-Users Digest, Issue: 1559 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 31 20:07:29 1997
Date: Wed, 31 Dec 97 17:00:21 -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, 31 Dec 1997 Volume: 8 Number: 1559
Today's topics:
Re: 'flock'ing <reibert@mystech.com>
Re: 'flock'ing (Tad McClellan)
Re: [Q ] What is wrong with @INC ???? Help please! <koos_pol@bigfoot.com>
Re: better foreach? (Terry Michael Fletcher - PCD ~)
Building libwin32 with VC++5 , fatal errors danny_aldham@bctel.com
Re: CGI y comandos SSI <witsend@ix.netcom.com>
Excel->perl functions? <jeffrey@halcyon.com>
Going multiple directions from a list of checkboxes (Keith Sullivan)
Re: How do I pass objects from Perl to Javascript? (William R. Ward)
Re: IIS4 Please Help! <scott_clark@merck.com>
Re: misterious context <rootbeer@teleport.com>
Re: Mysterious FileHandle + fork() behavior; possible P <achen@nssdc.gsfc.nasa.gov>
newbie: what am i doing wrong? (jay)
Re: newbie: what am i doing wrong? <barce@slip.net>
Okay, I should know this, but its about reading info fr (William Byrd)
Re: PERLIPC - FIFO: parent, child, stalled! <rootbeer@teleport.com>
Re: Script calls embedded in web pages <scott_clark@merck.com>
Simple(!) regular expression problem (Laurel Shimer)
Re: Simple(!) regular expression problem <ebohlman@netcom.com>
Re: SQL and PERL (Laurel Shimer)
Re: Stripping non-alphanum's from within string? (Jeff Stampes)
system command <info@bigfoot.ch>
Re: system command <barce@slip.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 31 Dec 1997 12:34:30 -0700
From: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: 'flock'ing
Message-Id: <34AA9E46.54421165@mystech.com>
Ernie Johnson wrote:
> Actually, I forgot to indicate that I have tried the process with the seek
> in place.. still no luck.
>
> In response to a direct email I received on the problem, here is part of it:
>
> >> *) your file is accessed through NFS (flock() don't work well with NFS)
Hmmm, I wasn't aware of this - maybe it's the source of your problem.
> NFS? Isn't that a file system of the drive?
Network File System - remote mounted from another machine. Maybe the network
traffic causes a problem with the flock(). Better yet, maybe flock() can't
handle NFS because the file system may have different characteristics on the
remote machine. [I don't know - I'm reaching here! :-)]
> Anyway, anyone have a good, and reliable solution for non-flock on unix
> sytems? Right now, I'm back to a timed loop to see if a lock file clears
> and if so, proceed with its work, but if it doesn't clear after 15 seconds
> it wipes out the lock in case of a prior crash of sorts and continues.
You could try a semaphore. This will give you the same functionality and may
work over NFS.
Good Luck!
-----------------------------
Mark S. Reibert, Ph.D.
Mystech Associates, Inc.
3233 East Brookwood Court
Phoenix, Arizona 85044
Tel: (602) 732-3752
Fax: (602) 706-5120
E-mail: reibert@mystech.com
-----------------------------
------------------------------
Date: Wed, 31 Dec 1997 15:11:58 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: 'flock'ing
Message-Id: <uece86.af1.ln@localhost>
Ernie Johnson (tcm@tcmd.com) wrote:
: I've read some past posts on file locking and the general suggestion seems
: to be utilize flock if its available... (our program is running on a linux
: system - yes its a web app - and the server is apache)
: after following some flock implemenations I set it into use, but within a
: few hours, had erased data...
: my code follows this pattern:
: open file
: read data
: close file
: do other stuff here
If process1 loses its time slice here, then process2 might run the
above code.
Then if process 1 does:
: open the file
: flock handle,2
: write new data
: close file
followed by process2 doing that, then process1's changes disappeared
(process 2 stomped on them)
: I understand its not "good" to close the flock, just let close handle the
: flushing, unlock and close.
: My question is, using this, why would I still have lost data? The program
: is simply reading a file, adding a line to it and resaving it.
You need to do the read, modify, write part while keeping the lock
for the entire evolution.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 31 Dec 1997 09:59:20 +0100
From: Koos Pol <koos_pol@bigfoot.com>
Subject: Re: [Q ] What is wrong with @INC ???? Help please!
Message-Id: <34AA0968.5DF8@bigfoot.com>
John Porter wrote:
>
> Augusto Cardoso wrote:
> >
> > when I try to run Perl programs I get a message stating that PM files
> > can not be found.
> > @INC is displayed and it refers to the right LIB...
> > Here is the error message:
> >
>
> If you're sure that Text.pm is in \perl\lib, then that's the problem.
> Move it down into the Pod directory; that seems to be
> where it's expected to be.
>
> John Porter
> jporter@logicon.com
Correct. It should be in ..\LIB\POD\Text.pm
(At least that's where is sits on my OS/2 install :-))
--
Koos Pol
----------------------------------------------------------------------
S.C. Pol tel: +31 20 3116122
PC Systems Administrator email: Koos_Pol@bigfoot.com
Compuware Europe PGP public key available upon request
A little inaccuracy sometimes saves tons of explanation.
-- H. H. Munroe
------------------------------
Date: 31 Dec 1997 22:29:43 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: better foreach?
Message-Id: <68eh0n$2gg$1@news.fm.intel.com>
WOLtetch (woltetch@aol.com) so eloquently and verbosely pontificated:
> Take something like this:
>
> foreach $drop (@water) {
> foreach $bat (@hell) {
> #do something with $drop and $bat
> }
> }
>
> Is there a way to do this without nesting the foreach loops?
> (I take it something like
> foreach ($drop, $bat) (@water, @hell) {
> #do something with $drop and $bat
> }
>
> won't work at all).
if you are trying to process each $bat out of @hell with each $drop of
@water, then you were already doing the right thing.
if you are suggesting that the first $drop of @water gets processed only
with the first $bat out of @hell, then you just want to increment a common
index (you can even still use 'foreach'):
foreach ($i=0; $i < @water; $i++) {
#do something with $drop[$i] and $bat[$i]
}
hope that helps.
--
#!/usr/local/bin/perl -w
system("pod2html $0")&&die"Just another Perl hacker,\n";system("
lynx $0.html")&&die"Just another Perl hacker,\n";unlink"$0.html";
=head1 Just another POD hacker, tfletche@pcocd2.intel.com
------------------------------
Date: Wed, 31 Dec 1997 15:36:47 -0600
From: danny_aldham@bctel.com
Subject: Building libwin32 with VC++5 , fatal errors
Message-Id: <883603641.1647837190@dejanews.com>
I have built the core perl5.004_04 dist with MS VC++5
fine, but am getting fatal error: don't know how to
make 'blib\lib\.exists' when I run nmake in the libwin32-0.08
directory. I did run ./perl Makefile.pl , and got no errors.
I tried to make individual modules, like ODBC or NetAdmin
and am getting the same error. Any help appreciated.
Danny Aldham
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Wed, 31 Dec 1997 15:28:07 -0800
From: Denise Connell <witsend@ix.netcom.com>
Subject: Re: CGI y comandos SSI
Message-Id: <34AAD507.5BA2@ix.netcom.com>
Clinton Bodine wrote:
The question was answered, en espanol, in comp.lang.perl.modules
>
> I personally welcome non-English questions. Unfortunately, I don't have a
> grasp of any other language except for a little German. Could someone
> translate this question for us?
>
------------------------------
Date: 31 Dec 1997 23:02:22 GMT
From: Thanh Luu <jeffrey@halcyon.com>
Subject: Excel->perl functions?
Message-Id: <68eitu$lcn$1@brokaw.wa.com>
Is there a math library with the functions commonly used in spread
sheets?
example in excel:
=avg(A1:A2) returns average of cells A1 and A1
Is there a perl subroutine that averages space seperated numbers
on the command line?
$average = &avg(<STDIN>);
I see some trig functions in the standard install but am unable
to find any decent math perl modules on CPAN.
I know they must be out there.
Please direct me there if you can.
thanks in advance.
--tl
------------------------------
Date: 31 Dec 1997 21:37:54 GMT
From: sull@au13.ecn.purdue.edu (Keith Sullivan)
Subject: Going multiple directions from a list of checkboxes
Message-Id: <68edvi$44p@mozo.cc.purdue.edu>
I am creating a web based evaluation form. As part of this project, I present
a list of check boxes to the user. They can choose any number of them.
Checking a box will bring up a series of questions about that topic. I have
it working as long as the user only checks one box. However, I want it to
work if the user checks more than one box. So, I need to go one way if a box
is checked, then return and check if any other boxes were checked, and then
go in a different direction. Where I am lost is how to go in the second
direction. I need a way to hold the original information concerning the
checkboxes, and also, be able to analyze it. I could write this information
to a temporary file, but that seems awfully messy, since the user could pick
any combination of 12 checkboxes. Handling all possibilities would get ugly.
Any help is appreciated.
In case this is confusing, here is a small example of what I mean. Say there
is a list of three items (with checkboxes):
Dairy Cows
Beef Cows
Horses
The user can check any number of the three. Say they check all three. The
idea is this: go off and ask a series of questions regarding Dairy Cows,
return to the list to see if any other boxes were checked. Go off and ask
questions about Beef Cows, return to the list to see if any other boxes were
checked. Then go off and ask questions about Horses. Return, and present
analysis of the users answers from all three areas.
Thanks,
Keith Sullivan
sull@ecn.purdue.edu
------------------------------
Date: 31 Dec 1997 13:37:31 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: How do I pass objects from Perl to Javascript?
Message-Id: <waak9cl42jo.fsf@am.UCSC.EDU>
spectd@horus.sara.nl (Neil Burnett) writes:
> Seasons Greetings -
>
> I am creating nascent documents from a textbase created using CGI.pm
> and wish to transfer the data to Javascript objects in an efficient
> way. Does anyone have any suggestions?
>
> I am doing it in a very long-winded fashion at the moment by creating
> text strings in Perl which replace placeholders in my html document.
> This is fine for a limited application, but I would like to do it in a
> more general way by passing a CGI.pm object to the Javascript.
Use CGI.pm's hidden() method to output hidden fields containing the
fields you wish to make accessible to JavaScript. JavaScript can
access that data the same as any data entered by the user. To pass
data as a JavaScript object, create a JavaScript function dynamically:
For example, say you have an associative array %foo in Perl that you
want to be able to access in JavaScript. Write this in your Perl CGI
script:
print JAVASCRIPT "function get_foo()\n{\n";
while (($key, $value) = each %foo)
{
print JAVASCRIPT " this[$key] = '$value';\n";
}
print JAVASCRIPT "}\n";
Then in your JavaScript code you can say "var foo = new get_foo()" and
then foo contains all the values of Perl's %foo.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Wed, 31 Dec 1997 16:11:05 -0800
From: scott clark <scott_clark@merck.com>
Subject: Re: IIS4 Please Help!
Message-Id: <34AADF19.3C48@merck.com>
Mark Polakow wrote:
>
> Hello all. I am in serious need of getting Perl up and running on IIS4
> and having a heck of a problem setting up Perl scripts though I had no
> problem running them under Netscape server on NT. I have done all the
> basics: Run the Perl 5.003 Install.bat which makes registry changes
> and associates .pl with the Perl interpreter. I have heard that IIS
> requires you to use 2 slashes instead of 1 for pathing....
> If you could offer any help I would appreciate it!
Try the following URL, it worked great for me on IIS3.0...
http://support.microsoft.com/support/kb/articles/Q150/6/29.asp
This of course assumes that you have Perl running from the command
line...
If not, check and *make sure* your path points to ...\Perl5\bin\ (or
wherever you installed the Perl.exe
The contents of this message express only the sender's opinion.
This message does not necessarily reflect the policy or views of
my employer, Merck & Co., Inc. All responsibility for the statements
made in this Usenet posting resides solely and completely with the
sender.
------------------------------
Date: Wed, 31 Dec 1997 16:38:12 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: misterious context
Message-Id: <Pine.GSO.3.96.971231163133.27854L-100000@user2.teleport.com>
On Wed, 31 Dec 1997, Eric Bohlman wrote:
> If you try to assign a list to a scalar, only the first element in the
> list gets assigned.
I don't think that's the right rule! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 31 Dec 1997 10:56:20 -0500
From: Allen Chen <achen@nssdc.gsfc.nasa.gov>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Mysterious FileHandle + fork() behavior; possible Perl bug?
Message-Id: <Pine.OSF.3.95.971231102819.1572A-100000@nssdc.gsfc.nasa.gov>
> As I understand that, the child process could mess up the parent's copies
> of the data. But my understanding of such things is less than total... :-)
Well, I think the point of them sharing the actual file pointer is that
the children and parent could read/write without clobbering one another.
For instance, if a parent and a child both wrote to a file, the fact that
they both use the same file offset prevents them from writing over each
other. But still, in my program, only the parent uses the filehandle in
question!
> Not likely. :-) But I'm appending a simple test case which shows the
> behavior (on my system). Let's see if anyone reading along in the
> newsgroup can tell us whether the problem is in Perl or in the code below!
What exactly happens when you run your code? It doesn't always work when
I run it. It's probably because the parent finishes up before the child
has a chance to seek back to the beginning. A sleep() in the parent would
probably do the trick.
Maybe it would help if I posted my code. Here's my code, stripped down as
much as I could while still exhibiting the problem. Basically, the parent
opens up the file specified on the command line. It goes through a loop
reading each line of the file into a variable and then has a child process
print out that variable. Even when I run this on a 50-line /etc/passwd
file, it gets stuck in some kind of loop (not sure if it's infinite) and
prints the file over and over again. What am I doing wrong? This program
is driving me crazy! :)
Thanks,
-Allen
Allen Chen / Systems Programmer / ?????? STX Corporation ////
SSDOO Software, Systems / International Solar-Terrestrial Physics /////
e-mail: achen@nssdc.gsfc.nasa.gov / voice: (301) 286-7376 //////
----- cut here --------------------------------------------------------
#!/usr/local/bin/perl -w
$|=1;
my $i; # generic counter
open (LIST, "<$ARGV[0]"); # open the specified file
# when the child dies, start another while we haven't reached end of $LIST
while (!(eof LIST)) {
&startKid;
wait();
}
exit(0);
#######################################################################
# startKid
# This forks off a child process which prints the next line.
sub startKid {
my $hfile;
my $pid;
$hfile=<LIST>; # note that the PARENT reads the file
{
if (not defined($pid = fork)) {
# Assume harmless fork failure
sleep 1;
redo;
}
}
if ($pid==0) { ## all the child does is print the variable.
print "$hfile"; # The strangeness still occurs if the print
exit(0); # is commented out.
} else { ## parent just returns
return $pid;
}
} #sub startKid
------------------------------
Date: Wed, 31 Dec 1997 22:36:13 GMT
From: mocat@NOSPAM.best.com (jay)
Subject: newbie: what am i doing wrong?
Message-Id: <34aac7f4.2255509@nntp.best.com>
I'm bored at work, so I'm working on a random password geneator.
I have lots of ideas for it, but I can't implement those until I get
this problem worked out. I see no problem in my code, but then again,
I don't have a lot of experience with PERL. If you can tell me what I
am doing wrong, it'd be much appreciated. Thx.
What it does is continuously loops, and it doesnt give me a variable
for $nextchar... *shrug*
#!/usr/bin/perl
srand; $stat = 0;
@caplet = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
@lowlet = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
@numbers = qw(1 2 3 4 5 6 7 8 9 0);
@arrays = qw(caplet lowlet numbers);
while ($stat < 8) {
$nextarr = $arrays[rand(@arrays)];
$nextchar = $nextarr[rand(@$nextarr)];
if ($stat = 0) {
print "new password: $nextchar";
$stat++;
} else {
print $nextchar;
$stat++;
}
}
jay... feeling stupid
------------------------------
Date: Wed, 31 Dec 1997 16:04:51 -0800
From: "Jim Barcelona" <barce@slip.net>
Subject: Re: newbie: what am i doing wrong?
Message-Id: <68en27$q39$1@owl.slip.net>
jay wrote in message <34aac7f4.2255509@nntp.best.com>...
>I'm bored at work, so I'm working on a random password geneator.
>I have lots of ideas for it, but I can't implement those until I get
>this problem worked out. I see no problem in my code, but then again,
>I don't have a lot of experience with PERL. If you can tell me what I
>am doing wrong, it'd be much appreciated. Thx.
Okay, I'll give it a try, and comment your code below.
>
>What it does is continuously loops, and it doesnt give me a variable
>for $nextchar... *shrug*
>
>#!/usr/bin/perl
>srand; $stat = 0;
>@caplet = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
>@lowlet = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
>@numbers = qw(1 2 3 4 5 6 7 8 9 0);
>@arrays = qw(caplet lowlet numbers);
>while ($stat < 8) {
> $nextarr = $arrays[rand(@arrays)];
> $nextchar = $nextarr[rand(@$nextarr)];
The variable assignment above will give you undef. I can see that you want
the object between the parentheses following the rand function to refer to
the array selected in the previous line. Perhaps you can try using an
if-elsif structure. For example:
if ($nextarr eq "caplet") {
# select random caplet
} elsif ($nextarr eq "lowlet") {
# select random lowlet
} else {
# select random numbers
}
> if ($stat = 0) {
Use "if($stat == 0) {".
A common mistake that I'll often make is to take the assignment operator (in
this case the "=") to be a logical operator like ==. To avoid this mistake,
when composing conditional statements such as $stat == 0, I say to myself
'$stat really equals 0'. The addition of really in my English translation
makes me use the double equals sign.
> print "new password: $nextchar";
> $stat++;
> } else {
> print $nextchar;
> $stat++;
> }
>}
>
>jay... feeling stupid
>
Everybody's stupid at something. ;-) I'm stupid at getting dates.
Cheers,
Jim
------------------------------
Date: Thu, 01 Jan 1998 01:44:11 GMT
From: wcb4@erols.com (William Byrd)
Subject: Okay, I should know this, but its about reading info from a file
Message-Id: <68emg6$rge$1@winter.news.erols.com>
In every perl script I have written to date, I have had to read
through an entire file for information and process it. Now I need to
open a file and read only the second line of the file to see if it has
the information I need, and if not, close it.
I don't know the perl syntax, but I want to
open (file,"<$filename");
read $line; # this gets discarded
read $line; # this is the line I readlly want
the I check to see if my info is on that line and if not close(file)
I have a directory containign hundreds of files and I can have perl do
a bare directory and pipe the contents into a file called dir.dir and
open dir.dir and use a while loop until I have examined all the files
in the directory, but how to I make perl read only the 2 lines?
Any help would be appreciated. Please reply via e-mail as well, as I
do not know when I will get back to this newsgroup.
wcb4@erols.com
------------------------------
Date: Wed, 31 Dec 1997 16:47:36 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Jihad Battikha <jbattikha@highsynth.com>
Subject: Re: PERLIPC - FIFO: parent, child, stalled!
Message-Id: <Pine.GSO.3.96.971231164130.27854N-100000@user2.teleport.com>
On Tue, 30 Dec 1997, Jihad Battikha wrote:
> Can someone look this small script over and tell me what I'm doing
> wrong?
> #!/usr/local/bin/perl
I don't mean to sound rude here, but how can you ask us to look this over
when you haven't even used -w and 'use strict' to get Perl to help you?
Perl wants to help you to make good code; please work with it and we'll
all be happier.
> pipe(FROM_CHILD, TO_PARENT);
> $pid = fork;
You should check whether the fork call succeeded, and possibly whether the
pipe call did as well.
> print TO_PARENT $FIFO;
Of course, this info won't actually be sent until the buffer is flushed.
> } elsif (defined $pid) {
The if clause tested whether $pid was zero, so the only way you can get
here is if it's non-zero (and thereby defined).
> $FIFO = <FROM_CHILD>;
Yes, this will block until the buffer is flushed. That's probably where
your code is hanging.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Wed, 31 Dec 1997 16:20:28 -0800
From: scott clark <scott_clark@merck.com>
Subject: Re: Script calls embedded in web pages
Message-Id: <34AAE14C.461@merck.com>
SoCheer wrote:
>
> Hi there,
>
> Instead of physically clicking on a link to execute the perl script, could
> we call a perl script from a html tag ?
>
> I know <IMG SRC="/cgi-bin/scriptname.pl"> does it, but a broken image is
> shown. How could I get rid of it ?
>
> Thanks !
> So Cheer
> socheer.kwek@ac.com
>
> ><a href="/cgi-bin/scriptname.pl"> goforit link</a>
> >
> >hope this helps
Or how about Server Side Includes (SSI) that will execute
/cgi-bin/scriptname.pl with the following HTML tag. Note: Server Side
Includes must be configured on your webserver...
<!-- #exec cgi"/cgi-bin/scriptname.pl" -->
-scottyc
The contents of this message express only the sender's opinion.
This message does not necessarily reflect the policy or views of
my employer, Merck & Co., Inc. All responsibility for the statements
made in this Usenet posting resides solely and completely with the
sender.
------------------------------
Date: 31 Dec 1997 23:29:32 GMT
From: autopen@autopen.com (Laurel Shimer)
Subject: Simple(!) regular expression problem
Message-Id: <autopen-3112971530050001@dynamic2.pm02.mv.best.com>
I am very embarassed that I just don't get how to do regular expressions yet...
Have been staring at the Camel, the Llama book and the Perl Reference
Guidetrying to figure out how to make the following two variables match
$reqinput ="360-WG-002 ";
$reqmatch =" 360-WG-002";
I have tried both
if ($reqinput=~ /\b$reqmatch\b/) {print "matched\n";}
else {print "no match\n";}
And
if (/\b$reqinput\b/ =~ /\b$reqmatch\b/) {print "matched\n";}
else {print "no match\n";}
Obviously I really have the wrong idea here.
Pointers are much appreciated.
Thank you
Laurel
--
The Reader's Corner: Mystery, Romance, Fantasy
http://www.autopen.com/index.shtml
Subscribe to our free StoryBytes publication
Did you miss? The Pigeon, A St.John Bathshirker Mystery
http://www.autopen.com/pigeon.shtml
------------------------------
Date: Thu, 1 Jan 1998 00:01:05 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Simple(!) regular expression problem
Message-Id: <ebohlmanEM2w1t.BAG@netcom.com>
Laurel Shimer <autopen@autopen.com> wrote:
: $reqinput ="360-WG-002 ";
: $reqmatch =" 360-WG-002";
^ ^
Dashes have a special meaning inside regular expressions. That's what's
causing your problem.
: I have tried both
: if ($reqinput=~ /\b$reqmatch\b/) {print "matched\n";}
: else {print "no match\n";}
You've got the right idea here. You just need to surround $reqmatch with
\Q and \E; those tell perl that all characters in between them (including
characters interpolated from a variable) should be treated literally.
: And
: if (/\b$reqinput\b/ =~ /\b$reqmatch\b/) {print "matched\n";}
: else {print "no match\n";}
This one is syntactic garbage, and perl should complain about it. You're
trying to match the result of a match against the thing you matched. Not
very clear, eh.
: Obviously I really have the wrong idea here.
: Pointers are much appreciated.
Your Perl distribution came with an enormous amount of free, high-quality
documentation. In particular, it came with a file called "perlre" (which
may be a Unix man page or an HTML document, depending on your platform)
which tells you everything you need to know, and more, about regular
expressions. Your assignment, should you choose to accept it, is to read
it at least twice; in between readings, you should play around with the
stuff you picked up on the first reading (Perl is one of those languages
where you have to be able to play with it before you can work with it).
------------------------------
Date: 31 Dec 1997 23:31:52 GMT
From: autopen@autopen.com (Laurel Shimer)
Subject: Re: SQL and PERL
Message-Id: <autopen-3112971532250001@dynamic2.pm02.mv.best.com>
I'm not sure how diffent MSQL is from MySQL - but it seems pretty popular
out there. Laurel
--
The Reader's Corner: Mystery, Romance, Fantasy
http://www.autopen.com/index.shtml
Subscribe to our free StoryBytes publication
Did you miss? The Pigeon, A St.John Bathshirker Mystery
http://www.autopen.com/pigeon.shtml
------------------------------
Date: 31 Dec 1997 20:35:24 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Stripping non-alphanum's from within string?
Message-Id: <68eaad$q9d$1@neocad.com>
hagani@worldnet.att.net wrote:
: Let's say I have: $string = "P#E!$R- L"
: I'd like to remove all non-alphanumerics, the result being:
: $string = "PERL"
: I've tried $sting =~ s/\W//g; but this doesn't seem to work
: properly (it strips some of the letters too!)
Actually it does work...not the way you're defining your string
though:
DB<10> $_ = "P#E!$R- L"
DB<11> print $_
P#E!- L
Hmmm...where's your 'R'? You didn't escape the '$', so it tried to
use the value of $R, which doens't exist.
DB<12> $_ = 'P#E!$R- L'
DB<13> s/\W//g
DB<14> print $_
PERL
use single-quotes so the $ doesn't interpolate and you'll be fine.
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Wed, 31 Dec 1997 23:40:39 +0100
From: Bigfoot Schweiz <info@bigfoot.ch>
Subject: system command
Message-Id: <34AAC9E7.3D5983DE@bigfoot.ch>
Hello everybody,
I actually have serious problems with Perl at the moment. Does anybody
have an idea how I can fetch the output of a system command?
Or does anybody know how I can look( certainly with Perl) how big a file
is?
Thanks
Thomas
------------------------------
Date: Wed, 31 Dec 1997 15:36:48 -0800
From: "Jim Barcelona" <barce@slip.net>
Subject: Re: system command
Message-Id: <68eldk$mkj$1@owl.slip.net>
Bigfoot Schweiz wrote in message <34AAC9E7.3D5983DE@bigfoot.ch>...
[snip]
>Or does anybody know how I can look( certainly with Perl) how big a file
>is?
>
>Thanks
>
>Thomas
Try using the stat function described on page 224 of the Camel book.
Assuming you're on a Unix platform, you might try, for example:
#!/usr/local/bin/perl -w
$filename = "file"; # place the filename of your choice and the proper
directory
# in quotes
$bytes = (stat($filename)) [7]; # the number 7 corresponds to the size
field in bytes.
print "$filename is $bytes bytes.\n";
There's also other ways, in particular the use of the File::stat module in
release 5.004 of Perl, which I'm not yet familiar with.
Take care,
Jim
------------------------------
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 1559
**************************************