Re: regex nth match of string, perl 5.8.5

2006-01-23 Thread Chris Cosner



Bingo! Thanks for the replies.



Just use the non-greedy form of *:

s{(\I\)(.*?)(\I\)}{$1$2\\/I\}g

should do what you want.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: import modules at begin block

2006-01-23 Thread Tom Phoenix
On 1/22/06, Ken Perl [EMAIL PROTECTED] wrote:

 May I import all modules located in a directory called
 '/opt/myperlmodules' in Begin block like this?

What happened when you tried it?

 $myModules = /opt/myperlmodules;
 lib-import($myModules);

I don't think it will work, but maybe you have a different version of
Perl installed on your machine than I have in my brain. :-)

Maybe you're doing something quite unusual, but... It's probably not a
defensible programming technique to use whichever modules are found in
a given directory, for much the same reason that recipes seldom
suggest choosing ingredients by location. Begin with the rightmost
box on the shelf with the breakfast cereal. Next, stir in half of the
largest container on the bottom shelf in the refrigerator. Add a
spoonful of every third spice from the second row of the spice
rack

Modules: Ask for them by name.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Array problem

2006-01-23 Thread Ditlev, Unix Consulting
Is this what you wan't ?

 open INPUT,$ARGV[0];
 while ($line=INPUT){
push (@array,$line);
 }

foreach $i(@array){
print $i;
   }

Andrej Kastrin [EMAIL PROTECTED] skrev i en meddelelse 
news:[EMAIL PROTECTED]
I wrote simple script, which have to concatenate multiple lines into array 
and then print each element of tihis array:

 open INPUT,$ARGV[0];
 while ($line=INPUT){
push (@array,$line);
foreach $i(@array){
print $i;
   }
 }

 Input is e.g.
 line 1
 line 2

 I don't know where is the problem, Please, help!

 Cheers, Andrej 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Want to add exception for a auto run sub in module

2006-01-23 Thread Jimmy
Hi all,

I have a module somewhat looks like this :

  package minicgi;
  require Exporter;  our @ISA = qw/Exporter/;
  our @EXPORT = qw/NormalHeader OtherHeader/;

  sub NornalHeader { print Content-Type:text/html\n\n } # normal html
  sub OtherHeader { print Content-Type:$_[0]\r\n\r\n } # perhaps sending file

   NormalHeader;
  1;


So, when I use minicgi, normal_header() will autorun, however, 
it makes the other_header() meaningless. So my question is, 
is there anyway I'll run normal_header() without specific argument, 
but don't run it if I pass whatever argument on the 'use' statement ?

Thank you very much,
Jim


Re: Want to add exception for a auto run sub in module

2006-01-23 Thread Jimmy
Sorry for typing err for the sub name at the question part =(
normal_header() and other_header() should aling with the
sample code, so is NormalHeader() and OtherHeader().


- Original Message - 
From: Jimmy [EMAIL PROTECTED]
To: Perl Beginners beginners@perl.org
Sent: Monday, January 23, 2006 8:17 PM
Subject: Want to add exception for a auto run sub in module


Hi all,

I have a module somewhat looks like this :

  package minicgi;
  require Exporter;  our @ISA = qw/Exporter/;
  our @EXPORT = qw/NormalHeader OtherHeader/;

  sub NornalHeader { print Content-Type:text/html\n\n } # normal html
  sub OtherHeader { print Content-Type:$_[0]\r\n\r\n } # perhaps sending
file

   NormalHeader;
  1;


So, when I use minicgi, normal_header() will autorun, however,
it makes the other_header() meaningless. So my question is,
is there anyway I'll run normal_header() without specific argument,
but don't run it if I pass whatever argument on the 'use' statement ?

Thank you very much,
Jim



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: import modules at begin block

2006-01-23 Thread Peter Scott
On Sun, 22 Jan 2006 17:39:47 -0800, Tom Phoenix wrote:
 On 1/22/06, Ken Perl [EMAIL PROTECTED] wrote:
 
 May I import all modules located in a directory called
 '/opt/myperlmodules' in Begin block like this?
 
 What happened when you tried it?
 
 $myModules = /opt/myperlmodules;
 lib-import($myModules);
 
 I don't think it will work, but maybe you have a different version of Perl
 installed on your machine than I have in my brain. :-)

What perl do you have installed in your brain?  Do you have a full CPAN?  :-)

 Maybe you're doing something quite unusual, but... It's probably not a
 defensible programming technique to use whichever modules are found in a
 given directory, for much the same reason that recipes seldom suggest
 choosing ingredients by location. Begin with the rightmost box on the
 shelf with the breakfast cereal. Next, stir in half of the largest
 container on the bottom shelf in the refrigerator. Add a spoonful of every
 third spice from the second row of the spice rack
 
 Modules: Ask for them by name.

Maybe I'm missing something, but the poster appears to be asking how to
achieve the common and useful pattern of plugins, where you control
dynamic behavior by deciding what modules are in a particular directory. 
Of course there's a lot more scaffolding than the poster alluded to, but
at some point you do have to load all the modules in a directory.  My
current favorite way is to eval each file one at a time and extract
package directives to push class names onto an array. 

Ken: that won't work.  You need BEGIN blocks, glob(), and a require
followed by a $class-import inside the loop. 

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: import modules at begin block

2006-01-23 Thread Shawn Corey

Peter Scott wrote:

Maybe I'm missing something, but the poster appears to be asking how to
achieve the common and useful pattern of plugins, where you control
dynamic behavior by deciding what modules are in a particular directory. 
Of course there's a lot more scaffolding than the poster alluded to, but

at some point you do have to load all the modules in a directory.  My
current favorite way is to eval each file one at a time and extract
package directives to push class names onto an array. 


Ken: that won't work.  You need BEGIN blocks, glob(), and a require
followed by a $class-import inside the loop. 



Every now and again someone gets the bright idea to load modules 
dynamically. Usually they do this to save time. The correct way to do 
this is to rewrite the modules for AutoLoader. Then you just 'use' 
everything. See `perldoc AutoLoader` for details.



--

Just my 0.0002 million dollars worth,
   --- Shawn

Probability is now one. Any problems that are left are your own.
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is available at http://perldoc.perl.org/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Want to add exception for a auto run sub in module

2006-01-23 Thread Tom Phoenix
On 1/23/06, Jimmy [EMAIL PROTECTED] wrote:

 is there anyway I'll run normal_header() without specific argument,
 but don't run it if I pass whatever argument on the 'use' statement ?

I believe you're asking how a module can determine how it was 'use'd,
so as to provide default behavior when no import list is specified.
The documentation for 'use' in the perlfunc manpage covers the
'import' method, which is called when the import list is not missing;
does that give you what you need? Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




file test

2006-01-23 Thread hien

dear all,

i am trying to check if there are any files named file* (e.g.  
file_001.txt file1.doc) in my directory.


if( -e file* ) { print(true\n); } # this doesn't work
else { print(false\n); }

if( -e m/^file/ ) { print(true\n); } # this doesn't work either
else { print(false\n); }

thank you in advance, any answer would be greatly appreciated.

-H.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: file test

2006-01-23 Thread Chris Devers
On Mon, 23 Jan 2006, hien wrote:

 i am trying to check if there are any files named file* (e.g. 
 file_001.txt file1.doc) in my directory.

perldoc -f glob


-- 
Chris Devers
DO NOT LEAVE IT IS NOT REAL

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response