Process Directory and subdirectories Recursively

2008-01-28 Thread Mimi Cafe
Hi,

I am trying to process a directory and all subdirectory recursively and
generate a list as the Unix command ls -R will display, but this seems not
to behave as it should.
My script only goes as far as processing the directory and the 1 step below
not more.

I have some like, but the script goes as far as 1_child and 2_child but no
further:
/parent/1_child/1_grant_child/././
/parent/2_child/2_grant_child/././

The script will finally be used on Windows OS,  Unix system command cannot
be used.

Can anyone help?

Regards

Mimi

###
#!/usr/bin/perl -w


# Recursively read content of a folder and dynamically create a list on an
html page.

use CGI qw(:standard);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#use warnings;
use strict;



print header(),
 start_html(Documents list);
print h1 Documents List/h1br\n;

my $source = /depot/my_directory;

opendir (SOURCE, $source) or die Cannot open the source folder for reading:
$!\n;

my $file;
while (defined($file = readdir(SOURCE))){
 next if $file =~ /^\.{1,2}$/;
 my $full_name = $source/$file;
 if (-d $full_name){
  #my $full_name = $source/$file;
  print qq(b$file/bbr);
  process($full_name);
 }else{
  print qq(a href=$full_name$file/abr);
 }
 #next;
}
closedir (SOURCE);


print end_html();



# Subroutine to process subdirectory and list content.

sub process{

 my ($path, $file, @files, $file_full_path);
 $path = shift;
 opendir (SUBDIR, $path) or die Cannot open the subfolder for reading:
$!\n;

 @files = sort grep {!/^\.{1,2}$/} readdir(SUBDIR);
 closedir (SUBDIR);

 for (@files){
  $file_full_path = $path/$_;

  if (-d $_){
   print qq(b$_/bbr /);
   process($_);


  }else {

   print qq(a href=$file_full_path$_/abr /);

  }

 }


}
###


Re: Process Directory and subdirectories Recursively

2008-01-28 Thread Sean Davis
On Jan 28, 2008 6:56 AM, Mimi Cafe [EMAIL PROTECTED] wrote:
 Hi,

 I am trying to process a directory and all subdirectory recursively and
 generate a list as the Unix command ls -R will display, but this seems not
 to behave as it should.
 My script only goes as far as processing the directory and the 1 step below
 not more.

 I have some like, but the script goes as far as 1_child and 2_child but no
 further:
 /parent/1_child/1_grant_child/././
 /parent/2_child/2_grant_child/././

 The script will finally be used on Windows OS,  Unix system command cannot
 be used.

 Can anyone help?

I would suggest trying to use a CPAN module for this type of thing.
There may be others, but look at File::Find:

http://search.cpan.org/search%3fmodule=File::Find



 ###
 #!/usr/bin/perl -w


 # Recursively read content of a folder and dynamically create a list on an
 html page.

 use CGI qw(:standard);
 #use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
 #use warnings;
 use strict;



 print header(),
  start_html(Documents list);
 print h1 Documents List/h1br\n;

 my $source = /depot/my_directory;

 opendir (SOURCE, $source) or die Cannot open the source folder for reading:
 $!\n;

 my $file;
 while (defined($file = readdir(SOURCE))){
  next if $file =~ /^\.{1,2}$/;
  my $full_name = $source/$file;
  if (-d $full_name){
   #my $full_name = $source/$file;
   print qq(b$file/bbr);
   process($full_name);
  }else{
   print qq(a href=$full_name$file/abr);
  }
  #next;
 }
 closedir (SOURCE);


 print end_html();



 # Subroutine to process subdirectory and list content.

 sub process{

  my ($path, $file, @files, $file_full_path);
  $path = shift;
  opendir (SUBDIR, $path) or die Cannot open the subfolder for reading:
 $!\n;

  @files = sort grep {!/^\.{1,2}$/} readdir(SUBDIR);
  closedir (SUBDIR);

  for (@files){
   $file_full_path = $path/$_;

   if (-d $_){
print qq(b$_/bbr /);
process($_);


   }else {

print qq(a href=$file_full_path$_/abr /);

   }

  }


 }
 ###


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




Re: Process Directory and subdirectories Recursively

2008-01-28 Thread Gunnar Hjalmarsson

Mimi Cafe wrote:

Hi,

I am trying to process a directory and all subdirectory recursively and


Please do not multi-post!!

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

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




Re: passing array reference from one perl script to another perl scirpt

2008-01-28 Thread praveen mall
I am just putting the code here that might be helpful to others.  Thank you
very much.

Praveen Mall

Program1: (sending hash reference)

use strict;

use warnings;

use Storable;

 my %h = (a = 1, b = 2, c = 3);

 store(\%h, c:\\perlipc.$$)

   or die could not store hash in /tmp/perlipc.$$: $!;

 system(perl, 2.pl, $$) == 0

   or die could not run second.pl;



Program2: (receiving hash reference)

use strict;

use warnings;

use Storable;
my $parentpid = shift;

my $href = retrieve(c:\\perlipc.$parentpid)

   or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;



my %hash = %$href;



