[22672] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4893 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 25 14:06:06 2003

Date: Fri, 25 Apr 2003 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 25 Apr 2003     Volume: 10 Number: 4893

Today's topics:
    Re: approximate substitution <ubl@schaffhausen.de>
        check if it's an English word <bing-du@tamu.edu>
    Re: check if it's an English word (Walter Roberson)
    Re: compare two files (Helgi Briem)
    Re: Distribute a perl script (Randy Kobes)
    Re: Good Programming Practices - Avoiding Memory Leaks <kevin.vaughn@ttu.edu>
        How to delete the current array element? <SeeMessageBody@nospam.com>
        Is there an array for ($1, $2, $3, ...) (Sara)
    Re: Is there an array for ($1, $2, $3, ...) <ubl@schaffhausen.de>
    Re: Is there an array for ($1, $2, $3, ...) <bigj@kamelfreund.de>
    Re: Is there an array for ($1, $2, $3, ...) (Sara)
    Re: LWP::Simple "get" gets me one giant line.  Want arr <johngros@bigpond.net.au>
    Re: Perl and ASp <ddl76@singnet.com.sg>
    Re: Perl and ASp <abigail@abigail.nl>
    Re: Problem updating data in DB2 from webserver? <shah@typhoon.xnet.com>
    Re: Record seperator over lines (Sara)
    Re: Record seperator over lines <tassilo.parseval@rwth-aachen.de>
    Re: Regex greediness question <bigj@kamelfreund.de>
    Re: Regex greediness question <bigj@kamelfreund.de>
        RegEx question (Yang Xiao)
    Re: RegEx question <abigail@abigail.nl>
    Re: RegEx question <noreply@gunnar.cc>
    Re: search, replace and insert. <beable+unsenet@beable.com>
        Subscript of a match? or another solution? <johngros@bigpond.net.au>
    Re: Subscript of a match? or another solution? <ptlen@ceti.pl>
        Verifying if a regular expression is well formed (i5513)
    Re: Verifying if a regular expression is well formed <thepoet@nexgo.de>
    Re: Verifying if a regular expression is well formed (Anno Siegel)
    Re: {newbie} sorting  of files <wksmith@optonline.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 25 Apr 2003 17:16:24 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: approximate substitution
Message-Id: <b8bmlf$fav$1@news.dtag.de>

Helgi Briem wrote:
> On Fri, 25 Apr 2003 09:21:16 +0200, Malte Ubl
> <ubl@schaffhausen.de> wrote:
> 
> 
>>First of all thanks, it works. The Problem with Text::Soundex is that it 
>>finds only thinks that sound alike. A spelling mistake can seriously 
>>change the sound, so you won't get a match. At least that's what I think 
>>is happening.
> 
> 
>>I think in the case of my problem an algorithm based on edit distances 
>>would work better because spelling mistakes usually only increase the 
>>edit distance by one.
> 
> 
> How about String::Approx?

I used that in the original post :)

The question was more about the algorithm to make multi _word_ fuzzy 
matches than the fuzzy matching algorithm. See above post for more details.

I think that I should be able to adapt Benjamin's solution to work with 
String::Approx.

Bye,
malte.tar.gz



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

Date: Fri, 25 Apr 2003 10:25:42 -0500
From: Bing Du Test <bing-du@tamu.edu>
Subject: check if it's an English word
Message-Id: <3EA95376.363F6B8C@tamu.edu>

Greetings,

Is there any Perl module that can verify if part of a string is an
English word?  I need to upper case the first letter of English word.
If it's not an English word, leave it all capitalized.  For instance, an
input title is 'TTI MAMAGER'.  The output should be 'TTI Manager'.

Thanks in advance for any ideas,

Bing



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

Date: 25 Apr 2003 15:43:46 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: check if it's an English word
Message-Id: <b8bl3i$7f3$1@canopus.cc.umanitoba.ca>

In article <3EA95376.363F6B8C@tamu.edu>,
Bing Du Test  <bing-du@tamu.edu> wrote:
:Is there any Perl module that can verify if part of a string is an
:English word?  I need to upper case the first letter of English word.
:If it's not an English word, leave it all capitalized.  For instance, an
:input title is 'TTI MAMAGER'.  The output should be 'TTI Manager'.

There is no reliable way to do this in any computer language.
New English words are invented pretty much every day, and there is
no central registry of valid English words.

The closest one could come would be to use a word list
in conjunction with a spelling module that was able to recognize
common variations. Perhaps CPAN has a 'spell' module.
-- 
I predict that you will not trust this prediction.


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

