[22660] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4881 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 23 18:05:51 2003

Date: Wed, 23 Apr 2003 15:05:09 -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           Wed, 23 Apr 2003     Volume: 10 Number: 4881

Today's topics:
        Changing Process Priority <lapenta@ll.mit.edu>
    Re: Changing Process Priority <galenmenzel@yahoo.com>
    Re: Changing Process Priority <grazz@pobox.com>
    Re: DESPERATE: Win32::OLE Iteration Variable Problem <tim@mcguireland.com>
        exclusive lock - bad file number <tomcat@visi.com>
    Re: korn shell or perl <No_4@dsl.pipex.com>
    Re: OT slightly: mod_perl vs JSP <richard@zync.co.uk>
    Re: OT slightly: mod_perl vs JSP (Malcolm Dew-Jones)
    Re: Perl and ASp <nospam@raytheon.com>
    Re: Perl's exec and system use the shell even if the do <nobull@mail.com>
    Re: Perl's exec and system use the shell even if the do <grazz@pobox.com>
    Re: Perl's exec and system use the shell even if the do <j.g.karssenberg@student.utwente.nl>
        POD help - please - first time with pod2html <jozefn@bolt.sonic.net>
    Re: POD help - please - first time with pod2html <noreply@gunnar.cc>
    Re: print out multi queries <member17678@dbforums.com>
    Re: print out multi queries <member17678@dbforums.com>
    Re: print out multi queries (Malcolm Dew-Jones)
    Re: Read File, write filename? (entropy123)
    Re: reg expr prl newbie <bigj@kamelfreund.de>
    Re: regular expression question <bigj@kamelfreund.de>
    Re: regular expression question <greg@hassan.com>
        Search engine design tips (OT?) <stevenm@bogus.blackwater-pacific.com>
    Re: Search engine design tips (OT?) <galenmenzel@yahoo.com>
    Re: Still Stumped <delautenschl@[nospam]wisc.edu>
    Re: Tough question for the guru's; Grep Once, Awk Twice (Agrapha)
    Re: Tough question for the guru's; Grep Once, Awk Twice (Randal L. Schwartz)
    Re: Tough question for the guru's; Grep Once, Awk Twice <abigail@abigail.nl>
    Re: Tough question for the guru's; Grep Once, Awk Twice <tassilo.parseval@rwth-aachen.de>
    Re: webhosts that support perl well? <greg@hassan.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 23 Apr 2003 15:30:20 -0400
From: "Jason M. LaPenta" <lapenta@ll.mit.edu>
Subject: Changing Process Priority
Message-Id: <3EA6E9CC.3040001@ll.mit.edu>

Hello,

I'm trying to up the process of my perl program with the following

setpriority( PRIO_PROCESS, getppid(), -5 ); # PRIO_PROCESS doesn't work

or

setpriority( 0, getppid(), -10 );

and neither do anything. How am I supposed to use this function? the 
docs are almost useless.

Thanks
J



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

Date: 23 Apr 2003 19:56:10 GMT
From: Galen Menzel <galenmenzel@yahoo.com>
Subject: Re: Changing Process Priority
Message-Id: <slrnbads4f.1te.galenmenzel@localhost.localdomain>

In article <3EA6E9CC.3040001@ll.mit.edu>, Jason M. LaPenta wrote:
> Hello,
> 
> I'm trying to up the process of my perl program with the following
> 
> setpriority( PRIO_PROCESS, getppid(), -5 ); # PRIO_PROCESS doesn't work
> 
> or
> 
> setpriority( 0, getppid(), -10 );
> 
> and neither do anything. How am I supposed to use this function? the 
> docs are almost useless.

What error are you getting?  How do you know these functions aren't
doing anything?  Only root can lower the priority of a process, so if
your script isn't running as root, it's no wonder you're having
trouble.  Perl's setpriority is implemented in terms of the UNIX
setpriority system call.  See the setpriority manpage for all you ever
wanted to know about it.

galen


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

Date: Wed, 23 Apr 2003 20:09:14 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Changing Process Priority
Message-Id: <KpCpa.23839$J17.4878@twister.nyc.rr.com>