foreach my $key(keys %hash){



print $key=$hash{$key}\n;


On Jan 28, 2008 3:00 PM, praveen mall [EMAIL PROTECTED] wrote:

 Thanks a lot for helping me. :)



 On Jan 25, 2008 6:50 PM, Nagrale, Ajay [EMAIL PROTECTED] wrote:

  Passing hashes between the scripts would be useful using GDBM
  files..Hashes would be stored internally. You can directly load and change
  the contents.
 
  It's easy to handle. But, gdbm files have their own disadvantages when
  you keep on adding and deleting the data.
 
  Try this out. This might help.
 
  ~Ajay
 
  -Original Message-
  From: Chas. Owens [mailto:[EMAIL PROTECTED]
  Sent: Friday, January 25, 2008 6:32 PM
  To: praveen mall
  Cc: beginners@perl.org
  Subject: Re: passing array reference from one perl script to another
  perl scirpt
 
 
  On Jan 25, 2008 4:45 AM, praveen mall [EMAIL PROTECTED] wrote:
  snip
   There are two script. From first script I need to call the second
  program
   and in second program I want to receive the hash. I have complete hash
  in
   first program and calling second program by system call by passing
  hash
   reference as a parameter.
  snip
 
  I believe you are placing constraints on yourself that do not actually
  exist, but we will work with them for now.  You need some form of
  IPC*.  The easiest to understand is the simple file method: script one
  writes a file to disk and script two reads that file.  Now that we
  know how to get the two scripts talking, we need to know how to
  transfer a hash along that conduit.  We need to serialize it (turn it
  into a string that contains all of the information we need).  There
  are many functions in Perl that can do this for us and which one is
  best depends on the data structure to be serialized and your other
  needs.  For now, let's us one that is in Core Perl: Storable**.
 
  Here is the first script
  #!/usr/bin/perl
 
  use strict;
  use warnings;
  use Storable;
 
  my %h = (a = 1, b = 2, c = 3);
 
  store(\%h, /tmp/perlipc.$$)
 or die could not store hash in /tmp/perlipc.$$: $!;
 
  system(perl, second.pl, $$) == 0
 or die could not run second.pl;
 
  Here is the second script
  #!/usr/bin/perl
 
  use strict;
  use warnings;
  use Storable;
  use Data::Dumper;
 
  my $parentpid = shift;
  my $href = retrieve(/tmp/perlipc.$parentpid)
 or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;
 
  print Dumper($href);
 
 
  * inter process communication
  ** http://perldoc.perl.org/Storable.html
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/
 
 
 


 --
 Thanks and Regards,
 Praveen Kumar Mall
 Jr. SQA Engineer
 Pune
 Mo. No. 09850982204




-- 
Thanks and Regards,
Praveen Kumar Mall
Jr. SQA Engineer
Pune
Mo. No. 09850982204


Process Directory and subdirectories Recursively

2008-01-28 Thread Mimi Cafe
Hi,

I am trying to process a directory and all subdirectory recursively and
generate a list as the Unix command ls -R will display, but this seems not
to behave as it should.
My script only goes as far as processing the directory and the 1 step below
not more.

I have some like, but the script goes as far as 1_child and 2_child but no
further:
/parent/1_child/1_grant_child/././
/parent/2_child/2_grant_child/././

The script will finally be used on Windows OS,  Unix system command cannot
be used.

Can anyone help?

Regards

Mimi

###
#!/usr/bin/perl -w


# Recursively read content of a folder and dynamically create a list on an
html page.

use CGI qw(:standard);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#use warnings;
use strict;



print header(),
 start_html(Documents list);
print h1 Documents List/h1br\n;

my $source = /depot/my_directory;

opendir (SOURCE, $source) or die Cannot open the source folder for reading:
$!\n;

my $file;
while (defined($file = readdir(SOURCE))){
 next if $file =~ /^\.{1,2}$/;
 my $full_name = $source/$file;
 if (-d $full_name){
  #my $full_name = $source/$file;
  print qq(b$file/bbr);
  process($full_name);
 }else{
  print qq(a href=$full_name$file/abr);
 }
 #next;
}
closedir (SOURCE);


print end_html();



# Subroutine to process subdirectory and list content.

sub process{

 my ($path, $file, @files, $file_full_path);
 $path = shift;
 opendir (SUBDIR, $path) or die Cannot open the subfolder for reading:
$!\n;

 @files = sort grep {!/^\.{1,2}$/} readdir(SUBDIR);
 closedir (SUBDIR);

 for (@files){
  $file_full_path = $path/$_;

  if (-d $_){
   print qq(b$_/bbr /);
   process($_);


  }else {

   print qq(a href=$file_full_path$_/abr /);

  }

 }


}
###


Re: Process Directory and subdirectories Recursively

2008-01-28 Thread Gunnar Hjalmarsson

Mimi Cafe wrote:

I am trying to process a directory and all subdirectory recursively and
generate a list as the Unix command ls -R will display,


snip


The script will finally be used on Windows OS,  Unix system command cannot
be used.


print `dir /B /S`;

If you prefer a portable solution, check out the File::Find module.

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

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




Re: passing array reference from one perl script to another perl scirpt

2008-01-28 Thread praveen mall
Thanks a lot for helping me. :)