Date: Fri, 25 Apr 2003 15:25:17 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: compare two files
Message-Id: <3ea9521d.1297624745@news.cis.dfn.de>

>> >Helgi Briem wrote:
>> >> my $sizediff = abs((-s $file1) - (-s $file2));
>> >> if ($sizediff > 300) { # do something }

On 24 Apr 2003 15:11:53 -0700, patyoung13@hotmail.com (Herb
Burnswell) wrote:
>I would like to thank all that responded.  I have found that it works
>best for me to use:
>
>$file1 = "logfile1";
>$file2 = "logfile2";
>
>$size1 = `wc -l $file1 | awk '{print \$1}'`;
>$size2 = `wc -l $file2 | awk '{print \$1}'`;
>$diff  = ($size1 - $size2);

You believe it's an improvement to invoke not
one, but two external programs (wc and awk)
and not once, but twice each, plus add two unneeded 
temporary variables in order to get something 
that you can get with a single built-in Perl operator?

Not to mention the fact that the whole thing is
far more complex and harder to understand.

The mind boggles.

If you don't understand the program I sent above, 
perhaps it is clearer like this:

my $size1 = -s $file1;
my $size2 = -s $file2;  

$diff = abs($size1 - $size2);
-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


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

Date: 25 Apr 2003 13:41:43 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Distribute a perl script
Message-Id: <slrnbaie31.7hm.randy@theoryx5.uwinnipeg.ca>

On 24 Apr 2003 12:24:06 -0700, Patrice <google@ppatrice.ovh.org> wrote:
>tadmc@augustmail.com (Tad McClellan) wrote in message 
  news:<slrnbafl0k.2rr.tadmc@magna.augustmail.com>...
>> Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
>> > Patrice wrote:
>>  
>> >> There's a
>> >> high probability they have a windows machine, but I'd like to provide
>> >> something for Linux as well.
>> >> My script is using two modules : XML::LibXML and XML::LibXSLT
>>                                     ^^^^^^^^^^^     ^^^^^^^^^^^^
>> Those are XS modules.
>
>So, what can I do ? Is it possible to have them into a standalone exe
>?
>I think I need the libxml and libxslt. I grabbed the binaries for
>win32 (from http://www.zlatkovic.com/projects/libxml/binaries.html)
>but I don't know what to do next and I couldn't get perlcc compile my
>script. The error is :
>Can't locate loadable object for module XML::LibXML::Common in @INC
>(@INC contains: ...)
>
>Thanks for your help.

For Win32, assuming ActivePerl, you can install XML::LibXML
and XML::LibXSLT with the ppm utility - we have them in
our repository at http://theoryx5.uwinnipeg.ca/ppms/ for
ActivePerl 8xx, and at http://theoryx5.uwinnipeg.ca/ppmpackages/
for ActivePerl 6xx. The XML-LibXML-Common package (which
should also be installed) contains the needed libxml2.dll,
which should be installed via a post-install script.

-- 
best regards,
randy kobes


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

Date: Fri, 25 Apr 2003 09:30:31 -0500
From: "Kevin Vaughn" <kevin.vaughn@ttu.edu>
Subject: Re: Good Programming Practices - Avoiding Memory Leaks
Message-Id: <vaihm1l6nc08c2@corp.supernews.com>

Just an update on what's been going on...

I set up a test server and started running the program every five minutes.
Even with all the Win32::OLE stuff commented out, the memory leak persists.
I'm losing about 10MB of RAM per day.

I'm going to turn on strict (ugh...) and fix my program.  Maybe that will do
the trick.  I'll let you know.

-Kevin

"Juha Laiho" <Juha.Laiho@iki.fi> wrote in message
news:b7o4ub$q0$1@ichaos.ichaos-int...
> "Kevin Vaughn" <kevin.vaughn@ttu.edu> said:
> >I'm having a problem with a small memory leak (~20MB/day). I have
> >traced the problem back to my Perl scripts.
> ...
> >I've written a 250 line Perl script and a bunch of smaller scripts that
> >are ~50 lines. All of these scripts run every five minutes, working
> >together to extract WMI information from servers (I'm also running
> >MRTG, which could conceivably be the culprit).
>
> So, are you saying that these scripts (also the 250-liner) are started
> fresh every five minutes (not that they just sleep for five minutes, do
> something, and go to sleep again but do not exit)?
>
> If it is so that the scripts are started fresh, the memory leak is
> not in Perl - but in your OS. Ok, something you do in Perl might be
> triggering the leak, but the leak still is on the OS side - which makes
> the Win32::OLE routines the most probable place of problems. You might
> try to check this by having the same script, but instead of calling
> things through Win32::OLE just return some fixed (or random) data.
>
> And as was mentioned in the other reply, use 'my' for declaring your
> variables, and limit them to the smallest possible scope. This also
> helps to keep your program(s) maintainable (and so do, after you cross
> the initial "pain", turning on warnings and strict). This doesn't help
> much in catching memory leaks, but it might catch some other problems
> that are waiting to bite you.
> --
> Wolf  a.k.a.  Juha Laiho     Espoo, Finland
> (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
>          PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
> "...cancel my subscription to the resurrection!" (Jim Morrison)




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

Date: Fri, 25 Apr 2003 18:03:00 GMT
From: "John" <SeeMessageBody@nospam.com>
Subject: How to delete the current array element?
Message-Id: <oLeqa.41713$4P1.3807038@newsread2.prod.itd.earthlink.net>

I put the lines of a report into an array and used "pop" and "shift" to trim
it down to the goodies.

The remaining lines begin with a keyword.  Unless that keyword exists in my
hash, I want that line out of the array.  This would be easily accomplished
by putting the lines into another hash (using that keyword as the key), but
that would lose their order.  The order of these lines is definitely *not*
trivial, and that's why I want to keep them in an array.  I wouldn't be able
to re-order them.

#
#  Go through @lines and remove those that don't exist in %myhash...
#
foreach (@lines) {
        if (/(^\w+)/) {                         # Grab that keyword from the
beginning of this line...
           unless exists $myhash{$1} {      #  ...unless it exists as a key
in %box, get rid of it.
                #  How to delete the current line from the array?  That's
the $64 question.
           }
}


Aside:  Didn't want to waste bandwidth for this before, but now that I'm
posting again:   THANKS to "mfield" for responding about "split" (his
solution was what I meant).  Thanks especially to Uri Guttman, David
Efflant, and Mr. John Gros for their excellent discussion!   :^)

Aside #2:  The most useful Perl book for my money (better than any other I
have) is "Learning Perl" by Schwartz & Phoenix.  Combined with searches of
groups.google.com, it answers a LOT of questions!  It is rich with
information.
--
------------------------------------------------
Feel free to mail me:  workingstiff19
 ...and that's at hotmail.





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

Date: 25 Apr 2003 06:12:20 -0700
From: genericax@hotmail.com (Sara)
Subject: Is there an array for ($1, $2, $3, ...)
Message-Id: <776e0325.0304250512.686df315@posting.google.com>

Of course we can use @ARGV for ($ARGV[0], $ARGV[1], ...)
and @_ for ($_[0], $_[1],...)

Is there an array defined for ($1, $2, $3,...)  after a regex defines
them? I did a perldoc -q on regex and some other keywords but I didn't
discover anything related.

Cheers. Hey its Friday can't be all bad!

-Gx


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

Date: Fri, 25 Apr 2003 15:23:36 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Is there an array for ($1, $2, $3, ...)
Message-Id: <b8bg20$oej$1@news.dtag.de>

Sara wrote:
> Of course we can use @ARGV for ($ARGV[0], $ARGV[1], ...)
> and @_ for ($_[0], $_[1],...)
> 
> Is there an array defined for ($1, $2, $3,...)  after a regex defines
> them? I did a perldoc -q on regex and some other keywords but I didn't
> discover anything related.

You can simply assign your regex to an array like this

my @matches = $string =~ /(\d)(\w)/


Bye,
->malte



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

Date: Fri, 25 Apr 2003 16:08:57 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Is there an array for ($1, $2, $3, ...)
Message-Id: <pan.2003.04.25.14.02.32.366977@kamelfreund.de>

Sara wrote at Fri, 25 Apr 2003 06:12:20 -0700:

> Of course we can use @ARGV for ($ARGV[0], $ARGV[1], ...)
> and @_ for ($_[0], $_[1],...)
> 
> Is there an array defined for ($1, $2, $3,...)  after a regex defines
> them? I did a perldoc -q on regex and some other keywords but I didn't
> discover anything related.

Well, normally you won't need a special array,
as you can always do something like

@array = $string =~ /match/;

and now @array contains ($1, $2, $3, ...)


Of course,
you could also use the variables
@+
@-
holding the beginning and ending indizes of the substring matched with
$1, $2, ....
Just read 
perldoc perlvar
for details about them.

> 
> Cheers. Hey its Friday can't be all bad!


Cheerio,
Janek


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

Date: 25 Apr 2003 10:37:35 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Is there an array for ($1, $2, $3, ...)
Message-Id: <776e0325.0304250937.64274b20@posting.google.com>

"Janek Schleicher" <bigj@kamelfreund.de> wrote in message news:<pan.2003.04.25.14.02.32.366977@kamelfreund.de>...
> Sara wrote at Fri, 25 Apr 2003 06:12:20 -0700:
> 
> > Of course we can use @ARGV for ($ARGV[0], $ARGV[1], ...)
> > and @_ for ($_[0], $_[1],...)
> > 
> > Is there an array defined for ($1, $2, $3,...)  after a regex defines
> > them? I did a perldoc -q on regex and some other keywords but I didn't
> > discover anything related.
> 
> Well, normally you won't need a special array,
> as you can always do something like
> 
> @array = $string =~ /match/;
> 
> and now @array contains ($1, $2, $3, ...)
  .
  .

Thanks both of you- I never saw that before. It doesn't come up often
that I'd need an array like that but on occasion it may be useful.

Regards,
Gx


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

Date: Fri, 25 Apr 2003 16:41:47 GMT
From: "John Gros" <johngros@bigpond.net.au>
Subject: Re: LWP::Simple "get" gets me one giant line.  Want array!
Message-Id: <fzdqa.11140$8K2.107748@news-server.bigpond.net.au>


"David Efflandt" <efflandt@xnet.com> wrote in message HTML linebreaks might
be represented
> by </p>, <p>, <br>, etc., or may wrap automatically based on your browser
> window size.  So you need to define what you consider a line and why it
> even matters.

It matters because when you are beginning perl using regexes is not as easy
as when you have been perling for years. Breaking up pages into lines helps
(for beginners) to make regexes to get the job done, inefficient,
multi-line, but at least done.




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

Date: Fri, 25 Apr 2003 22:48:54 +0800
From: "ldd" <ddl76@singnet.com.sg>
Subject: Re: Perl and ASp
Message-Id: <b8bh43$93c$1@reader01.singnet.com.sg>

I gave up Perl. Now try to use ASP only but my code below generates the
error

Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'isPostBack'
/AddFeedback.asp, line 11

Anyone knows why?

If isPostBack() then

   uname = Request.Form.Item("name")
   email =  Request.Form.Item("email")
   comment = Request.Form.Item("comment")

   If uname = NULL then
   nameErrCode = 1
   else
   nameErrCode = 0
   End if

   If email = NULL then
   nameEmailCode = 1
   else
   nameEmailCode = 0
   End if

   If comment = NULL then
   nameCommentCode = 1
   else
   nameCommentCode = 0
   End if

   If ((nameErrCode = 0) and (nameEmailCode = 0) and (nameCommentCode = 0))
then

 'Set DatabaseConnection = Server.CreateObject("ADODB.Connection")

 'DatabaseConnection.Open "FILEDSN=C:/bestcar/bettercar.dsn"

    'Call AddFeedback
 'DatabaseConnection.Close

 Response.Write("<h1>Thank you, " & Request.Form.Item("name") & "!</h1><br>
Your feedback was successfully submitted.")

    Else

 Response.write("pls")

   End If

End If


"Chris Olive" <nospam@raytheon.com> wrote in message
news:EsBpa.337$35.1159@dfw-service2.ext.raytheon.com...
> ldd wrote:
> > Thanks I tried to incorporate Perlscript in ASP but it doesn't work not
sure
> > why.
> >
> > I modified instructions from here but it still doesn't work. Basically
after
> > a parameter like $name is passed into the Perlscript, an if statement is
> > used to check if its "ddl". But the parameter is not compared correctly.
I
> > even tried to print out the value from the Perlscript section and it
even
> > cannot be printed.
> >
> > I'm desparate Can anyone kind soul in this world help me. Thanks a
million
> > and billi.....
> >
> > Following is a simple ASP document that contains a PerlScript function,
and
> > VBScript code that calls it:
> >
> > 1    <% @LANGUAGE="VBSCRIPT" %>
> > 2    <script language="PerlScript" runat="server">
> > 3    sub sayHello {
> > 4    # This function takes two parameters, creates a string
> > 5    # from the parameters, and returns the string.
> > 6
> > 7     # get the two parameters into local variables
> > 8     my ($strName, $strTime) = @_;
> > 9     #now, create the return string.
> > 10    $strRetVal="Hello $strName. The time is $strTime.";
> > 11
> > 12    # Return the string
> > 13    $strRetVal;
> > 14   }
> > 15   </script>
> > 16   <html>
> > 17   <head>
> > 18   <title>Test of a PerlScript function being called from
VBScript</title>
> > 19   </head>
> > 20   <body>
> > 21   <h2>Test of a PerlScript function being called from VBScript</h2>
> > 22   <%
> > 23
> > 24    strOutput=sayHello("Richard",Now & "")
> > 25    Response.Write strOutput & "<br>"
> > 26   %>
> > 27
> > 28
> > 29   <p><%
> > 30   '-- asp stub
> > 31   if (Request("CloseMe")) then
> > 32   %>
> > 33   </p>
> > 34   <form method="POST" action="" onsubmit="return false">
> > 35    <p><input type="button" value="Close" onclick="self.close();"></p>
> > 36   </form>
> > 37   <p><%
> > 38   end if
> > 39   '-- asp stub
> > 40   %>
> > 41   </p>
> > 42
> > 43
> > 44
> > 45   </body>
> > 46   </html>
> >
>
> So what does it do?  What error do you get?  This looks correct, and I
> even ran it on my system just fine.  Maybe try JUST a PerlScript .ASP
> page and see what that does.  Maybe PerlScript isn't installed
> correctly.  Just a guess.  This works for me.
>
> Chris
> -----
> Chris Olive
> Systems Consultant
> Raytheon Technical Services Corporation
> Indianapolis, IN
>
> email: olivec(AT)indy(DOT)raytheon(DOT)com
>




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

Date: 25 Apr 2003 15:11:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl and ASp
Message-Id: <slrnbaik10.fbv.abigail@alexandra.abigail.nl>

ldd (ddl76@singnet.com.sg) wrote on MMMDXXIV September MCMXCIII in
<URL:news:b8bh43$93c$1@reader01.singnet.com.sg>:
@@  I gave up Perl. Now try to use ASP only but my code below generates the
@@  error
@@  
@@  Microsoft VBScript runtime (0x800A000D)
@@  Type mismatch: 'isPostBack'
@@  /AddFeedback.asp, line 11
@@  
@@  Anyone knows why?


You have an error in line 11.

Why are you posting this in a Perl group?


Abigail
-- 
perl -Mstrict -we '$_ = "goto Q.print chop;\n=rekcaH lreP rehtona tsuJ";Q1:eval'


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

Date: Fri, 25 Apr 2003 13:45:58 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: Problem updating data in DB2 from webserver?
Message-Id: <b8be6m$rdb$1@flood.xnet.com>

While stranded on information super highway Darin McBride wrote:
:)Hemant Shah wrote:
:)
:)> I am using CGI.pm to render HTML pages and I also use DBI and DBD::DB2
:)> to query the database. The script that queries the database is working
:)> O.K. But the script I use to update the table is giving me problems.
:)> 
:)> When I try to insert or delete a row from the table, I get error message
:)> that I am violating constraint 1. I checked all the constraints on the
:)> table but I cannot see it violating any constraints. Funny thing is that
:)> the insert or delete is done successfully. I have turned off AutoCommit so
:)> it should not commit anything. Couple of other things I noticed is that
:)> when the update of the table fails, I cannot use the database, I cannot
:)> even do the queries on the command line unless I run "force application
:)> all".
:)> 
:)> I also noticed that even though I execute $dbh->disconnect, the connection
:)> is still there, "list applications" show all the connection with UOW
:)> waiting.
:)> 
:)> I have written many perl script with DBD::DB2 and I have never encountered
:)> such problem. This the first time I am writing perl script that is execute
:)> from a web server using mod_perl.
:)> 
:)> Are there any tricks to writing DBD:DB2 scripts while running under
:)> mod_perl?
:)
:)Probably.  However, I would guess that they are the same tricks that you 
:)need under any DBI-based driver (Oracle, Sybase, Informix, etc.), and the 
:)DBI mailing list may be a better place for this question.  Personally, I've 
:)not yet used mod_perl for my DBI-based CGI scripts, so I can't really help, 
:)although I've seen many mod_perl-related questions on the DBI list.  See 
:)the documentation for the DBI module (perldoc DBI) for how to join.
:)
:)Also, may I recommend trying without mod_perl to see if that actually is the 
:)problem?  I understand you've written without mod_perl before, but perhaps 
:)it's something specific to this application other than mod_perl.  It's 
:)always nice to be able to confirm the cause of the problem before solving 
:)it ;-)

   It is related to how Apache/mod_perl caches things. I could run the same
   script from command line without any problem.