Jason M. LaPenta <lapenta@ll.mit.edu> wrote:
> 
> I'm trying to up the process of my perl program with the 
> following
> 
> setpriority( PRIO_PROCESS, getppid(), -5 ); 
> # PRIO_PROCESS doesn't work
> 
> or
> 
> setpriority( 0, getppid(), -10 );
> 
> and neither do anything.

They probably fail, and without any error-checking they'll fail
silently.   This might fit your definition of "not doing anything",
but it's the usual behavior for Perl's system call functions so 
you might as well get used to it.

    defined( setpriority, 0, getppid(), -10 )
      or die "setpriority: $!";

> How am I supposed to use this function?  the docs are almost 
> useless.
 
Well, perlfunc just refers you to your system documentation.  Do
you have setpriority()?  Have you you read setpriority(2)?  Is the
script running as root?

Anyway, there's actually a full-blown example in the perltie manpage,
which is kind of an odd place for it, but grepping for PRIO_PROCESS
could lead you there.

The constants are in the BSD::Resource (CPAN) module.

    use BSD::Resource;

    defined( setpriority PRIO_PROCESS, $$, -5)
      or die "setpriority: $!";

And nice() is in the standard POSIX module.

(And you might want $$ instead of getppid.)

HTH
-- 
Steve


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

Date: Wed, 23 Apr 2003 15:53:06 -0400
From: "Tim McGuire" <tim@mcguireland.com>
Subject: Re: DESPERATE: Win32::OLE Iteration Variable Problem
Message-Id: <b86qv901sm1@enews1.newsguy.com>

I found it...this might help a lot of folks new to Win32::OLE...maybe even
intermediates like me...first time I have ran into it...basically the
EnumProjects function needed the variable $It to be "BY REFERENCE" so it
could modify it as well as of type "VT_VARIANT" Basically I only had to use
Win32::OLE::Variant and change the line "$It = 0;" to "$It =
Win32::OLE::Variant->new(VT_VARIANT|VT_BYREF, 0);"....then it all screamed
to life....I had been banging my head for a while on this one....

Thanks to any who were investigating already...


Tim


"Tim McGuire" <tim@mcguireland.com> wrote in message
news:b868fj0v59@enews1.newsguy.com...
> I am trying to get a very simple piece of data out....My perl code is
below
> and the ASP script I am mimicking is blow that...the only problem is when
I
> get to the enumeration part...I only get one record into the $Project
object
> (a hash)...The automation library's EnumProjects routine gets a $Iterator
> passed to it, which I think is supposed increment by itself as you call
the
> routine again and again...My code will not work this way...The $Iterator
> never gets incremented because the while loop runs forever and always
> displays only the first Project Name...I have tried incrementing the
> $Iterator myself, I have tried making $Project an Win32::OLE::Enum object
> (which gives an error that $Project is not a valid collection object)....I
> have tried using the Next method on $Project which runs, but gives a
'member
> not found' error....I should have at least four projects....when this
> originally happened I added a project...the same thing happened, but my
> newly added project name showed up instead of the original one so I
believe
> the code is good...
>
>
>  I am pretty sure that the magic iteration variable is not getting
> incremented...any help greatly appreciated....I AM STUMPED
>
>
>  ###PERL CODE
>  #
>  #
>
>
>  use Win32::OLE;
>  use Win32::OLE::Enum;
>  #Win32::OLE->Option(_NewEnum => 1);
>  $CrsSrv = Win32::OLE->new("CrsApi.ReplicationServer");
>  &OLEErrorCheck;
>  $CrsSrv->Initialize("");
>  &OLEErrorCheck;
>  $Iterator = 0;
>  $Project = $CrsSrv->EnumProjects($Iterator) || die "ERROR: " .
> Win32::OLE->LastError();
>  #$Enum = Win32::OLE::Enum->new($Project);
>  #@Projects=$Enum->All;
>  while (!Win32::OLE->LastError()) {
>     print "Name: " . $Project->Name() . "\n";
>     undef $Project;
>     $Project = $CrsSrv->EnumProjects($Iterator)
>  }
>
>  sub OLEErrorCheck {
>     $errorcheck = Win32::OLE->LastError();
>     if ($errorcheck) {
>        print "\n***ERROR***: $errorcheck";
>        return 1;
>     }
>     else
>        {return 0;}
>  }
>
>
>  ############################################
>  ###Working ASP Script (CatchAndReportError() sub omitted for brevity)
>  #
>
>      Set m_objCrsServer = Server.CreateObject("CrsApi.ReplicationServer")
>      Call CatchAndReportError()
>      m_objCrsServer.Initialize("")
>      If (Err.Number <> 0) Then
>        Call CatchAndReportError()
>        Exit Sub
>      End If
>      nIterator = 0
>      Set objCrsProject = m_objCrsServer.EnumProjects(nIterator)
>      While (Err.Number = 0)
>        Response.Write objCrsProject.Name
>        Set objCrsProject = Nothing
>        Set objCrsProject = m_objCrsServer.EnumProjects(nIterator)
>      Wend
>
>
>
>
>




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