On Jan 25, 2008 6:50 PM, Nagrale, Ajay [EMAIL PROTECTED] wrote:

 Passing hashes between the scripts would be useful using GDBM
 files..Hashes would be stored internally. You can directly load and change
 the contents.

 It's easy to handle. But, gdbm files have their own disadvantages when you
 keep on adding and deleting the data.

 Try this out. This might help.

 ~Ajay

 -Original Message-
 From: Chas. Owens [mailto:[EMAIL PROTECTED]
 Sent: Friday, January 25, 2008 6:32 PM
 To: praveen mall
 Cc: beginners@perl.org
 Subject: Re: passing array reference from one perl script to another
 perl scirpt


 On Jan 25, 2008 4:45 AM, praveen mall [EMAIL PROTECTED] wrote:
 snip
  There are two script. From first script I need to call the second
 program
  and in second program I want to receive the hash. I have complete hash
 in
  first program and calling second program by system call by passing hash
  reference as a parameter.
 snip

 I believe you are placing constraints on yourself that do not actually
 exist, but we will work with them for now.  You need some form of
 IPC*.  The easiest to understand is the simple file method: script one
 writes a file to disk and script two reads that file.  Now that we
 know how to get the two scripts talking, we need to know how to
 transfer a hash along that conduit.  We need to serialize it (turn it
 into a string that contains all of the information we need).  There
 are many functions in Perl that can do this for us and which one is
 best depends on the data structure to be serialized and your other
 needs.  For now, let's us one that is in Core Perl: Storable**.

 Here is the first script
 #!/usr/bin/perl

 use strict;
 use warnings;
 use Storable;

 my %h = (a = 1, b = 2, c = 3);

 store(\%h, /tmp/perlipc.$$)
or die could not store hash in /tmp/perlipc.$$: $!;

 system(perl, second.pl, $$) == 0
or die could not run second.pl;

 Here is the second script
 #!/usr/bin/perl

 use strict;
 use warnings;
 use Storable;
 use Data::Dumper;

 my $parentpid = shift;
 my $href = retrieve(/tmp/perlipc.$parentpid)
or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;

 print Dumper($href);


 * inter process communication
 ** http://perldoc.perl.org/Storable.html

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





-- 
Thanks and Regards,
Praveen Kumar Mall
Jr. SQA Engineer
Pune
Mo. No. 09850982204


Re: Want to access Jenda as a PPM repository

2008-01-28 Thread Jeff Pang


-Original Message-
From: axtens [EMAIL PROTECTED]
Sent: Jan 28, 2008 8:32 PM
To: beginners@perl.org
Subject: Want to access Jenda as a PPM repository

Can anyone tell me why Jenda is not available as a repository any
more? I get a redirect and then a forbidden.


Just was not sure, what do you mean?

--
Jeff Pang - [EMAIL PROTECTED]
http://home.arcor.de/jeffpang/

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




RE: Process Directory and subdirectories Recursively

2008-01-28 Thread Nagrale, Ajay
Hi Mimi,

I could think of a replacement of ls -R command of unix in windows. It's dir 
/S.

Recursive function call is a one way to do the same.

You can try File::Find as well: 
http://search.cpan.org/~lbrocard/perl5.005_04/lib/File/Find.pm

Thanks,
Ajay

-Original Message-
From: Mimi Cafe [mailto:[EMAIL PROTECTED]
Sent: Monday, January 28, 2008 5:25 PM
To: beginners@perl.org
Subject: Process Directory and subdirectories Recursively


Hi,

I am trying to process a directory and all subdirectory recursively and
generate a list as the Unix command ls -R will display, but this seems not
to behave as it should.
My script only goes as far as processing the directory and the 1 step below
not more.

I have some like, but the script goes as far as 1_child and 2_child but no
further:
/parent/1_child/1_grant_child/././
/parent/2_child/2_grant_child/././

The script will finally be used on Windows OS,  Unix system command cannot
be used.

Can anyone help?

Regards

Mimi

###
#!/usr/bin/perl -w


# Recursively read content of a folder and dynamically create a list on an
html page.

use CGI qw(:standard);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#use warnings;
use strict;



print header(),
 start_html(Documents list);
print h1 Documents List/h1br\n;

my $source = /depot/my_directory;

opendir (SOURCE, $source) or die Cannot open the source folder for reading:
$!\n;

my $file;
while (defined($file = readdir(SOURCE))){
 next if $file =~ /^\.{1,2}$/;
 my $full_name = $source/$file;
 if (-d $full_name){
  #my $full_name = $source/$file;
  print qq(b$file/bbr);
  process($full_name);
 }else{
  print qq(a href=$full_name$file/abr);
 }
 #next;
}
closedir (SOURCE);


print end_html();



# Subroutine to process subdirectory and list content.

sub process{

 my ($path, $file, @files, $file_full_path);
 $path = shift;
 opendir (SUBDIR, $path) or die Cannot open the subfolder for reading:
$!\n;

 @files = sort grep {!/^\.{1,2}$/} readdir(SUBDIR);
 closedir (SUBDIR);

 for (@files){
  $file_full_path = $path/$_;

  if (-d $_){
   print qq(b$_/bbr /);
   process($_);


  }else {

   print qq(a href=$file_full_path$_/abr /);

  }

 }


}
###

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




Re: Process Directory and subdirectories Recursively

2008-01-28 Thread Gunnar Hjalmarsson

Mimi Cafe wrote:

Hi,

I am trying to process a directory and all subdirectory recursively and


Please do not multi-post!!

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

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




Re: How to read an rfc spec

2008-01-28 Thread 2apart
On Jan 27, 7:21 pm, [EMAIL PROTECTED] (Gunnar Hjalmarsson) wrote:
 2apart wrote:

  Subject: How to read an rfc spec

 What has your question to do with Perl?

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

What does yours?  ;-)


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




Re: How to read an rfc spec

2008-01-28 Thread Tom Phoenix
On Jan 28, 2008 7:53 AM, 2apart [EMAIL PROTECTED] wrote:

 You guys just love to scold...

Nobody scolded you because of the love of scolding; don't pretend otherwise.

Keeping a forum on-topic is everyone's duty. Answers will be faster
and more reliable when the questions are posted to the correct forum.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: How to read an rfc spec

2008-01-28 Thread 2apart

 This question is both irrelevant to the Perl language and very lazy.
 RFC2822 is a specification for Internet text messages, and itself

You guys just love to scold... guys?  Are you female?  :-)

 1.2.2. Syntactic notation

 This standard uses the Augmented Backus-Naur Form (ABNF) notation
 specified in [RFC2234] for the formal definitions of the syntax of
 messages.

 Rob

