[24082] in Perl-Users-Digest
Perl-Users Digest, Issue: 6276 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 19 00:05:35 2004
Date: Thu, 18 Mar 2004 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 18 Mar 2004 Volume: 10 Number: 6276
Today's topics:
Accessing a SQL Server Database from a Perl Script on L (v796)
Re: Accessing a SQL Server Database from a Perl Script <invalid-email@rochester.rr.com>
Can somebody please help me <jillfr@hotmail.com>
Re: Can somebody please help me <matthew.garrish@sympatico.ca>
Re: chm decompiler <tlviewer@yahoo.com>
Re: count unique values in array <tore@aursand.no>
Re: get filename using regexp and if <matthew.garrish@sympatico.ca>
Re: get filename using regexp and if <PerlGuRu2b@bobotheclown.org>
Re: Help: Deleting Entries in Flat File Database <tore@aursand.no>
Re: HOW TO PARSE A VAST FILE! <tore@aursand.no>
Re: Multiple compares -- TMTOWTDI <skuo@mtwhitney.nsc.com>
NET::FTP debug output (mike)
Re: perl2exe can't locate DBI.pm (Bunny)
Re: Printing in Perl <bsoist@otaku.freeshell.org>
Re: Printing in Perl <uri@stemsystems.com>
Re: Printing in Perl <bsoist@otaku.freeshell.org>
Re: Printing in Perl <spamtrap@dot-app.org>
Re: Regular Expressions Question <uri@stemsystems.com>
Re: Regular Expressions Question <tore@aursand.no>
Re: reverse search modifier (S Raven)
Re: reverse search modifier <uri@stemsystems.com>
Re: seek help with regular expressions syntax <invalid-email@rochester.rr.com>
Re: stripping out ASCII chars using regexp? <invalid-email@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Mar 2004 15:38:52 -0800
From: vicky7909@rediffmail.com (v796)
Subject: Accessing a SQL Server Database from a Perl Script on Linux
Message-Id: <49f90fb9.0403181538.20302aea@posting.google.com>
Hi,
My Perl script (running as a Cron on Linux) is parsing a text file and
now it must access a SQL Server database on a Windows machine. I need
the code for that. Can anybody help? Any book or website has that?
Thanks,
v796.
------------------------------
Date: Fri, 19 Mar 2004 04:04:50 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Accessing a SQL Server Database from a Perl Script on Linux
Message-Id: <405A715C.1010106@rochester.rr.com>
v796 wrote:
...
> My Perl script (running as a Cron on Linux) is parsing a text file and
> now it must access a SQL Server database on a Windows machine. I need
> the code for that. Can anybody help? Any book or website has that?
...
> v796.
Actually, your hard drive has that. You will want to:
use DBI;
Check out:
perldoc DBI
at your command prompt for documentation. You will need to know details
about the particular database package you are using and how to connect
to it remotely. You will need to get that from your database's
documentation.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Fri, 19 Mar 2004 00:32:56 GMT
From: "Jill" <jillfr@hotmail.com>
Subject: Can somebody please help me
Message-Id: <Ycr6c.20201$E8.4389999@news4.srv.hcvlny.cv.net>
How can I read the variable that is passed to a url
like
www.mydomain.com/test.html?SVAR=55
I want to access the SVAR variable and store it in the cookie, then retrieve
it later again to display if this person revisits site.
how to I modify
http://javascript.internet.com/cookies/id-tracker.html
to make it work.
(I am just not sure how to read this variable from url) , lets assume I know
the variable name and maybe do not have to parse)
' sorry I thinkg this is the wrong topic but the javascript NG doesnt seem
to have anything in it.
Please help.
Thanks in advance
------------------------------
Date: Thu, 18 Mar 2004 19:49:06 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Can somebody please help me
Message-Id: <2sr6c.10883$Eb6.359920@news20.bellglobal.com>
"Jill" <jillfr@hotmail.com> wrote in message
news:Ycr6c.20201$E8.4389999@news4.srv.hcvlny.cv.net...
> How can I read the variable that is passed to a url
> like
> www.mydomain.com/test.html?SVAR=55
>
Even if I told you, what possible good do you think it would do? Perl and
javascript aren't even remotely similar.
And did you even try googling for a solution? I'm sure you would have found
the answer in less time that it took to post your question twice. It is
common practice to ignore people who post ***faqs***, you know:
http://www.faqts.com/knowledge_base/view.phtml/aid/969/fid/129
Matt
------------------------------
Date: Fri, 19 Mar 2004 02:04:23 GMT
From: "gnu valued customer" <tlviewer@yahoo.com>
Subject: Re: chm decompiler
Message-Id: <Hys6c.43971$F9.41356@nwrddc01.gnilink.net>
"meneerjansen" <meneerjansen@europe.be> wrote in message
news:c3d1jd$m5m$1@reader13.wxs.nl...
> Greetings,
> I'm looking for a Perl script (or a platform-independent exe outputting to
> STDOUT) that converts chm (HTML Help) files to text or HTML.
> Does anyone know if such program exists?
>
> Thanks for your time,
> Janssen
>
>
(platform independent)
Check out the CHM Tool source code here:
http://www.speakeasy.org/~russotto/chm/
If you are on Win32, you can use
this code to extract a page from a chm:
# win32 chm page extractor
#########################
#!/usr/bin/perl
# use Win32::OLE;
my $chmfile = "The Perl CD Bookshelf.chm";
my $HTTP = Win32::OLE->new('MSXML2.XMLHTTP.3.0') or
die "couldn't create MsXml2 object \n";
# strings contains the toc, main, and index page names
my $src = "ms-its:$path/" . $chmfile . "::#STRINGS";
# get using the M$ InfoTech Storage protocol
my $str = ChmGet( \$HTTP, $src);
sub ChmGet
{
my ($obj,$url) = @_;
$$obj->Open( "GET", "$url" , "FALSE");
$$obj->Send();
my $lRes = 0;
$lRes = Win32::OLE->LastError();
if ($lRes ) {
return $lRes;
}
else
{
return $$obj->{responseBody};
}
}
# end script
This code was developed in a project to data_mine
my CHM ebook collection and to insert the results
into MySQL.
I have about 43,000 chapter headings that I can
search with SQL queries. Query results are formatted
as anchor tags in an HTML interface, which when
clicked will open the desired page to the desired chapter.
A single ebook collection can be browsed across
a LAN.
I've looked into doing the same with PDF, but never
got to square-one.
good luck,
msp
AIM:Yahoo:tlviewer
------------------------------
Date: Fri, 19 Mar 2004 02:07:50 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: count unique values in array
Message-Id: <pan.2004.03.19.00.55.44.557486@aursand.no>
On Thu, 18 Mar 2004 21:15:42 +0000, Don Stefani wrote:
> Using the results of a query in the form of an array, I'd like to find...
> - The number of unique values
> - The number of times that each unique value is repeated in the array
Use a hash;
my %values;
foreach ( @array ) {
$values{$_}++;
}
--
Tore Aursand <tore@aursand.no>
"Leadership is doing what is right when no one is watching." -- George
Van Valkenburg
------------------------------
Date: Thu, 18 Mar 2004 18:48:33 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: get filename using regexp and if
Message-Id: <izq6c.10848$Eb6.343813@news20.bellglobal.com>
"Rocky" <PerlGuRu2b@bobotheclown.org> wrote in message
news:pan.2004.03.18.21.41.32.413018@bobotheclown.org...
>
> $ftp->get($file) if ($goodfile < "86400" & $file =~ /.*\.txt|.*\.xml/);
>
> the problem:
> whenever I add "or print FILENAMES ..." to the last line it gets every
file in
> the remote dir.
Most likely because there are a whole slew of problems with the above code.
Going on the assumption that you typed that code in, the or is interpreted
as being part of the if statement (i.e. get the file if the expressions in
parens match, OR if the filename can be printed). One line statements are
all the rage, but sometimes you can try and do too much in them:
if (($goodfile < 86400) && ($file =~ /.*\.txt|.*\.xml/)) {
$ftp->get($file)
}
else {
print $file, "\n";
}
Matt
------------------------------
Date: Fri, 19 Mar 2004 01:45:16 GMT
From: Perl GuRu2b <PerlGuRu2b@bobotheclown.org>
Subject: Re: get filename using regexp and if
Message-Id: <pan.2004.03.19.02.19.41.311313@bobotheclown.org>
thank you. I can't believe I didn't think of that.
I know my code is not beautiful yet, but it works. Anyway, thanks again.
Rocky
On Thu, 18 Mar 2004 18:48:33 -0500, Matt Garrish wrote:
>
> "Rocky" <PerlGuRu2b@bobotheclown.org> wrote in message
> news:pan.2004.03.18.21.41.32.413018@bobotheclown.org...
>>
>> $ftp->get($file) if ($goodfile < "86400" & $file =~ /.*\.txt|.*\.xml/);
>>
>> the problem:
>> whenever I add "or print FILENAMES ..." to the last line it gets every
> file in
>> the remote dir.
>
>
> Most likely because there are a whole slew of problems with the above code.
> Going on the assumption that you typed that code in, the or is interpreted
> as being part of the if statement (i.e. get the file if the expressions in
> parens match, OR if the filename can be printed). One line statements are
> all the rage, but sometimes you can try and do too much in them:
>
> if (($goodfile < 86400) && ($file =~ /.*\.txt|.*\.xml/)) {
> $ftp->get($file)
> }
> else {
> print $file, "\n";
> }
>
> Matt
------------------------------
Date: Fri, 19 Mar 2004 02:07:50 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Help: Deleting Entries in Flat File Database
Message-Id: <pan.2004.03.19.01.06.21.801598@aursand.no>
On Thu, 18 Mar 2004 16:37:54 -0500, TP wrote:
> i wrote a html and ask from a user what name they want to remove from the
> database. And for example, if the user enter john, all other field with john
> will be deleted.
>
> [...]
>
> Here are partial code from my scripts
> $del1=$formdata{'del'}; # get the input what user want to delete
Are you using the CGI module? And do you 'use strict' and 'use warnings'?
> $dbpath = 'dbnew.txt';
my $dbpath = 'dbnew.txt';
> open(DB,"$dbpath");
> @array=<DB>;
> close(DB);
Always (!) check if open() succeeds;
open( DB, '<', $dbpath ) or die "Couldn't open '$dbpath'; $!\n";
my @array = <DB>;
close( DB );
> [...]
I didn't bother analyzing the rest of your code, but you're nevertheless
in trouble if multiple users tries to delete simultaneously.
However; You should go through the first line and write all the lines to
a new (temporary) file as long as the line shouldn't be deleted.
--
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
4 will be fought with sticks and stones." -- Albert Einstein
------------------------------
Date: Fri, 19 Mar 2004 02:07:49 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: HOW TO PARSE A VAST FILE!
Message-Id: <pan.2004.03.19.00.47.36.765428@aursand.no>
On Fri, 19 Mar 2004 01:05:53 +0800, news.hinet.net wrote:
> 163.22.3.7 2003/06/28 0011:00:42 PASSED
> http://proxy.ncnu.edu.tw/cgi-bin/squidGuard.cgi?clientaddr=163.22.28.128&clientname=ip128.puli28.ncnu.edu.tw&clientuser=&clientgroup=general-clients&targetgroup=moe&url=http://gatorcme.gator.com/gatorcme/autoupdate/precisiontime.ini
> 163.22.3.7 2003/06/28 0011:00:42 PASSED
> http://163.22.3.7/gatorcme/autoupdate/precisiontime.ini
> 163.22.3.7 2003/06/28 0011:00:43 PASSED
> http://proxy.ncnu.edu.tw/cgi-bin/squidGuard.cgi?clientaddr=163.22.9.25&clientname=ip025.puli09.ncnu.edu.tw&clientuser=&clientgroup=general-clients&targetgroup=moe&url=http://gatorcme.gator.com/gatorcme/autoupdate/installdatemanager.exe
> 163.22.3.7 2003/06/28 0011:00:43 PASSED
> http://163.22.3.3/gatorcme/autoupdate/installdatemanager.exe
> 218.172.162.134 2003/06/28 0011:00:44 PASSED
> http://liveupdate.symantecliveupdate.com/autoupdt.trg
> 218.172.162.134 2003/06/28 0011:00:44 PASSED
> http://202.239.172.95/autoupdt.trg
>
> [...]
> i want to find ip(163.22.3.7 218.172.162.134 ...) that are not exist in
> mysql.
There are two solutions here; The first is to read all the existing IP
addresses into a hash and check each one. The second one if to let MySQL
take care of the uniqueness of the IP address field (ie. setting that
field/column to unique in MySQL). The latter is probably the fastest (and
best way);
my %ip_addresses;
while ( <DATA> ) {
if ( /^(.*?)\s+/ ) {
$ip_addresses{$1}++;
}
}
my $stInsert = $dbh->prepare( 'INSERT INTO ip_addresses (ip_address) VALUES (?)' );
foreach ( keys %ip_addresses ) {
$stInsert->execute( $_ );
}
$stInsert->finish();
--
Tore Aursand <tore@aursand.no>
"Writing is a lot like sex. At first you do it because you like it.
Then you find yourself doing it for a few close friends and people you
like. But if you're any good at all, you end up doing it for money."
-- Unknown
------------------------------
Date: Thu, 18 Mar 2004 16:58:19 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <Pine.GSO.4.21.0403181649150.20707-100000@mtwhitney.nsc.com>
On 18 Mar 2004, Steve The Geek wrote:
(snipped)
...
> Is there any advantage (speed or legibility) to creating another
> variable name for the $DataLine[xx] scalars, e.g. $Enterprise =
> $DataLine[7], $GenericTrap = $DataLine[14], $SpecificTrap =
> $DataLine[15], etc.? A hash seems (to this novice) to be the way to go
> in that case...
>
> Are comments as a suffix (as listed in the script) acceptable?
I'm fond of using constants, such as:
use constant ENTERPRISE => 7;
# then down in your program:
return if $dataline[ENTERPRISE] eq 'RMON';
This way, if the order or number of elements in @dataline ever
changes, one can just update the constant and leave the remaining
code unchanged.
--
Hope this helps,
Steven
------------------------------
Date: 18 Mar 2004 20:28:45 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: NET::FTP debug output
Message-Id: <dfd17ef4.0403182028.3170dd39@posting.google.com>
hi
when i use NET::FTP to get some files from an ftp server, i get this message
Net::FTP=GLOB(0x1c98f4c)>>> CWD /
Net::FTP=GLOB(0x1c98f4c)<<< 501 A qualifier in "/" begins with an invalid cha
cter
What does this error mean?
thanks
------------------------------
Date: 18 Mar 2004 20:21:36 -0800
From: bunny1112@yahoo.com (Bunny)
Subject: Re: perl2exe can't locate DBI.pm
Message-Id: <d4a4789a.0403182021.68ac5d72@posting.google.com>
Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040318140750.K21521@dishwasher.cs.rpi.edu>...
> On Thu, 18 Mar 2004, Bunny wrote:
>
> > Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040318101447.T21521@dishwasher.cs.rpi.edu>...
> > > On Thu, 17 Mar 2004, Bunny wrote:
> > >
> > > > Date: 17 Mar 2004 22:38:02 -0800
> > > > From: Bunny <bunny1112@yahoo.com>
> > > > Newsgroups: comp.lang.perl.misc
> > > > Subject: perl2exe can't locate DBI.pm
> > > >
> > > > Hi!
> > > > I have perl5.00503 loaded on my Linux and I have downloaded and loaded
> > > > perl2exe V1.09U on Linux 6.1
> > > >
> > > > I have written a small code for extracting data from database. Now my
> > > > perl script runs fine and an appropriate output is also rendered by
> > > > the web browser.
> > > >
> > >
> > > Have you tried looking at the user's manual for perl2exe, or did you
> > > consider asking the world for help your first recourse instead?
> > >
> > > http://www.indigostar.com/pxman.htm
> > > FAQ #15: How to use DBI with Perl2Exe
> > >
> > > Paul Lalli
> >
> > Thanks Paul Lalli!!
> > I am sure you would not have gone through my code properly and thats
> > you had raised this question.. I had gone through the pxman.htm file
> > already and had added the statement "use DBI;" I also tried adding
> > the line "use DBD::mysql;" in my script but still getting the same
> > errors?????
>
> I did read your code "properly", and saw that you had not included the
> DBD::mysql line. That's why I sent you to the FAQ. Regardless, at this
> point I have to be wondering if this is simply a bug in the old version of
> perl2exe. Perl2exe's homepage says not to use the version specifically
> built for 5.005, even if that's what you 'normally' code with. Perl2exe's
> distribution includes a bundled Perl interpeter, so it doesn't matter what
> perl version is installed on your system. I would suggest downloading the
> latest version of Perl2exe and see what happens.
>
> Paul Lalli
Thanks once again Paul I was not sure if the latest verion would
support my old verion of Linux I was specific about the perl
verion???? Anyways I have downloaded the latest version as well and
shall be loading it and checking it up...
Bunny
------------------------------
Date: Fri, 19 Mar 2004 01:23:03 +0000 (UTC)
From: Bill Soistmann <bsoist@otaku.freeshell.org>
Subject: Re: Printing in Perl
Message-Id: <slrnc5kirk.f83.bsoist@otaku.freeshell.org>
In article <4059fc12@news.victoria.tc.ca>, Malcolm Dew-Jones wrote:
> Bill Soistmann (bsoist@sdf.lonestar.org) wrote:
>: Greetings
>: I have not used perl in some time and I was wondering if I could ask a
>: quick question.
>
>: Are parenthesis now required for printing? I know that had not always
>: been the case.
>
> no.
>
>: If so, I have another quick question
>: Is there an option to make old scripts work.
>
> What doesn't work? We have lots of old scripts that have continued to
> function unaltered for many years through many perl upgrades.
>
Never mind.
I thought I could ask a quick question without getting yelled at.
I have read the other replies and decided not to worry about it.
It must have something to do with the installation or something.
I was trying to help a student with a script in perl (He wants to learn
perl even though I don't recommend it), and ours seems to only work with
parenthesis. I was really on asking out of curiousity.
All my scripts work if I use the () so no need for the help.
I don't use perl anymore anyway.
BTW, thanks for at least being polite in this message.
--
Bill Soistmann
Always try to do things in chronological order; it's less confusing
that way.
------------------------------
Date: Fri, 19 Mar 2004 01:34:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Printing in Perl
Message-Id: <x7brmtd3gw.fsf@mail.sysarch.com>
>>>>> "BS" == Bill Soistmann <bsoist@otaku.freeshell.org> writes:
>> What doesn't work? We have lots of old scripts that have continued to
>> function unaltered for many years through many perl upgrades.
>>
BS> Never mind.
BS> I thought I could ask a quick question without getting yelled at.
BS> I have read the other replies and decided not to worry about it.
then why did you ask here at all?
BS> It must have something to do with the installation or something.
no, it has something to do with the code that you didn't post.
BS> I was trying to help a student with a script in perl (He wants to
BS> learn perl even though I don't recommend it), and ours seems to
BS> only work with parenthesis. I was really on asking out of
BS> curiousity.
and he asked you for help? you should have just sent him here directly
abd bypassed your sorry ass. good job 'helping' him.
BS> All my scripts work if I use the () so no need for the help.
and it shows you don't know perl if that is what you think is needed.
BS> I don't use perl anymore anyway.
good. perl doesn't need friends like you. at least learn the language if
you use it.
BS> BTW, thanks for at least being polite in this message.
and you were polite in return? your snide comments about perl were not
appreciated.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 19 Mar 2004 02:49:58 +0000 (UTC)
From: Bill Soistmann <bsoist@otaku.freeshell.org>
Subject: Re: Printing in Perl
Message-Id: <slrnc5knui.jls.bsoist@otaku.freeshell.org>
In article <x7brmtd3gw.fsf@mail.sysarch.com>, Uri Guttman wrote:
>>>>>> "BS" == Bill Soistmann <bsoist@otaku.freeshell.org> writes:
That's funny.
>
> >> What doesn't work? We have lots of old scripts that have continued to
> >> function unaltered for many years through many perl upgrades.
> >>
>
> BS> Never mind.
> BS> I thought I could ask a quick question without getting yelled at.
> BS> I have read the other replies and decided not to worry about it.
>
> then why did you ask here at all?
>
Obviously the sequence goes as follows:
1. I posted
2. I read the rude replies
3. and *then* I decided not to bother
> BS> It must have something to do with the installation or something.
>
> no, it has something to do with the code that you didn't post.
>
The code was from a book he was using.
I had used perl for many years and was confused as to why the code
did not work, so I tried some simple tests like:
print "Help Me";
and it would print nothing unless I did
print ("Help Me");
so I just was *curious* why -- not a big deal
> BS> I was trying to help a student with a script in perl (He wants to
> BS> learn perl even though I don't recommend it), and ours seems to
> BS> only work with parenthesis. I was really on asking out of
> BS> curiousity.
>
> and he asked you for help? you should have just sent him here directly
> abd bypassed your sorry ass. good job 'helping' him.
>
> BS> All my scripts work if I use the () so no need for the help.
>
> and it shows you don't know perl if that is what you think is needed.
You are missing the point to my original post
I try -- print "help me";
that doesn't work.
I try -- print ("help me");
and that does.
As was mentioned, I stopped using perl some time ago
I thought the syntax may have been changed.
Is that a crime?
>
> BS> I don't use perl anymore anyway.
>
> good. perl doesn't need friends like you. at least learn the language if
> you use it.
>
> BS> BTW, thanks for at least being polite in this message.
I was not being sarcastic here. I was replying to the only polite
reply I read.
>
> and you were polite in return? your snide comments about perl were not
> appreciated.
>
> uri
>
I am sincerely sorry. I did not mean to be snide.
I think perl is a fantastic language, I just don't use it anymore.
I also don't think it is particularly suited to new students, which
is why I don't recommend this student learn it.
Nothing against perl.
--
Bill Soistmann
Always try to do things in chronological order; it's less confusing
that way.
------------------------------
Date: Thu, 18 Mar 2004 22:53:19 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Printing in Perl
Message-Id: <qbidnWczK9g388fd4p2dnA@adelphia.com>
Bill Soistmann wrote:
> You are missing the point to my original post
>
> I try -- print "help me";
> that doesn't work.
The example you gave works in any standard production environment. Therefore
you've either left something out - i.e. the code that "doesn't work" is not
a simple 'print "help me";' - or your Perl is badly broken.
It's fairly unlikely that something as simple as 'print "help";' is broken
in your Perl. That leaves the alternative, which is that you're barking in
the wrong forest. There's probably something else wrong in the script
that's causing it to fail, but you haven't given enough detail for anyone
to help.
> I thought the syntax may have been changed.
It hasn't.
> Is that a crime?
Perhaps it should be. Do you *honestly* believe that the Perl developers
would be stupid enough to break compatibility with the bazillions of
scripts that omit the parentheses around function parameters?
In essence, you asked a vague question that was based on an assumption of an
absurd abount of stupidity on the part of Wall & Co. - and were surprised
when you received flames in return. The mind boggles.
sherm--
------------------------------
Date: Fri, 19 Mar 2004 01:01:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Regular Expressions Question
Message-Id: <x7ekrpd511.fsf@mail.sysarch.com>
>>>>> "PL" == Paul Lalli <ittyspam@yahoo.com> writes:
PL> On Thu, 18 Mar 2004, Emil Falcon wrote:
>> What regular expression must I use to match all lines NOT containing a
>> certain word? I basically need to sift through a large file and remove
>> all lines not beginning with the word "Display". Any help would be
>> appreciated.
PL> while (<FILE>){
PL> push @good_lines if $_ !~ /^Display/;
push @good_lines unless /^Display/;
i hate to see $_ and !~ used unnessarily
if you don't mind a list slurp of the file:
use File::Slurp ;
my @good_lines = grep( !/^Display/, read_file( 'filename' ) ) ;
the parens are just for the newbies who need them.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 19 Mar 2004 02:07:50 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Regular Expressions Question
Message-Id: <pan.2004.03.19.00.51.20.52043@aursand.no>
On Thu, 18 Mar 2004 11:12:50 -0800, Emil Falcon wrote:
> What regular expression must I use to match all lines NOT containing a
> certain word? I basically need to sift through a large file and remove
> all lines not beginning with the word "Display". Any help would be
> appreciated.
This one will print all lines, except those beginning with 'Diaplay':
while ( <FILE> ) {
next unless ( /^Display/ );
print;
}
--
Tore Aursand <tore@aursand.no>
"To cease smoking is the easiset thing I ever did. I ought to know,
I've done it a thousand times." -- Mark Twain
------------------------------
Date: 18 Mar 2004 19:56:17 -0800
From: blacraven@hotmail.com (S Raven)
Subject: Re: reverse search modifier
Message-Id: <6826327b.0403181956.37e47da9@posting.google.com>
Brian McCauley <nobull@mail.com> wrote in message news:<u9smg6ggv9.fsf@wcl-l.bham.ac.uk>...
> blacraven@hotmail.com (S Raven) writes:
>
> > Is there is any reverse search modifier that can be used in regexes?
>
> No.
>
> > Something like, $text =~ s/me/mine/r;
> > I have not seen anything like that before, so was wondering whether
> > there was one. Can anyone please clarify.
>
> When I first encountered regex I thought such a thing would be good
> but now I know more about regex I realise that understanding the
> semantics of such a modifer would be very complex.
>
> Anything you could achive can be equally done with greedy/non-greeded
> and/or lookahead/lookbehind. Or as a last resort simply reverse the
> string.
Thanks Brian.
I only wish that there would be something like that in future. Anyway
that clarified my doubt.
------------------------------
Date: Fri, 19 Mar 2004 04:06:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: reverse search modifier
Message-Id: <x7y8pxbhuq.fsf@mail.sysarch.com>
>>>>> "SR" == S Raven <blacraven@hotmail.com> writes:
SR> Brian McCauley <nobull@mail.com> wrote in message news:<u9smg6ggv9.fsf@wcl-l.bham.ac.uk>...
>> blacraven@hotmail.com (S Raven) writes:
>>
>> > Is there is any reverse search modifier that can be used in regexes?
>>
>> Anything you could achive can be equally done with greedy/non-greeded
>> and/or lookahead/lookbehind. Or as a last resort simply reverse the
>> string.
SR> I only wish that there would be something like that in future. Anyway
SR> that clarified my doubt.
can you show a reason why you need it? as brian said most likely you
could solve it with lookbehind or i will say even rindex can help.
what is the actual problem you have? i smell an XY problem where you
think a reverse looking regex is a good solution when it probably is
not. i have yet to see a real problem where a reverse regex is needed
and nothing else will do it.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 19 Mar 2004 03:56:13 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: seek help with regular expressions syntax
Message-Id: <405A6F58.6030101@rochester.rr.com>
Mad Scientist Jr wrote:
...
> catch all cases, and use something like ["|'] to "OR" the
> quote/apostrophe).
Nope, not quite. You mean ["'], which defines a character class which
will match either " or ' . ["|'] will match any of the three characters
" | ' . You could also use (?:"|') but that's not as good.
> the above was done for .net's regex object, so the syntax may be
> different. what are the s! are !i; for in the example you posted?
In Perl, the statement:
s!pattern!replacement!;
will match "pattern" against the contents of the default variable $_ and
replace the matched text with the string "replacement". The "s" is for
"substitute". The character following the s is the delimiter used.
This delimiter may be most any non-whitespace character (but there are a
number of special cases -- look in the docs). Normally / is used for
the delimiter, but, since / is used in your regexp, I chose ! instead to
avoid the necessity to escape the /'s. In the case of s, there will be
three delimiters. Following the last delimiter may be a set of flags,
one of which is the "i" flag. If present, the match will be done in a
case-insensitive fashion. So:
$_='a pAtTeRn string';
s!pattern!replacement!i;
print;
will print 'a replacement string';
If you have questions about .net, maybe a .net newsgroup would be a
better place to ask?
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Fri, 19 Mar 2004 03:38:12 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: stripping out ASCII chars using regexp?
Message-Id: <405A6B1F.2000009@rochester.rr.com>
Greg wrote:
> Bob Walton <invalid-email@rochester.rr.com> wrote in message news:<40590571.7090607@rochester.rr.com>...
>
>>Could you give us the URL of an example web page? And the (minimal)
>>code that grabs it and runs HTML::TableExtract? That is so we can run
>>it ourselves and see what is really going on. For example, is the above
>>the exact literal string which is generated? For debugging, that is
>>important to know.
>>
Thanks for the data and code. I verify the ASCII 160 characters in your
data. It looks like HTML::TableExtract is generating one of those in
place of each it encounters. You found your problem with why you
were unable to get rid of them (other posts in this thread), so I won't
dwell on that.
You can avoid decoding the entities by adding decode=>0 to the
list of initializations in your "new HTML::TableExtract" call. If you
do that, then you will see output like:
Argument "2.00 " isn't numeric in numeric ge (>=) at
junk438.pl line 57.
which clearly points out that your table entries do contain
characters in addition to the data you expected. So you are probably
doing the right thing by getting rid of the ASCII 160 characters.
HTH.
...
> Greg
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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.
#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 V10 Issue 6276
***************************************