Date: Wed, 23 Apr 2003 15:24:57 -0500
From: uNConVeNtiOnAL <tomcat@visi.com>
Subject: exclusive lock - bad file number
Message-Id: <3EA6F699.A35A2933@visi.com>

I get this error

can't get exclusive lock on /home/mydir/members.txt.sem:
Bad file number at my.cgi line 54.

when I run this code:

# first, get an exclusive lock on the queue semaphore file.
    my $lockfile = $Socalsail::Register::queue_file_semaphore;
    open QUEUE_LOCK, "> $lockfile"
        or die "can't open $lockfile for writing: $!";
    flock QUEUE_LOCK, LOCK_EX                         <== line 54!!!
        or die "can't get exclusive lock on $lockfile: $!";

Anybody recognize what is wrong?

The file and directory permissions are 775
This is on unix

Tom



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

Date: Wed, 23 Apr 2003 22:36:51 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: korn shell or perl
Message-Id: <3ea70773$0$957$cc9e4d1f@news.dial.pipex.com>

"Michael Vilain " wrote:
> 
> what's wrong with grep piped through awk?

    Because you don't need grep.  awk could do it all.

 >                                                            If all the
> lines that contain "src:" are formatted the same, then you can extract 
> that column with awk.


    and you could select them with awk, too. It all becomes an awk 
one-liner:
  awk '/src: / {print $NF}'  filename


-- 
      -*-    Just because I've written it here doesn't    -*-
      -*-    mean that you should, or I do, believe it.   -*-



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

Date: Wed, 23 Apr 2003 19:35:56 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: OT slightly: mod_perl vs JSP
Message-Id: <20030423.193556.1451042659.18265@richg.zync>

Hi

Apache::Registry nearly does it for me, but the implicit handler function
interferes with the scope of the request context vars which I declare and
instantiate at the top of each cgi. I could as easily rewrite into
mod_perl as Apache::Registry. (Well, nearly!)

Apparently Resin beats mod_perl these days, at least according to the
Resin website ;-) However, I agree with you about programming style. All
I can say, is I'm usually trying to improve it :-)

Thanks for the reply
Rick


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: 23 Apr 2003 13:37:15 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: OT slightly: mod_perl vs JSP
Message-Id: <3ea6f97b@news.victoria.tc.ca>

Richard Gration (richard@zync.co.uk) wrote:
: Hi All

: I have a biggish (~15000 lines) web application written as cgis, and not
: surprisingly it's suffering from speed issues.

: But my boss has mentioned JSP, so

JSP will not magically solve any problems.

If you do use JSP, then might I suggest you do so as part of a framework 
such as "struts".


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

Date: Wed, 23 Apr 2003 14:00:50 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Perl and ASp
Message-Id: <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: 23 Apr 2003 19:04:36 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl's exec and system use the shell even if the docs say something different (was: Re: Why no viruses on Linux?)
Message-Id: <u965p59jkb.fsf@wcl-l.bham.ac.uk>

Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx> writes:

> Scripsit ille »Brian McCauley« <nobull@mail.com>:
> > Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx> writes:
> > > According to the documentation, the syntax:
> > > 
> > >   exec { "./foobar.sh" } "foobar.sh", "aaa;"
> > > 
> > > should never call the shell.
> > 
> > Can you tell me where this is stated - I can't find it in "perldoc
> > -f exec" in 5.8.0 or 5.6.1.
> 
> (I have 5.8.0)
> 
> > All I can see is a satement that 
> > 
> >  exec { "./foobar.sh" } "foobar.sh", "aaa";
> > 
> > and 
> > 
> >  exec "foobar.sh", "aaa";
> > 
> > both call execvp() directly.
> 
> Yes, and it is tried. It fails because of the missing #! line. Perl
> detects the error ("DWIM") and calls /bin/sh explicitly.