Yes, I read that.  I was just hoping someone might translate a line or
two gratis.
Forgot I was in a perl group. Thanks for the advice.



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




Re: How to read an rfc spec

2008-01-28 Thread Dr.Ruud
2apart schreef:

 Here's a little section from rfc 2822.  I know what the nemonics stand
 for, but
 I'm not sure how to read the spec

Look at the end of http://www.perlmonks.org/?node_id=603647

-- 
Affijn, Ruud

Gewoon is een tijger.


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




Want to access Jenda as a PPM repository

2008-01-28 Thread axtens
Can anyone tell me why Jenda is not available as a repository any
more? I get a redirect and then a forbidden.

Kind regards,
Bruce.


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




Re: Looking for regex

2008-01-28 Thread obdulio santana
I offer you a solution and my comments

why use hash of 24 elements?

using a hash may brings some problem because if  file is the joined day+day
you finally get a file corresponding for example a month (I use these kind
of reports of automatic station)
you can face this situation



2007-01-23 00:01:00,43.3,34.9,30.14,North,359,7,8,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 00:06:00,43.2,34.8,30.14,North,354,11,11,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 00:12:00,43.2,34.8,30.14,North,1,6,9,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:11:00,42.9,34.8,30.13,North,1,5,6,73,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:17:00,42.9,34.8,30.12,NNW,346,3,7,73,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:23:00,43.1,35.0,30.12,North,359,5,11,73,0.00,,,0.00,Wunderground
v.1.13,
 2007-01-23 02:14:00,43.2,34.1,30.10,North,0,16,16,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 02:19:00,43.2,34.1,30.09,North,0,6,13,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 02:24:00,43.2,33.7,30.09,North,349,8,14,69,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 23:04:00,43.2,34.1,30.11,North,0,7,12,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 23:09:00,43.2,34.1,30.11,North,0,10,17,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-24 00:01:00,43.3,34.9,30.14,North,359,7,8,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-24 00:06:00,43.2,34.8,30.14,North,354,11,11,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-24 00:12:00,43.2,34.8,30.14,North,1,6,9,72,0.00,,,0.00,Wunderground
v.1.13,

in the 7th line  it is a  extra white space,  because  this word is not
perfect (noise, or lack of data)

then you find a 00: hour after 23 but we using hash met a problem, thereby I
offer you

perl -lne ($h=$1,print) if (/ (..):/  $h ne $1)  datos.txt

the result is

2007-01-23 00:01:00,43.3,34.9,30.14,North,359,7,8,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:11:00,42.9,34.8,30.13,North,1,5,6,73,0.00,,,0.00,Wunderground
v.1.13,
 2007-01-23 02:14:00,43.2,34.1,30.10,North,0,16,16,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 23:04:00,43.2,34.1,30.11,North,0,7,12,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-24 00:01:00,43.3,34.9,30.14,North,359,7,8,72,0.00,,,0.00,Wunderground
v.1.13,


maybe it helps

regards


file.db VS filedb

2008-01-28 Thread MK

when i use DB_File the files produced lack a dot in their title, eg.

dbmopen %email, email.db, 0666;

manipulates a file who's directory entry is actually emaildb

MORE IMPORTANTLY, perl will not access a database outside of the same  
directory as the script -- it pulls a blank hash.  without being able  
to include any functional path in the filenames, i can't even call the  
script with a soft link...i have to use a shell script to cd first


that is ridiculous and i presume a bug that may have been fixed  
somewhere?


perl 5.8.8 on fedora 7

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




Re: file.db VS filedb

2008-01-28 Thread Gunnar Hjalmarsson

MK wrote:

when i use DB_File the files produced lack a dot in their title, eg.

dbmopen %email, email.db, 0666;

manipulates a file who's directory entry is actually emaildb


Please enable strictures and warnings!!

$ cat test.pl
#!/usr/bin/perl
use strict;
use warnings;
use DB_File;
dbmopen my %email, email.db, 0666;

$ ./test.pl
Bareword email not allowed while strict subs in use at ./test.pl line 5.
Bareword db not allowed while strict subs in use at ./test.pl line 5.
Execution of ./test.pl aborted due to compilation errors.
$

MORE IMPORTANTLY, perl will not access a database outside of the same 
directory as the script -- it pulls a blank hash.  without being able to 
include any functional path in the filenames, i can't even call the 
script with a soft link...i have to use a shell script to cd first


that is ridiculous and i presume a bug that may have been fixed somewhere?


Talking about a bug, based on that reasoning, _that_ is ridiculous.

Of course Perl will access a database in some other directory, if you 
state the correct path to that directory.


dbmopen my %email, '/path/to/email.db', 0644
  or die $!;

As a side note, there is a chdir() function in Perl.

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

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




Re: file.db VS filedb

2008-01-28 Thread John W. Krahn

MK wrote:

when i use DB_File the files produced lack a dot in their title, eg.

dbmopen %email, email.db, 0666;

manipulates a file who's directory entry is actually emaildb

MORE IMPORTANTLY, perl will not access a database outside of the same 
directory as the script -- it pulls a blank hash.  without being able to 
include any functional path in the filenames, i can't even call the 
script with a soft link...i have to use a shell script to cd first