:)
:)Oh, and if you find a solution other than on the DBI list, please post back 
:)here - I'd love to know the gotchas before I go down that route.  I'm 
:)hoping to go to mod_perl (to learn it), but just haven't had the time 
:)and/or the guts :-)
:)

  I will try the mod_perl mailing list and I will also search google groups
  to see if I find anything.
  
  Thanks.


-- 
Hemant Shah                           /"\  ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com       \ /  --------------------- 
                                       X     against HTML mail
TO REPLY, REMOVE NoJunkMail           / \      and postings      
FROM MY E-MAIL ADDRESS.           
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind,                Above opinions are mine only.
it's backed up on tape somewhere.      Others can have their own.


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

Date: 25 Apr 2003 10:39:25 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Record seperator over lines
Message-Id: <776e0325.0304250939.7accba67@posting.google.com>

"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<b8b0i7$955$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach kderaedt:
> 
> >     I have a problem with a files where I have different records.  The
> > records can be separated by a new line.  How can I eliminate this new line?
> > See example below.
> > 
> > Content test file:  Record seperator is #%#
> > 
> > qmfkjsqfjqmskfdj #%# qsfqsdfqgqsg
> > qsdfqsdfqs # qsdfqsdfqsdffdqqsdf #%#
> > 
> > Used code for the record seperator:
> > #!/usr/bin/perl
> > open (IN, "wsp.out");
> > open (OUT, "> wsp.new");
> > local $/ = '#%#';
> > $a = 0;
> > while(<IN>) {
> >    $Line = $_;
> >    $a++;
> > }
> 
> Don't do the copy into $Line. Just use $_ (unless you need a copy, of
> course). To get rid of newlines, simply add:
> 
>     while (<IN>) {
>         tr/\n//d; # works on $_
>         ...
>     }
>  
> > close IN;
> > close OUT;
> > 
> > Output:
> > 1 : qmfkjsqfjqmskfdj #%#
> > 2 :  qsfqsdfqgqsg
> > qsdfqsdfqs # qsdfqsdfqsdffdqqsdf #%#
> > 
> > 
> > Should be:
> > 1 : qmfkjsqfjqmskfdj #%#
> > 2 :  qsfqsdfqgqsgqsdfqsdfqs # qsdfqsdfqsdffdqqsdf #%#
> 
> Tassilo