No, Perl does not detect the error, because this is not a error
condition for execvp().  execvp() calls execve() with the program
you've asked it to run and if that fails on ENOEXEC then it tries
again with /bin/sh instead.

> That's nowhere stated in
> 
>   perldoc -f exec

If the behaviour is that of the underlying platform and not Perl then
I would not expect it to be documented in the Perl documentation.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 23 Apr 2003 18:21:47 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Perl's exec and system use the shell even if the docs say something different
Message-Id: <%QApa.23417$J17.17491@twister.nyc.rr.com>

Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx> wrote:
> Scripsit ille »Brian McCauley« <nobull@mail.com>:
>>
>> All I can see is a satement that 
>> 
>>  exec { "./foobar.sh" } "foobar.sh", "aaa";
>> 
>> and 
>> 
>>  exec "foobar.sh", "aaa";
>> 
>> both call execvp() directly.
> 
> Yes, and it is tried. It fails because of the missing #! line. Perl
> detects the error ("DWIM") and calls /bin/sh explicitly.
> 
> That's nowhere stated in
> 
>   perldoc -f exec
> 

It is, however, documented behavior of execvp:

    ~ > man 3 execvp 
       ...

       If the header of a file isn't  recognized  (the  attempted
       execve returned ENOEXEC), these functions will execute the
       shell with the path of the file  as  its  first  argument.
       (If this attempt fails, no further searching is done.)

HTH
-- 
Steve


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

Date: Wed, 23 Apr 2003 22:11:36 +0200
From: Jaap Karssenberg <j.g.karssenberg@student.utwente.nl>
Subject: Re: Perl's exec and system use the shell even if the docs say something different (was: Re: Why no viruses on Linux?)
Message-Id: <20030423221136.2e8b109f.j.g.karssenberg@student.utwente.nl>

: According to the documentation, the syntax:
: 
:   exec { "./foobar.sh" } "foobar.sh", "aaa";
: 
: should never call the shell. However, it does. It isn't as bad as I
: thought because it seems to happen if and only if a file cannot be
: executed because of a missing #! line, but it isn't documented. It
: probably should.

Are you sure it's perl that does this ?

man 3 execvp:

# If the header of a file isn't recognized (the attempted execve #
# returned ENOEXEC), these functions will execute the shell with the
# path  of  the file as its first argument.  (If this attempt fails, no
# further searching is done.)

Also I think POSIX demands this behaviour for shell environments.