that is ridiculous and i presume a bug that may have been fixed somewhere?

perl 5.8.8 on fedora 7


Put these two lines at the top of your program:

use warnings;
use strict;

And perl will tell you that you are concatenating two barewords.

email.db is tranlated by perl as 'email' . 'db' and there is no dot in 
the concatenation of those two strings.




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: file.db VS filedb

2008-01-28 Thread Jenda Krynicky
From: MK [EMAIL PROTECTED]
 when i use DB_File the files produced lack a dot in their title, eg.
 
 dbmopen %email, email.db, 0666;
 
 manipulates a file who's directory entry is actually emaildb

If you do

   use strict;
   use warnings;

as you should it does not. It reports an error. And apparently 
rightly so.

 MORE IMPORTANTLY, perl will not access a database outside of the same  
 directory as the script -- it pulls a blank hash.  without being able  
 to include any functional path in the filenames, i can't even call the  
 script with a soft link...i have to use a shell script to cd first
 
 that is ridiculous and i presume a bug that may have been fixed  
 somewhere?

If you want to include a string literal in your script enclose it in 
quotes. In this case it doesn't matter whether you use single or 
double quotes:


  dbmopen %email, 'email.db', 0666;

or

  dbmopen %email, email.db, 0666;

What happened was that Perl assumed that you want to join (the dot 
operator) two unquoted words ... without 'use strict' you are allowed 
to omit quotes around words like this:

  $variable = Hello;

but you should NEVER EVER do that. The catch is that there is no 
telling whether that should assign to the $variable the string 
Hello or the results of calling the Hello subroutine. What it does 
depends on the existence of such subroutine.


The next problem is that 
  use DB_File;
and
   dbmopen ...
are not related at all. There is an old interface to one (hard to say 
which) DBM file format via the builtin dbmopen function and there are 
several different modules for different formats of on-disk-hashes 
with their own interfaces. If you read the documentation of DB_File, 
you could see that the way to tie a hash to a DB_File compatible file 
is definitely not dbmopen().

Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: creating multiple variables in loop

2008-01-28 Thread Sonal Singhal
Thank you for your help! The Perl documents and mini-programs were great.

Cheers,
Sonal

On Jan 24, 2008 9:25 PM, Sonal Singhal [EMAIL PROTECTED] wrote:

 So, what I want to do is go through an existing array and break the array
 into mini-arrays at any certain points (where the diff. in two bordering
 values are greater than 2000).  I programmed it as a recursive function, but
 I need to store all these mini-arrays and be able to sort them easily by
 mini-array.  The problem with the array of arrays is I cannot get it to
 treat each row as an array.  Maybe if you can help me there...

 Also, if I am dynamically allocating my array of arrays, how can I find
 out later my index values?

 Thanks for the advice thus far.


 On Jan 23, 2008 6:21 PM, Jenda Krynicky  [EMAIL PROTECTED] wrote:

  From:   Sonal Singhal  [EMAIL PROTECTED]
   Simple question, I hope... I am looping through a set of commands, and
  each
   time, I want to create a unique array with a tag representing the loop
 
   number.
  
   for (my $j = 1; $j  $#start_points; $j++){
   if ( abs($start_points[0] - $start_points[$j])  1999) {
   my @{start_points.$n} =
  @start_points[$j...$#start_points];
   my @{end_points.$n} = @end_points[$j...$#start_points];
   }
   }
  
   I would hope this would give me 'n' arrays: @start_points0,
  @start_points1,
   etc.  But this isn't working.
   ERROR MESSAGE: Can't declare array dereference in my at
   /Users/s/Desktop/shorttest.pl line 17, near } =
  
   I know I can do an array of arrays but that doesn't work well for the
  rest
   of my program.
 
  You never want to have a row of variables like this. NEVER. Show us
  what doesn't work well with an array of arrays.
 
  Jenda
  = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
  When it comes to wine, women and song, wizards are allowed
  to get drunk and croon as much as they like.
 -- Terry Pratchett in Sourcery
 
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/
 
 
 



print records that match regexp

2008-01-28 Thread bbrecht56
I have a table customer_table with the following fields:

Id int,
firstname varchar(64),
lastname varchar(64),
emailaddress varchar(64) not null primary key
city varchar (32),

Can some one help me and show me how to print only records that
matches a given regexp using, for example if I run:

# getRecord.pl  A+

should return all record from the database if the first name, last
name, or email address starts with a capital A

OR:

# getRecord.pl

should return all records from the table, which I have it this way and
it works just fine:

use DBI;

my $dataBaseDriver  =   DBI:mysql;
my $dataBaseName=   test;
my $dataBaseUser=   user;
my $dbUserPass  =   user1234;
my $tableName   =   my_table;

#---#
# connect to the database  #
#---#

my $dbh = DBI-connect($dataBaseDriver:$dataBaseName,
$dataBaseUser,
$dbUserPass,
  { RaiseError = 1,
AutoCommit = 0 }) || die ERROR-1: Couldn't
connect to $dataBaseHost:  . DBI-errstr();
print Connection to the database successful.\n;

#---#
# querying the database  #
#---#
my $sth = $dbh-prepare(SELECT * FROM $tableName);
$sth-execute();

#---#
# print the data   #
#---#
while(my $ref = $sth-fetchrow_hashref()) {
print ID:   $ref-{'Id'}\n;
print First Name:  $ref-{'firstname'}\n;
print Last Name:  $ref-{'lastname'}\n;
print Email Address: $ref-{'emailaddress'}\n;
print City:$ref-{'city'}\n;
}
$sth-finish();
$dbh - disconnect();


Thanks for your help

Berti


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




Re: file.db VS filedb

2008-01-28 Thread Gunnar Hjalmarsson

Jenda Krynicky wrote:
The next problem is that 
  use DB_File;

and
   dbmopen ...
are not related at all.


Why not? If you read perldoc dbmopen, you even find an example call of 
dbmopen() preceeded by use DB_File.


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

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




Re: file.db VS filedb

2008-01-28 Thread Gunnar Hjalmarsson

Gunnar Hjalmarsson wrote:


Why not? If you read perldoc dbmopen, ...


I meant perldoc -f dbmopen.

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

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




Re: How to read an rfc spec

2008-01-28 Thread asmith9983

Hi everyone
It cost nothing to be polite and only a few seconds to be helpful. I was 
myself looking at RFC822 a few days ago to try to figure out what headers 
should be in an 
email message I bounce with my Perl re-wtite script from a procmail recipe. 
Secret formats and being generally unhelpful are a M$ trait, not to be cloned.

--
Andrew in Edinburgh,Scotland.

On Mon, 28 Jan 2008, 2apart wrote:




This question is both irrelevant to the Perl language and very lazy.
RFC2822 is a specification for Internet text messages, and itself


You guys just love to scold... guys?  Are you female?  :-)