Don't forget about good old Mr chomp()

-Gx


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

Date: 25 Apr 2003 17:56:12 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Record seperator over lines
Message-Id: <b8bsrs$gdj$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Sara:

>> Also sprach kderaedt:

>> >     I have a problem with a files where I have different records.  The
>> > records can be separated by a new line.  How can I eliminate this new line?
>> > See example below.
>> > 
>> > Content test file:  Record seperator is #%#
>> > 
>> > qmfkjsqfjqmskfdj #%# qsfqsdfqgqsg
>> > qsdfqsdfqs # qsdfqsdfqsdffdqqsdf #%#

> Don't forget about good old Mr chomp()

Err, no. chomp() removes a trailing record-separator (which has been
tampered with in this case), not necessarily a newline.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Fri, 25 Apr 2003 16:09:07 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Regex greediness question
Message-Id: <pan.2003.04.25.14.08.04.880104@kamelfreund.de>

Sara wrote at Fri, 25 Apr 2003 05:26:14 -0700:

> in a regex, would 
> 
>   /(something)*?/ 
> 
> ever be any different than 
> 
>   /(something)*/
> 
> Wouldn't both match zero-many sometings?

No, look at the one liner,
showing the difference:

perl -e '$_ = "somethingsomething"; /(something)*?/; print "*?: $&\n"; /(something)*/; print "*: $&"'