-- 
   )   (       Jaap Karssenberg || Pardus [Larus]
   :   :       http://pardus-larus.student.utwente.nl/~pardus 
 )  \ /  (    
 ",.*'*.,"     " You win again, gravity! "


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

Date: Wed, 23 Apr 2003 20:17:16 GMT
From: Joseph Norris <jozefn@bolt.sonic.net>
Subject: POD help - please - first time with pod2html
Message-Id: <Pine.LNX.4.40.0304231314540.19344-100000@bolt.sonic.net>


I am trying to do a simple thing - I thought.

I just want to include some perl code in my pod documentation.
But when I do pod2html the resulting html file shows my perl code
with no indentation and no breaks - just one continuous line.

Can anybody give me a direction to take?

Thanks.


#Joseph Norris (Perl - what else is there?/Linux/CGI/Mysql)
print @c=map chr $_+100,(6,17,15,16,-68,-3,10,11,16,4,1,14,-68,12,1,14,8,
-68,4,-3,-1,7,1,14,-68,-26,11,15,1,12,4,-68,-22,11,14,14,5,15,-90);




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

Date: Wed, 23 Apr 2003 22:57:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: POD help - please - first time with pod2html
Message-Id: <b86utk$6ukft$1@ID-184292.news.dfncis.de>

Joseph Norris wrote:
> I just want to include some perl code in my pod documentation.

<snip>

> Can anybody give me a direction to take?

I can: Follow the instructions in the Pod::Html docs.

/ Gunnar

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



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

Date: Wed, 23 Apr 2003 19:40:31 +0000
From: Mario542 <member17678@dbforums.com>
Subject: Re: print out multi queries
Message-Id: <2799221.1051126831@dbforums.com>


Jue,
I'm trying to run two queries on one perl script.
Here's some of the script.



$statement ="select count (*) from Items where Item_StateID=1
and Item_AvailabilityDate <= GETDATE()
and Item_ExpirationDate > GETDATE()
select count (*) from Items where Item_StateID=1";



$dbh = DBI->connect($dbName, $user, $password) || die "$DBI::errstr";
$cursor = $dbh->prepare($statement) || die "$DBI::errstr";
$cursor->execute ;

--
Posted via http://dbforums.com


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

Date: Wed, 23 Apr 2003 19:46:44 +0000
From: Mario542 <member17678@dbforums.com>
Subject: Re: print out multi queries
Message-Id: <2799223.1051127204@dbforums.com>


Thanks Brian,
the union command worked out perfectly.

Mario

--
Posted via http://dbforums.com


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

Date: 23 Apr 2003 13:53:26 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: print out multi queries
Message-Id: <3ea6fd46@news.victoria.tc.ca>

Mario542 (member17678@dbforums.com) wrote:

: Jue,
: I'm trying to run two queries on one perl script.
: Here's some of the script.



: $statement ="select count (*) from Items where Item_StateID=1
: and Item_AvailabilityDate <= GETDATE()
: and Item_ExpirationDate > GETDATE()
: select count (*) from Items where Item_StateID=1";

You just can't do that.  Split them into two queries.


: $dbh = DBI->connect($dbName, $user, $password) || die "$DBI::errstr";
: $cursor = $dbh->prepare($statement) || die "$DBI::errstr";
: $cursor->execute ;


You need something like


	my $statement1 = "select count (*) 
                          from Items 
                          where Item_StateID=1
                          and Item_AvailabilityDate <= GETDATE()
                          and Item_ExpirationDate > GETDATE()
                         ";

        my $statement2 = "select count (*) 
                          from Items 
                          where Item_StateID=1
                         ";

	my $dbh = DBI->connect($dbName, $user, $p) || die "$DBI::errstr";

	my $cursor = $dbh->prepare( $statement1 ) || die "$DBI::errstr";
	$cursor->execute ;

	my $cursor = $dbh->prepare( $statement2 ) || die "$DBI::errstr";
	$cursor->execute ;

Of course the code above is missing some parts, like getting the data out
of the cursor, and closing the cursor after each statement has finished,
but the DBI documentation has all those details.  The first problem is
just the conceptual issue of how to have multiple queries in your script.



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

Date: 23 Apr 2003 11:44:48 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Re: Read File, write filename?
Message-Id: <90cdce37.0304231044.58518216@posting.google.com>

Thank you all for your attempts to answer my poorly phrased question.

A better way to put it:

I have a directory full of files with various names all ending in
any_name.old. I need to take information from these files, modify it,
and save it in a file named any_name.new. Also, and the hardest part
for me to figure out so far, the first line in any_name.new must be
any_name.

For example if I had a file named blue_forest.old, I'd want the
program to make the first line in blue_forest.new to be blue_forest.

Thanks,
entropy




Garry Short <g4rry_short@zw4llet.com> wrote in message news:<b861ug$sbt$1$8300dec7@news.demon.co.uk>...
> entropy123 wrote:
> 
> > Hey all,
> > 
> > I am a major Perl newbie working through 'Learning Perl' and I can't
> > figure out how to do this:
> > 
> > Have perl read the contents of a file with a *.txt and take the * part
> > of the file and write it to the first line of the new file.
> > 
> > Any suggestions?
> > Thanks,
> > entropy
>  Hmmm ... your question's not brilliantly phrased.
> 1. Where are you getting the filename from in the first place?
> 2. I take it it's the fileNAME you want to write to the file?
> 3. What new file??
> 
> Assuming you're being given a new filename to create, you should have
> something like this :
> 
> #!/usr/bin/perl -w
> 
> # Assume the new filename is defined within the script; define it now.
> my $filename = "rhubarb.txt";
> 
> # Try to open/create the file for writing; end the script and report if 
> # there are errors.
> open NEWFILE, ">$filename" or die "Can't open $filename: $!\n";
> # Remove ".txt" from the filename
> $filename =~ s/\.txt//;
> # Print the filename to the new file
> print NEWFILE "$filename\n";
> # Close the file.
> close NEWFILE;
> 
> HTH,
> 
> Garry


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

Date: Wed, 23 Apr 2003 20:08:39 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: reg expr prl newbie
Message-Id: <pan.2003.04.23.18.08.36.710816@kamelfreund.de>

James Peterson wrote at Wed, 23 Apr 2003 09:54:50 -0700:

> i want to extract the title from a number of html pages and i was told
> i could do this in perl but i am having troubles with it. Basically i
> want to grab whatever lies between <title> and </title> but i always
> seem to get errors when i have </title> in my regular expression
> because (i suppose) perl assumes that / denotes the end of the match.
> Can anyone point me to a correct reg expr that will grab PAGE TITLE
> from <title>PAGE TITLE</title>?

Parsing and extracting data from HTML is on the long not a job for a
regexp, but for a parser. There are a lot of HTML::* CPAN modules solving
such jobs (e.g. HTML::Parser).

However, your problem could be solved,
either with escaping the slash \/

my ($title) = $html =~ /<title>(.*?)<\/title>/is;
                                     ^^

or with choosing other characters than / to surround the re:

my ($title) = $html =~ m,<title>(.*?)</title>,is;
                        ^                    ^


Greetings,
Janek


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

Date: Wed, 23 Apr 2003 20:10:25 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: regular expression question
Message-Id: <pan.2003.04.23.18.10.24.19001@kamelfreund.de>

siva chelliah wrote at Wed, 23 Apr 2003 09:32:20 -0700:

> Hi,
>   The following regular expression:
>  
>          /FRED(.*)\s.*BARNEY\1/
> 
> matches the following string and I thought it should not.
>    
>          FREDyyy something here BARNEYyyyy
> 
> There are four y's at the end. Any ideas?

And there are also three y's at the end what's already enough to match :-)