1.2.2. Syntactic notation

This standard uses the Augmented Backus-Naur Form (ABNF) notation
specified in [RFC2234] for the formal definitions of the syntax of
messages.

Rob


Yes, I read that.  I was just hoping someone might translate a line or
two gratis.
Forgot I was in a perl group. Thanks for the advice.






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




How to match a token not be quoted?

2008-01-28 Thread Zhao, Bingfeng
Hello,
I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc that
not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.
What should I write my regex? I try some and referred cook book also, no
solution. Thanks in advance.


Best regards, 
Bingfeng 





Re: print records that match regexp

2008-01-28 Thread Chas. Owens
On Jan 28, 2008 4:12 PM,  [EMAIL PROTECTED] wrote:
 I have a table customer_table with the following fields:

 Id int,
 firstname varchar(64),
 lastname varchar(64),
 emailaddress varchar(64) not null primary key
 city varchar (32),

 Can some one help me and show me how to print only records that
 matches a given regexp using, for example if I run:

 # getRecord.pl  A+

 should return all record from the database if the first name, last
 name, or email address starts with a capital A

 OR:

 # getRecord.pl

 should return all records from the table, which I have it this way and
 it works just fine:
snip

This really isn't a job for a regex.  It is a job for a where clause.
Also, if the user where to pass A+ it would match any record whose
fields had one or more contiguous As, not records that have fields
that start with A.  That match would be ^A.  This further points to
the fact that you want the SQL operator LIKE (which does behave the
way you expect it to, but uses % instead of +).

snip
 my $sth = $dbh-prepare(SELECT * FROM $tableName);
snip