($& holds the last succesfull matching)

> Just looked odd to me. 
> 
> -Gx


Cheerio,
Janek


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

Date: Fri, 25 Apr 2003 16:09:08 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Regex greediness question
Message-Id: <pan.2003.04.25.14.08.09.937641@kamelfreund.de>

Sara wrote at Fri, 25 Apr 2003 05:26:14 -0700:

> in a regex, would 
> 
>   /(something)*?/ 
> 
> ever be any different than 
> 
>   /(something)*/
> 
> Wouldn't both match zero-many sometings?

No, look at the one liner,
showing the difference:

perl -e '$_ = "somethingsomething"; /(something)*?/; print "*?: $&\n"; /(something)*/; print "*: $&"'

($& holds the last succesfull matching)

> Just looked odd to me. 
> 
> -Gx


Cheerio,
Janek


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

Date: 25 Apr 2003 10:16:28 -0700
From: yxiao@panix.com (Yang Xiao)
Subject: RegEx question
Message-Id: <674d27b7.0304250916.69e8df41@posting.google.com>

Hi all,
How to I simplify this?

if(/(NYWS)\d{1,3}\$?/ or /(LNWS)\d{1,3}\$?/ or /CHARTER/ or /LNFFTW/){
do something here...
}


thanks,

Yang


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