I could imagine you simply left out to tell Perl
that the match should start at the beginning (^) of the string
and end at its end ($):

/^FRED(.*)\s.*BARNEY\1$/


Greetings,
Janek


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

Date: Wed, 23 Apr 2003 19:07:04 GMT
From: Greg <greg@hassan.com>
Subject: Re: regular expression question
Message-Id: <3EA6E45A.6010206@hassan.com>

siva chelliah wrote:
> Hi,
>   The following regular expression:
>  
>          /^FRED(.*)\s.*BARNEY\1$/
> 
> matches the following string and I thought it should not.
>    


You need to have a start and end, ^$, if
you want it not to match.

-Greg
http://www.supercgis.com/
Super Site Searcher



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

Date: Wed, 23 Apr 2003 12:00:02 -0700
From: Steve May <stevenm@bogus.blackwater-pacific.com>
Subject: Search engine design tips (OT?)
Message-Id: <b86nhj$ddo$1@quark.scn.rain.com>

(sort of perl related)

I've been looking around for documentation on search engine design 
principles and having little luck. So little in fact, that it almost 
seems like some big secret.

Maybe I'm just missing it. Or maybe a couple of goons will be around to 
break my legs for even asking. :-)

Anyway, it would be nice to find information on the basic principles of 
search engines and what is important to think about, performance issues, 
memory issues, and etc....  I don't want the code, I want the thinking 
that goes into writing the code.  I have my own ideas, of course, but 
want something to compare them to.

Note that I'm not planning on trying to take on Google with a Perl 
script, I would just like to know a little more the next time I design a 
text search system using Perl.

Any links, etc greatly appreciated.


s.



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

Date: 23 Apr 2003 19:10:59 GMT
From: Galen Menzel <galenmenzel@yahoo.com>
Subject: Re: Search engine design tips (OT?)
Message-Id: <slrnbadpfn.1qm.galenmenzel@localhost.localdomain>

In article <b86nhj$ddo$1@quark.scn.rain.com>, Steve May wrote:
> 
> <snip>
>
> Anyway, it would be nice to find information on the basic principles of 
> search engines and what is important to think about, performance issues, 
> memory issues, and etc....  I don't want the code, I want the thinking 
> that goes into writing the code.  I have my own ideas, of course, but 
> want something to compare them to.
>
> <snip>
> 

Namazu is a GPLed search engine written mostly in Perl, with a little C:

http://www.namazu.org

Perhaps you could ask one of the Namazu mailing lists for information:

http://www.namazu.org/ml.html

Hope that helps.
galen


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

Date: Wed, 23 Apr 2003 14:14:30 -0500
From: pooba53 <delautenschl@[nospam]wisc.edu>
Subject: Re: Still Stumped
Message-Id: <b86oml$2pt$1@news.doit.wisc.edu>

Regarding the line below:

Can you tell me how I can account for $key if one is "CG3038" and 
another is "CG13038"? The algorithm works as long as one key is not a 
subset of another.

Thanks.
-Dan

pooba53 wrote:
> I figured out using the:
> push ( @{$AllGenes{$gene}}, @range);
> 
> What I then used to get the unique elements was a chunk of code another
> gentleman posted a week or so ago that needed a tad bit of modification:
> 
> while (($key,$aref) = each %AllGenes)  {
>     @unique = grep !$seen{$_}++, map @$_, $aref;
>     $count = @unique;
>     print OUTPUT"$key:$count\n";



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

Date: 23 Apr 2003 11:42:02 -0700
From: brian@box201.com (Agrapha)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <11aabb15.0304231042.104d893f@posting.google.com>

> First off, you'll find the people on this group very helpful if you cut
> and paste perl code into your post. You will find they get progressively
> more unhelpful the less your posting has to do with a _specific_ perl
> problem. In fairness, free systems analysis is hard to come by ;-)

Mind you I appreciate that free analysis is hard to pull from people.
I have also found a rather troubling undercurrent. We are speaking in
an open perl forum. it's not a moderated membership forum. I posted in
a perl area because I respect the capabilities of the language. Some
of the tails are obviously left by people who know less perl than I do
and only post in here to burn others. If I knew more than
#!/usr/bin/env perl I would post it.



> Check out these:
> 
> perldoc perldata
> perldoc perlref
> perldoc -f localtime
> perldoc -f open
> perldoc -f die
> perldoc -f while
> perldoc -f split
> perldoc -f grep
> perldoc -f map	<--- probably not needed, might come in handy
> 


Excellent. Thats what I need here. Just a nudge in the right
direction. I have a book but it's main thrust is web developement.
I'll look up each of these and try a few things. Perl is a huge
language. I needed to know what corridor to begin looking. I don't
want someone to write it for me just help me learn how to write it
myself. Thanks for the references.

> This should be enough to allow you to open the file, read it, isolate the
> fields you're interested in, store them in a suitable data structure
> (maybe an array of array refs?), and then pull out the lines you need
> (grep and map). 

Looking at the arrays now. Is it reasonable to load an array with
100,000 lines (records)? Really I don't know. how would the array
remember the "\n" at the end of each line? I just got a very brief
intro on the array ref's. I don't fully understand those yet.

> Then you should be able to post some code which does most
> of what you need. Then the nice people here will probably jump at the
> chance to point out the subtle mistakes which are breaking your code.

Brilliant, I'll be back after I read up and try a few things from your
list. Thanks for taking a few moments and showing me which way to
start. I know it goes against the grain for some here. Still you gave
me a fighting chance. Thanks again.
 
> PS A few lines of data would have made your shell script miles easier to
> understand :-)

Yes I agree. I siphoned off a log to work with this morning. Let me
piece together the basic frame of opening a file and loading it into a
variable. I'll sanitize a few lines of the logs and post them. The
files are auto-generated so they are nearly always the same. Again
Thanks for resisting the temptation to slam me here. Your note helps a
bunch.

cheers 
bd


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

Date: Wed, 23 Apr 2003 18:43:40 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: brian@box201.com (Agrapha)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <1f083d958a9afae7e773c30dc98ef3a3@TeraNews>

>>>>> "Agrapha" == Agrapha  <brian@box201.com> writes:

Agrapha> First let me say I know nothing about perl. I only know what
Agrapha> I am trying to do can be better served by the perl language
Agrapha> then the way I'm doing it now. I have 3 log files
Agrapha> (proxyD."date") that include a date in the name. Therefore
Agrapha> they change every day. The files are proxy server files. My
Agrapha> shell script works but is inefficient with regards to
Agrapha> processor time. I hit the hard drive 5 times in my 40 line
Agrapha> script. I need to grep once and then awk twice or three
Agrapha> times. Here is my shell script can someone help me convert it
Agrapha> to and efficient perl script?