my $arg = shift;
my $where_clause = ;
if ($arg) {
#handle meta characters, match uses % for one or more characters,
* for 0 or more, _ for any character
$arg =~ s/\+/%/g;
$arg =~ s/\?/_/g;
#try to handle SQL injection attacks, users should not be able to
break out of the string
#FIXME: this may not be a complete solution, it also probably
breaks character classes like [']
$arg =~ s/'/\\'/;
$where_clause = where firstname like $arg or lastname like $arg
or email like $arg;
}

my $sth = $dbh-prepare(SELECT * from $tableName $where_clause);

By the way, comments are there to explain why you are doing something,
not to tell us what you are doing.  Comments like #print the data
are useless.  I can see that you are printing the data, why are you
printing it now?, what are you trying to achieve by printing it?

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




Database persistnce with Perl

2008-01-28 Thread Murali
Hi,

How do I maintain a persistent database connection for my perl
scripts?

I own a lot of perl libraries that let the users calling them to go to
a database and query it.
Is there a way I can write a handler routine so I don't need to open a
connection for every user.?

The database in question is Oracle 10g, and the operating system is
Solaris 10 and perl we are using is 5.8.6

Thanks,

-Murali


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




Re: How to match a token not be quoted?

2008-01-28 Thread Gunnar Hjalmarsson

Zhao, Bingfeng wrote:

I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc that
not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.


$line =~ s/([^]*)|abc/$1 ? $1 : 'd'/eg;

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

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




Re: How to match a token not be quoted?

2008-01-28 Thread Chas. Owens
On Jan 28, 2008 9:09 PM, Zhao, Bingfeng [EMAIL PROTECTED] wrote:
 Hello,
 I want to a cure regex that match following requirements: given $line =
 'abc abc abc abcc abcc', I want to replace all instances of abc that
 not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.
 What should I write my regex? I try some and referred cook book also, no
 solution. Thanks in advance.
snip

While this can be done, it is often easier to understand the following code

#!/usr/bin/perl

use strict;
use warnings;

my $string = 'abc abc abc abcc abcc';

my @tokens = split /()/, $string;
my $in_string = 0;
for my $token (@tokens) {
$in_string = not $in_string if $token =~ //;
next if $in_string;
$token =~ s/abc/d/g;
}
$string = join , @tokens;

print $string\n;

If you really need to do it with a regex then I would consult perldoc
-q balanced and
http://perldoc.perl.org/perlfaq6.html#Can-I-use-Perl-regular-expressions-to-match-balanced-text?

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




Re: How to match a token not be quoted?

2008-01-28 Thread Rob Dixon

Zhao, Bingfeng wrote:

Hello,
I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc that
not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.
What should I write my regex? I try some and referred cook book also, no
solution. Thanks in advance.


The program below does what you require.

HTH,

Rob


use strict;
use warnings;

my $str = 'abc abc abc abcc abcc';

my @str = split /([^]*?)/, $str;

for (my $i = 0; $i  @str; $i += 2) {
  $str[$i] =~ s/abc/d/g;
}

$str = join '', @str;

print $str, \n;

**OUTPUT**

d d abc abcc dc

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




Re: How to match a token not be quoted?

2008-01-28 Thread Rob Dixon

Gunnar Hjalmarsson wrote:

Zhao, Bingfeng wrote:

I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc that
not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.


$line =~ s/([^]*)|abc/$1 ? $1 : 'd'/eg;


You need a non-greedy modifier on that Gunnar:

  $line =~ s/([^]*?)|abc/$1 ? $1 : 'd'/eg;

Rob


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




Re: How to match a token not be quoted?

2008-01-28 Thread 亂世貓熊

Rob Dixon wrote:

Gunnar Hjalmarsson wrote:

Zhao, Bingfeng wrote:

I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc 
that

not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.


$line =~ s/([^]*)|abc/$1 ? $1 : 'd'/eg;


You need a non-greedy modifier on that Gunnar:

  $line =~ s/([^]*?)|abc/$1 ? $1 : 'd'/eg;

Rob



What if :  ([^]+) ? Is that any danger ?




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




Re: How to match a token not be quoted?

2008-01-28 Thread John W. Krahn

Zhao, Bingfeng wrote:

Hello,


Hello,


I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc that
not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.
What should I write my regex? I try some and referred cook book also, no
solution. Thanks in advance.


$ perl -le'
my $line = q[abc abc abc abcc abcc];
print $line;
$line =~ s/ (  [^]*  ) | abc / $1 || d /xeg;
print $line;
'
abc abc abc abcc abcc
d d abc abcc dc




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




How to avoid this greedy match?

2008-01-28 Thread News Howardz
Hi,

I have a trouble when composing a regex.

$str = ...scirptxxx/scriptzzzscriptyyy/script...

In the above string, xxx and yyy, zzz stand for any substring other than 
script

I want to pick up scriptyyy/script, but each time I get the 2 script 
sections matched scirptxxx/scriptzzzscriptyyy/script.

I've tried the following regex:
1) script.*/script
2) script.*?/script

How can I avoid the this greedy match?
(I'm using ActivePerl 5.6.1)

Thanks,
Howardz


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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




Re: How to avoid this greedy match?

2008-01-28 Thread News Howardz
Sorry, I make a mistake in the mail below:

$str = ...scriptxxx/scriptzzzscripty%%%yy/script...;

I want to match the script section containing %%%.
So I wrote regex like this:

/(script.*?%%%.*?\/script)/

But it doesn't work.
It still selects the 2 script sections: 
scriptxxx/scriptzzzscripty%%%yy/script.

Does anyone have an idea how to achieve this?

Thanks
Howardz

- Original Message 
From: News Howardz [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Tuesday, January 29, 2008 11:22:41 AM
Subject: How to avoid this greedy match?

Hi,

I have a trouble when composing a regex.

$str = ...scirptxxx/scriptzzzscriptyyy/script...

In the above string, xxx and yyy, zzz stand for any substring other than 
script

I want to pick up scriptyyy/script, but each time I get the 2 script 
sections matched scirptxxx/scriptzzzscriptyyy/script.

I've tried the following regex:
1) script.*/script
2) script.*?/script