Date: 25 Apr 2003 17:22:03 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: RegEx question
Message-Id: <slrnbairlr.fir.abigail@alexandra.abigail.nl>

Yang Xiao (yxiao@panix.com) wrote on MMMDXXIV September MCMXCIII in
<URL:news:674d27b7.0304250916.69e8df41@posting.google.com>:
!!  Hi all,
!!  How to I simplify this?
!!  
!!  if(/(NYWS)\d{1,3}\$?/ or /(LNWS)\d{1,3}\$?/ or /CHARTER/ or /LNFFTW/){
!!  do something here...
!!  }

Not much to simplify here, just lose the pointless \$?.

    if(/(NYWS)\d{1,3}/ or /(LNWS)\d{1,3}/ or /CHARTER/ or /LNFFTW/){
        do something here...
    }


Abigail
-- 
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/


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

Date: Fri, 25 Apr 2003 19:25:20 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RegEx question
Message-Id: <b8br6q$8asof$1@ID-184292.news.dfncis.de>

Yang Xiao wrote:
> How to I simplify this?
> 
> if(/(NYWS)\d{1,3}\$?/ or /(LNWS)\d{1,3}\$?/ or /CHARTER/ or /LNFFTW/){
> do something here...
> }

     if(/(?:NYWS|LNWS)\d{1,3}\$?/ or /CHARTER/ or /LNFFTW/)

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 25 Apr 2003 12:25:53 +1000
From: Beable van Polasm <beable+unsenet@beable.com>
Subject: Re: search, replace and insert.
Message-Id: <ee3ck7gvny.fsf@dingo.beable.com>