I think you want <http://jobs.perl.org>.  You can find a contractor
for hire there.  Be sure to mention how much you're willing to pay.

Either that, or <http://learn.perl.org>, which has a list of good
resources for you to learn Perl on your own.

Your choice.  Pay, or learn.

When you actually have a Perl question, perhaps you can post your
in-progress Perl script here, including the question you next face.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 23 Apr 2003 19:24:17 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbadq31.1ig.abigail@alexandra.abigail.nl>

Agrapha (brian@box201.com) wrote on MMMDXXII September MCMXCIII in
<URL:news:11aabb15.0304221750.721fdebb@posting.google.com>:
""  First let me say I know nothing about perl. I only know what I am
""  trying to do can be better served by the perl language then the way
""  I'm doing it now. I have 3 log files (proxyD."date") that include a
""  date in the name. Therefore they change every day. The files are proxy
""  server files. My shell script works but is inefficient with regards to
""  processor time. I hit the hard drive 5 times in my 40 line script. I
""  need to grep once and then awk twice or three times. Here is my shell
""  script can someone help me convert it to and efficient perl script?

There's no reason at all to go through the logfiles more than once,
even if you are using AWK.

Your problem isn't using the wrong language, your problem is using
the wrong algorithm. 

I'll write your program for you, for $150/hour, 4 hour minimum.



Abigail
-- 
               split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_)  {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};


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

Date: 23 Apr 2003 21:03:12 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <b86v2g$dbh$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Agrapha:

>> This should be enough to allow you to open the file, read it, isolate the
>> fields you're interested in, store them in a suitable data structure
>> (maybe an array of array refs?), and then pull out the lines you need
>> (grep and map). 
> 
> Looking at the arrays now. Is it reasonable to load an array with
> 100,000 lines (records)? Really I don't know. 

Not if you can avoid it. Most problems require to look at each line of a
file only once. In such a case you should not slurp a whole file into an
array. Instead, iterate over the file line-wise. Perl makes that quite
easy so it's a common idiom:

    open F, "file" or die $!;
    while (<F>) {
        # each line now in $_ including terminating newline
        ...
    }

> how would the array remember the "\n" at the end of each line? 

Not sure what you mean to ask with the above. Reading a line from a file
handle using the angle operator (<>) gives you the whole line which
includes the linebreak (unless you set $/ to a different record
separator). This is also true if you slurp the file like this:

    my @lines = <F>;

You'll probably be more concerned with getting rid of the terminating
newline. In such a case use chomp(), either on a scalar or on the
complete array:

    chomp;          # equivalent to chomp($_)
    chomp($line);
    chomp(@lines);  # chomp each array element

> I just got a very brief intro on the array ref's. I don't fully
> understand those yet.

You might get away without them, depends on your needs. You most often
will use references when you construct nested data-structures, a
two-dimensional array for instance.

References however are documented quite extensively throughout the
perldocs. Try

    perldoc perlreftut  # tutorial
    perldoc perlref     # the complete reference to, alas, references
    perldoc perldsc     # data structure cookbook
    perldoc perllol     # working with multi-dimensional arrays
    
>> Then you should be able to post some code which does most
>> of what you need. Then the nice people here will probably jump at the
>> chance to point out the subtle mistakes which are breaking your code.
> 
> Brilliant, I'll be back after I read up and try a few things from your
> list. Thanks for taking a few moments and showing me which way to
> start. I know it goes against the grain for some here. Still you gave
> me a fighting chance. Thanks again.

Pointing people to the relevant docs never goes against the grain here.
Your posting suggested that you wanted someone here to write the script
for you. Quite understandably, people are less helpful in such a case.

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: Wed, 23 Apr 2003 18:53:50 GMT
From: Greg <greg@hassan.com>
Subject: Re: webhosts that support perl well?
Message-Id: <3EA6E140.8000808@hassan.com>

 >>I realize this is not a *pure* perl question..... but I'm looking for
 >>some feedback from perl programmers who may have found some reasonable
 >>web hosts that do a good job supporting sites with custom scripts.

You might try fatcow.com or nwrks.net.  I think you
wont get any support for custom perl, unless you pay
for it.  You can certainly install any extra modules
in your sub-dir as needed.


-Greg
http://www.supercgis.com/
Super Site Searcher



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

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


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