How can I avoid the this greedy match?
(I'm using ActivePerl 5.6.1)

Thanks,
Howardz


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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




Re: How to avoid this greedy match?

2008-01-28 Thread News Howardz
The original mail is regarded as a SPAM by Yahoo -- poor regex match :-(.
So I modify the following content and resend it.

Sorry, I make a mistake in the mail below:

$str = ...scriptxxx/scriptzzzscripty222yy/script...;

I want to match the script section containing 222.
So I wrote regex like this:

/(script.*?222.*?\/script)/

But it doesn't work.
It still selects the 2 script sections: 
scriptxxx/scriptzzzscripty222yy/script.

Does anyone have an idea how to achieve this?

Thanks
Howardz

- Original Message 
From: News Howardz [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Tuesday, January 29, 2008 11:22:41 AM
Subject: How to avoid this greedy match?

Hi,

I have a trouble when composing a regex.

$str = ...scirptxxx/scriptzzzscriptyyy/script...

In the above string, xxx and yyy, zzz stand for any substring other than 
script

I want to pick up scriptyyy/script, but each time I get the 2 script 
sections matched scirptxxx/scriptzzzscriptyyy/script.

I've tried the following regex:
1) script.*/script
2) script.*?/script

How can I avoid the this greedy match?
(I'm using ActivePerl 5.6.1)

Thanks,
Howardz


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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




RE: How to avoid this greedy match?

2008-01-28 Thread Nagrale, Ajay
Try out the following regular expression:

perl -e '$str = ...script442226/scriptzzzscript222/script...;print 
1=$1\n if ($str =~ /.+script(.*222.*)\/script/);'

The regeular expression is: .+script(.*222.*)\/script

This might give a strange results if you have multiple '222' in the input 
string. Regex will always pick up the last occurance of '222'.

~Ajay

-Original Message-
From: News Howardz [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 29, 2008 9:36 AM
To: beginners@perl.org
Subject: Re: How to avoid this greedy match?


The original mail is regarded as a SPAM by Yahoo -- poor regex match :-(.
So I modify the following content and resend it.

Sorry, I make a mistake in the mail below:

$str = ...scriptxxx/scriptzzzscripty222yy/script...;

I want to match the script section containing 222.
So I wrote regex like this:

/(script.*?222.*?\/script)/

But it doesn't work.
It still selects the 2 script sections: 
scriptxxx/scriptzzzscripty222yy/script.

Does anyone have an idea how to achieve this?

Thanks
Howardz

- Original Message 
From: News Howardz [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Tuesday, January 29, 2008 11:22:41 AM
Subject: How to avoid this greedy match?

Hi,

I have a trouble when composing a regex.

$str = ...scirptxxx/scriptzzzscriptyyy/script...

In the above string, xxx and yyy, zzz stand for any substring other than 
script

I want to pick up scriptyyy/script, but each time I get the 2 script 
sections matched scirptxxx/scriptzzzscriptyyy/script.

I've tried the following regex:
1) script.*/script
2) script.*?/script

How can I avoid the this greedy match?
(I'm using ActivePerl 5.6.1)

Thanks,
Howardz


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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



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




RE: How to match a token not be quoted?

2008-01-28 Thread Zhao, Bingfeng
Thanks for all replies here and your valuable help last time:)

 -Original Message-
 From: John W. Krahn [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, January 29, 2008 11:11 AM
 To: Perl Beginners
 Subject: Re: How to match a token not be quoted?
 
snip 


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




Re: How to match a token not be quoted?

2008-01-28 Thread Gunnar Hjalmarsson

Rob Dixon wrote:

Gunnar Hjalmarsson wrote:

Zhao, Bingfeng wrote:

I want to a cure regex that match following requirements: given $line =
'abc abc abc abcc abcc', I want to replace all instances of abc that
not in quotation with, say 'd', so I expect I get 'd d abc abcc dc'.


$line =~ s/([^]*)|abc/$1 ? $1 : 'd'/eg;


You need a non-greedy modifier on that Gunnar:

  $line =~ s/([^]*?)|abc/$1 ? $1 : 'd'/eg;


Why would I need that? Are you mixing up [^]* with .* ?

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

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




Re: file.db VS filedb

2008-01-28 Thread MK
you know gunnar i would swear on my mothers grave that i tried using  
both  and '' in this and it still would not work, otherwise i really  
really really would not have cried wolf...but in all honesty it does  
work now, so there's egg on my face


however, my connection of dbmopen with DB_File is straight out of  
the 1st Perl Cookbook, but tie from the DB_File man doesn't seem much  
different, nb. they both produce


Global symbol %email requires explicit package name at  
/usr/local/bin/AddressBook line 6.


even with
tie %email, DB_File, 'email.db';

as long as use warnings/use strict is enabled (otherwise it's fine).

To anyone's knowledge is there somewhere/one who has connected these  
strict warning messages to specific meanings in context? (they would  
seem very useful if that is the case, otherwise i cannot imagine what  
requires explicit package name could mean beyond the supplied  
DB_File)


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




Re: How to avoid this greedy match?

2008-01-28 Thread yitzle
I'm not sure how it works, but I think  or \\ is a RegEx reserved
character for word matching.
Aside from that, consider using [^]* and [^]* in place of .*

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




Re: file.db VS filedb

2008-01-28 Thread Gunnar Hjalmarsson

MK wrote:
you know gunnar i would swear on my mothers grave that i tried using 
both  and '' in this and it still would not work, otherwise i really 
really really would not have cried wolf...but in all honesty it does 
work now, so there's egg on my face


Okay... ;-)

however, my connection of dbmopen with DB_File is straight out of 
the 1st Perl Cookbook, but tie from the DB_File man doesn't seem much 
different, nb. they both produce


Global symbol %email requires explicit package name at 
/usr/local/bin/AddressBook line 6.


even with
tie %email, DB_File, 'email.db';

as long as use warnings/use strict is enabled (otherwise it's fine).


use strict; means that variables should be declared, so

tie my %email, DB_File, 'email.db';
^^

To anyone's knowledge is there somewhere/one who has connected these 
strict warning messages to specific meanings in context? (they would 
seem very useful if that is the case, otherwise i cannot imagine what 
requires explicit package name could mean beyond the supplied DB_File)


Literally it suggests this:

tie %main::email, DB_File, 'email.db';
-^^
It's not the best worded error message in Perl...

Suggested reading: http://perl.plover.com/FAQs/Namespaces.html

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

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




RE: How to avoid this greedy match?

2008-01-28 Thread Nagrale, Ajay
Hi,

I don't think '' or '' are meta characters in regular expression match.

 is reserved for opening the files given at command line argument.

Aside from that, consider using [^]* and [^]* in place of .*
If we use [^]* and [^]*, regular expression will fail to match pattern like 
scriptxxx/scriptzzzscript222/script [Pattern having angular 
brackets beside 222.

As we don't know what can precede or succeed '222', it's better we don't give 
any restriction in the regular expression.

~Ajay

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of yitzle
Sent: Tuesday, January 29, 2008 11:53 AM
To: Nagrale, Ajay
Cc: News Howardz; beginners@perl.org
Subject: Re: How to avoid this greedy match?


I'm not sure how it works, but I think  or \\ is a RegEx reserved
character for word matching.
Aside from that, consider using [^]* and [^]* in place of .*

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