"Abhi" <abhinospam@kizna.com> writes:
> 
> I am making an rpm which involves enabling mod_proxy module in httpd.conf of
> apache

> What I need to do is to enable/uncomment the mod_proxy module entries i.e.
> 
> perl -pi -e 's|^#LoadModule proxy_module|LoadModule proxy_module|g'
> /etc/httpd/conf/httpd.conf
> perl -pi -e 's|^#AddModule mod_proxy.c|AddModule mod_proxy.c|g'
> /etc/httpd/conf/httpd.conf

You know, you don't HAVE to uncomment those lines. You can just add 
brand new lines.

> but the problem is I also need to do this :
> 
> perl -pi -e 's|^#<IfModule mod_proxy.c>|<IfModule mod_proxy.c>|g'
> /etc/httpd/conf/httpd.conf
> 
> and insert a few entries on a new line afterwards, and then uncomment the
> *next* matching </IfModule>

#!/usr/bin/perl -w

use strict;

my $conf = "httpd.conf";
open HTTPD_CONF, ">>$conf" or die "can't open $conf: $!";

print HTTPD_CONF << "EOF";
LoadModule proxy_module
AddModule mod_proxy.c
<IfModule mod_proxy.c>
# a few entries on a 
# new line afterwards
</IfModule>
EOF

__END__


> But is it possible to do this without including and invoking a seperate perl
> script file in the rpm ? I mean just using the perl -pi -e syntax in the rpm
> spec file ?

/usr/bin/perl -w -e 'use strict; my $conf = "httpd.conf"; open HTTPD_CONF, ">>$conf" or die "failed to open $conf: $!"; print HTTPD_CONF "LoadModule proxy_module\nAddModule mod_proxy.c\n<IfModule mod_proxy.c>\n# a few entries on a \n# new line afterwards\n</IfModule>\n"; close HTTPD_CONF;' 

cheers
Beable
-- 
    Why are General Tommy Franks and H.G. Nelson never seen in the
             same place at the same time? -- Phil Doyle
                             http://beable.com



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

Date: Fri, 25 Apr 2003 15:06:29 GMT
From: "John Gros" <johngros@bigpond.net.au>
Subject: Subscript of a match? or another solution?
Message-Id: <V9cqa.11106$8K2.107268@news-server.bigpond.net.au>

I dunno what I am doing, and I am sure you can tell. I have tried to find a
way to get the subscript of a match to extract the description that goes
with an HTML a href tag, I have also tried this code to extract the
description but I am getting an error. 'Use of uninitialised value in
concatenation ( . ) or string at .... line 22.'

My code is as follows.

#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $doc = get 'http://www.nswtab.com.au/today/today.htm';
my @links;
my @lines = split( / /,$doc); # seperate  the html into lines
my @course;
my $temp;
my $counter = 0;
foreach(@lines){
 if ($_ =~ /[A-Z]{2}.HTM>\D/ && $_ !~/DIVS/) # only the lines I want
 {
  $links[$counter] = substr($_,5,6); # the actual link
  $temp = /($links[$counter]<)(\w*)/; # matching to get the description of
the link
  $course[$counter++] = $2; # assigning the description (failing for some
reason! $temp regex not matching?)
 }
}
$counter = 0;
foreach(@links){
 print "$_ : $course[$counter++] \n";
}





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

Date: Fri, 25 Apr 2003 17:13:36 +0000 (UTC)
From: Filip G. <ptlen@ceti.pl>
Subject: Re: Subscript of a match? or another solution?
Message-Id: <slrnbainlt.10m.ptlen@localhost.localdomain>

John Gros pisze:
> I dunno what I am doing, and I am sure you can tell. I have tried to find a
> way to get the subscript of a match to extract the description that goes

>   $temp = /($links[$counter]<)(\w*)/; # matching to get the description of
                              ^

Shouldn't it be '>' instead of '<'?



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

Date: 25 Apr 2003 06:54:50 -0700
From: i5513@hotmail.com (i5513)
Subject: Verifying if a regular expression is well formed
Message-Id: <a657ec02.0304250554.5bc15e40@posting.google.com>

If I have a var $er with a regular expression, how can I control about
if it is well formed?

if (&well_formed ($er))
{
  print "OK";
}
else
{
  print "NOK";
}
What function is well_formed?

Thanks you very much


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

Date: Fri, 25 Apr 2003 16:31:08 +0200
From: "Christian Winter" <thepoet@nexgo.de>
Subject: Re: Verifying if a regular expression is well formed
Message-Id: <3ea946ad$0$18091$9b4e6d93@newsread4.arcor-online.net>

"i5513" <i5513@hotmail.com> wrote:
> If I have a var $er with a regular expression, how can I control about
> if it is well formed?
[...]
> What function is well_formed?

sub well_formed {
  my $re = shift;
  if( eval "qr/$re/" ) {
    return $re;
  }
  return undef;
}

see "perldoc perlop" on details regarding the
qr// operator.

HTH
-Christian



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

Date: 25 Apr 2003 17:52:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Verifying if a regular expression is well formed
Message-Id: <b8bska$1gn$1@mamenchi.zrz.TU-Berlin.DE>

Christian Winter <thepoet@nexgo.de> wrote in comp.lang.perl.misc:
> "i5513" <i5513@hotmail.com> wrote:
> > If I have a var $er with a regular expression, how can I control about
> > if it is well formed?
> [...]
> > What function is well_formed?
> 
> sub well_formed {
>   my $re = shift;
>   if( eval "qr/$re/" ) {
>     return $re;
>   }
>   return undef;
> }
> 
> see "perldoc perlop" on details regarding the
> qr// operator.

That's correct, though verbose (the "if" clause takes pains to return
what "eval ..." returns anyway).  Also, you use string eval where the
more light-weight block eval would have done.  I'd write this

    sub well_formed {
        no re 'eval';
        my $re = shift;
        eval { qr/$re/ };
    }

I have added "no re 'eval'", but that isn't mandatory.  For one, it's
the default, and then the OP may want to have embedded code executed.

However, if the source of the pattern string can't be trusted, or
if the job of well_formed() is to ascertain that the regex can be
safely called later in the program (without crashing it or worse),
then "no re 'eval'" should be added.

Anno


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

Date: Fri, 25 Apr 2003 14:30:28 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: {newbie} sorting  of files
Message-Id: <8Ebqa.123534$MB4.43216574@news4.srv.hcvlny.cv.net>


"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns9367E43F490B8sdn.comcast@216.166.71.239...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "Bill Smith" <wksmith@optonline.net> wrote in
> news:o3_pa.120670$MB4.40452999@news4.srv.hcvlny.cv.net:
>
> > "Uri Guttman" <uri@stemsystems.com> wrote in message
> > news:x765p3lh0y.fsf@mail.sysarch.com...
> >> >>>>> "o" == oracle1  <santyspamsharma@hotmail.com> writes:
> >>
> >>   o> sub by_time_and_files {
> >>   o>  $file_hash{b} <=> $file_hash{a}
> >>                  $b                $a
> >
> >
> > This is the kind of error that use strict usually finds.
>
> Why would 'use strict' have found this error?
>
It would not have.  I should have said what I meant by 'this is the kind
of error.'  'use strict' is a valuable aid in finding forgotten dollar
signs, misspellings, and similar typos.  It never occurred to me that
the underlying error could be anything else.  I did admit that in this
case, 'use strict' would not have helped.  My advice stands for those of
us who are prone to making these careless errors.

Sorry about the confusion.
Bill




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

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.  

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


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