useragent to support javascript

2008-02-01 Thread J. Peng
Hello,

I wrote a script using WWW::Mechanize, when I run it I got bad
results, it said my browser has no javascript supported.
Do you know how to fake the header declaring my useranget has enabled
javascript?
Thanks!

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




WWW::Mechanize's JS plugin

2008-02-01 Thread J. Peng
I found this module on cpan:

http://search.cpan.org/~sprout/WWW-Mechanize-Plugin-JavaScript-0.002/lib/WWW/Mechanize/Plugin/JavaScript.pm#PREREQUISITES

But it says,

To load the plugin, just use WWW::Mechanize's use_plugin method (note
that the current stable release of that module doesn't support
this;..)

oops since the original module doesn't support this method, how will
the plugin author think to develop that a module?
If I really want WWW::Mechanize to support Javascript, how to do it?

(I'm running Perl 5.8.8 and latest version of WWW::Mechanize).

Thanks.

//Jeff

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




Re: Can't locate CPAN.pm in @INC

2008-02-01 Thread Pradeep Mishra
thanks adrano.
you are correct. have installed perl-cpan. it is resolved now.

thanks again,



On Feb 1, 2008 8:17 AM, Adriano Ferreira [EMAIL PROTECTED] wrote:

 On Feb 1, 2008 10:47 AM, Pradeep Mishra [EMAIL PROTECTED]
 wrote:
  hi all
 
  I have been trying to install spamassin using ...perl -MCPAN -e shell
  which throws an error
 
  Can't locate CPAN.pm in @INC (@INC contains:
  /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7
  /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5
  /usr/lib/perl5/site_perl
  /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7
  /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
  /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi
  /usr/lib/perl5/5.8.8 .).
  BEGIN failed--compilation aborted.
  [EMAIL PROTECTED] ~]#
 
 
  Tried to search for CPAN.pm but is not found.
 
  perl version is
  [EMAIL PROTECTED] ~]# perl -v
 
  This is perl, v5.8.8 built for i386-linux-thread-multi
 
 
  packages installed
  [EMAIL PROTECTED] ~]# rpm -qa | grep perl
  perl-devel-5.8.8-32.fc8
  perl-libs-5.8.8-32.fc8
  perl-String-CRC32-1.4-3.fc8
  perl-5.8.8-32.fc8
  perl-ExtUtils-MakeMaker-6.30-32.fc8
  groff-perl-1.18.1.4-10.fc8
  perl-DBI-1.58-2.fc8
  perl-Test-Harness-2.56-32.fc8
  perl-DBD-MySQL-4.005-2.fc8.1
  perl-ExtUtils-Embed-1.26-32.fc8
  [EMAIL PROTECTED] ~]#
 
 
 
  Would appreciate if some one can help me solve this issue.

 It looks like you need to install a rpm package which should probably
 be named perl-CPAN or something like that. Your current system does
 not have CPAN installed or have used some weird path perl is not
 looking at.

 
  Thanks in advance.
 
  Regards
 
 
 
 
  --
  Good Judgement comes from Experience and Experience comes from bad
  Judgement!!
  The more I know, the more I realize I don't know!?
  The easiest way to find out is to try it!!!
 




-- 
Good Judgement comes from Experience and Experience comes from bad
Judgement!!
The more I know, the more I realize I don't know!?
The easiest way to find out is to try it!!!


Can't locate CPAN.pm in @INC

2008-02-01 Thread Pradeep Mishra
hi all

I have been trying to install spamassin using ...perl -MCPAN -e shell
which throws an error

Can't locate CPAN.pm in @INC (@INC contains:
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7
/usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8 .).
BEGIN failed--compilation aborted.
[EMAIL PROTECTED] ~]#


Tried to search for CPAN.pm but is not found.

perl version is
[EMAIL PROTECTED] ~]# perl -v

This is perl, v5.8.8 built for i386-linux-thread-multi


packages installed
[EMAIL PROTECTED] ~]# rpm -qa | grep perl
perl-devel-5.8.8-32.fc8
perl-libs-5.8.8-32.fc8
perl-String-CRC32-1.4-3.fc8
perl-5.8.8-32.fc8
perl-ExtUtils-MakeMaker-6.30-32.fc8
groff-perl-1.18.1.4-10.fc8
perl-DBI-1.58-2.fc8
perl-Test-Harness-2.56-32.fc8
perl-DBD-MySQL-4.005-2.fc8.1
perl-ExtUtils-Embed-1.26-32.fc8
[EMAIL PROTECTED] ~]#



Would appreciate if some one can help me solve this issue.


Thanks in advance.

Regards




-- 
Good Judgement comes from Experience and Experience comes from bad
Judgement!!
The more I know, the more I realize I don't know!?
The easiest way to find out is to try it!!!


RE: IO::Compress::Gzip creates empty file

2008-02-01 Thread RICHARD FERNANDEZ
 If you've just written the file, have you closed the 
 filehandle and checked the return value?
 
 Paul Johnson - [EMAIL PROTECTED]
 http://www.pjcj.net



Well, I've just learned a valuable lesson (or two), which is, after all,
what I'm on this list for :)

Just prior to the code I've already posted I have this:

snip
# @unixfile was created earlier
open $unixfile, '', $company.$ext or die Can't open
$company.$ext for dos2unix process\n;
for (@unixfile) {
   s#\r\n#\n#;# Replace CRLF with LF
   print $unixfile $_;  # Write the edited version back to
the file
}
# End dos2unix #

* This close fixed the problem *
close $unixfile or warn Unable to close
$company.$ext\n;

rename $company.$ext, $company.$ext.$date;

print Creating gzip'd archive\n;

gzip $company.$ext.$date= $company.$ext.$date.gz,
  BinModeIn   = 1 or do {
 warn Failed to gzip file: $company.$ext.$date:
$GzipError\n;
 next DOTDONE;
};
/snip

I was relying on Perl closing files for me, but in this particular case,
I hadn't thought it through
well enough.

Many thanks to all for helping me get a handle on this!

richf
 

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




Hiding standard output

2008-02-01 Thread Irfan.Sayed
Hi All,
 
I want to hide the standard output on the terminal when I am executing
the Perl script. For example I am running this command
`/usr/atria/bin/cleartool lslock lbtype:$dep_lbl`;
 
if the execution of this command failed then whatever output is coming
on the terminal I want to hide that and I want to print my standard
statement.
 
Can I do that
 
Please help
 
Regards
Irfan.
 
 
Project Lead
TSINDIA - Production Line
Individual Software Solutions - UMO
T-Systems India Private Limited, Pune
Telephone: +91-20-30245000/25605000 (Extn: 5406) 
Mobile: +91 9822 854 227
Fax: ++91-020 25674090
Internet: http://www.t-systems.com
blocked::blocked::http://www.t-systems.com/ 
 


Re: Can't locate CPAN.pm in @INC

2008-02-01 Thread Adriano Ferreira
On Feb 1, 2008 10:47 AM, Pradeep Mishra [EMAIL PROTECTED] wrote:
 hi all

 I have been trying to install spamassin using ...perl -MCPAN -e shell
 which throws an error

 Can't locate CPAN.pm in @INC (@INC contains:
 /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
 /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
 /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7
 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5
 /usr/lib/perl5/site_perl
 /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
 /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
 /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
 /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
 /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7
 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi
 /usr/lib/perl5/5.8.8 .).
 BEGIN failed--compilation aborted.
 [EMAIL PROTECTED] ~]#


 Tried to search for CPAN.pm but is not found.

 perl version is
 [EMAIL PROTECTED] ~]# perl -v

 This is perl, v5.8.8 built for i386-linux-thread-multi


 packages installed
 [EMAIL PROTECTED] ~]# rpm -qa | grep perl
 perl-devel-5.8.8-32.fc8
 perl-libs-5.8.8-32.fc8
 perl-String-CRC32-1.4-3.fc8
 perl-5.8.8-32.fc8
 perl-ExtUtils-MakeMaker-6.30-32.fc8
 groff-perl-1.18.1.4-10.fc8
 perl-DBI-1.58-2.fc8
 perl-Test-Harness-2.56-32.fc8
 perl-DBD-MySQL-4.005-2.fc8.1
 perl-ExtUtils-Embed-1.26-32.fc8
 [EMAIL PROTECTED] ~]#



 Would appreciate if some one can help me solve this issue.

It looks like you need to install a rpm package which should probably
be named perl-CPAN or something like that. Your current system does
not have CPAN installed or have used some weird path perl is not
looking at.


 Thanks in advance.

 Regards




 --
 Good Judgement comes from Experience and Experience comes from bad
 Judgement!!
 The more I know, the more I realize I don't know!?
 The easiest way to find out is to try it!!!


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




debugger questions

2008-02-01 Thread Cort Morgan
Hi,

  Can anyone tell me is it possible to look at the current value of a variable 
in a package method, if the package was included in the main program with a use 
statement?

  I've read perldebug, perldebugtut, perldebguts, any web links I can find, and 
all no help (or I just don't understand them). Examples would be greatly 
appreciated.

I've tried 

V ABC::def varname

with no luck.

Thanks,

Cort


   
-
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.

Re: Hiding standard output

2008-02-01 Thread Tom Phoenix
On Feb 1, 2008 6:26 AM,  [EMAIL PROTECTED] wrote:

 I want to hide the standard output on the terminal when I am executing
 the Perl script. For example I am running this command
 `/usr/atria/bin/cleartool lslock lbtype:$dep_lbl`;

 if the execution of this command failed then whatever output is coming
 on the terminal I want to hide that and I want to print my standard
 statement.

Do you want to run your command in backticks, so as to capture (and
thereby suppress) its STDOUT? You may wish to redirect STDERR as well.
This example uses shell redirection syntax to send the command's
STDERR to the same place as STDOUT was going, which is to say, back to
perl:

  my $result = `$command 21`;  # capture all output
  if ($?) {
print Standard command failure statement.\n;
  }

Backticks are the simple form of the qx// operator, documented in the
perlop manpage.

http://perldoc.perl.org/perlop.html#Quote-Like-Operators

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/




Re: Hiding standard output

2008-02-01 Thread Chas. Owens
On Feb 1, 2008 9:26 AM,  [EMAIL PROTECTED] wrote:
 Hi All,

 I want to hide the standard output on the terminal when I am executing
 the Perl script. For example I am running this command
 `/usr/atria/bin/cleartool lslock lbtype:$dep_lbl`;

 if the execution of this command failed then whatever output is coming
 on the terminal I want to hide that and I want to print my standard
 statement.

 Can I do that
snip

This depends heavily on the shell you are using.  Under most (if not
all) Unix shells you can say

my $output = qx{/usr/atria/bin/cleartool lslock lbtype:$dep_lbl 2/dev/null};

to redirect the file handle 2 (STDERR) to the bit bucket (/dev/null).


A better solution is not to use the qx// operator.  The IPC::Open3*
module lets you run a command with complete control over its STDIN,
STDOUT, and STDERR.

* http://perldoc.perl.org/IPC/Open3.html

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




Re: debugger questions

2008-02-01 Thread Tom Phoenix
On Feb 1, 2008 8:04 AM, Cort Morgan [EMAIL PROTECTED] wrote:

   Can anyone tell me is it possible to look at the current value
 of a variable in a package method, if the package was included
 in the main program with a use statement?

Yes and kinda. If it's a package variable, yes; if it's a lexical
variable, you can see it from within its scope. But it doesn't depend
upon the 'use' statement. Here's a good explanation of the basics:

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

If you know a variable's full name, including its package name, you
can access it from any line of code.

my $old_voltage = $Electro::Shock::electrode_volts;
my $new_voltage = ($old_voltage + 20) * 150; # evil laugh
$Electro::Shock::electrode_volts = $new_voltage;

If it's a lexical (my) variable, it doesn't have a package name. Its
name is valid only within its scope. But if you stop the debugger
within its scope, that qualifies.

 I've tried

 V ABC::def varname

That looks as if you're trying to examine $ABC::def::varname, or the
same name with a different sigil in front. That's a package variable,
not a lexical. Is that right? I would usually name the variable
directly in an x command; the debugger's x command shows you the
result of any expression.

This command examines the variable %optionVars in the DB package,
which is used by the debugger. The leading pipe character causes the
debugger to pipe the output to a pager program for easy reading; the
backslash preserves the structure of the hash:

  |x \%DB::optionVars

If you're trying to access a lexical variable, though, you'll need to
stop the debugger somewhere within the scope of that lexical in order
to access it by name. That's easy to do with a breakpoint.

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/




lpr within perl

2008-02-01 Thread Grant
I am able to print from my remote server to my local printer server
perfectly with 'lpr file.pdf'.  I'd like to be able to do that from
within a perl script.  What is the simplest way?

- Grant

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




uninitialized value in printf

2008-02-01 Thread obdulio santana
I must mix 3 files, and produce a little report but in line 23 and 31 is a
warning of uninitalized value I  really don't see  the mistake.

Thank you in advance




use warnings;
@lfile0 = DATA;
chomp @lfile0;
@meses = qw(ene feb mar abr may jun jul ago sep oct nov dic);
@files= glob 78*;
my %textos;
for (@files){
open FILE,$_;
$textos{$_}=[FILE];
chomp @{$textos{$_}};
s/.{5}// for @{$textos{$_}};
}
($day,$month,$year) = (localtime)[3..5];
$dec = $day /10;
$month++;
$dec = 3 if $dec  1;
$year+=1900;
$file = sprintf vcl%02d%02d%4d.txt,$day,$month,$year;
open FILEOUT, $file;
print FILEOUT Resumen decadal \n ;
printf FILEOUT $meses[$month-1]/$year;#%d \n,$dec  ;
$form = %13s x @files ;
printf FILEOUT %23s . $form\n,sort keys %textos ;
for $line (5..50){
@str=();
for (sort keys %textos){
push @str,${$textos{$_}}[$line];
}
$form = %13s x @files ;
$form = %-10s.$form.\n;
printf FILEOUT $form,$lfile0[$line-6],@str;
}
close FILEOUT;
__END__
1.A)
B)
C)
D)
E)
F)
2.A)
B)
C)
3.A)
4.A)
B)
C)
D)
5.A)
B)
C)



5.D)
6.A)
7.A)
8.A)
B)
C)
D)
9.A)
10.A)
B)
C)
11.A)
B)
C)
D)
E)
12.A)
B)
C)
D)
E)
F)


__

and example of the file to mix

_ this is the top
Resumen decadal
78343 - Ene/2008;#2

 1.A)  tres
   B)  23.8
   C)   32.6-19
   D)   15.0-14
   E)  29.9
   F)  17.8
 2.A)   49.5-17-18
   B)   12.5-14
   C)  27.8
 3.A)  26.0
 4.A)   5.0
   B)   20.9-19
   C)0.2-13
   D)  14.3
 5.A) 110.6
   B)  110.1-20
   C) 2
  1
  1
  1
 5.D) 8
 6.A)10
 7.A) 41.75
 8.A) E
   B)   12.8-16
   C)   8.9
   D)   1.4
 9.A) X
10.A) 3
   B) 1
   C) 5
11.A)81
   B)54
   C)100-13
   D) 33-19
   E) 5
12.A) 7
   B) 2
   C) 0
   D) X
   E) 0
   F) X






___this is the bottom


Re: uninitialized value in printf

2008-02-01 Thread Gunnar Hjalmarsson

obdulio santana wrote:

I must mix 3 files, and produce a little report but in line 23 and 31 is a
warning of uninitalized value I  really don't see  the mistake.

use warnings;


use strict;


@lfile0 = DATA;
chomp @lfile0;
@meses = qw(ene feb mar abr may jun jul ago sep oct nov dic);
@files= glob 78*;
my %textos;
for (@files){
open FILE,$_;
$textos{$_}=[FILE];
chomp @{$textos{$_}};
s/.{5}// for @{$textos{$_}};
}
($day,$month,$year) = (localtime)[3..5];
$dec = $day /10;
$month++;
$dec = 3 if $dec  1;
$year+=1900;
$file = sprintf vcl%02d%02d%4d.txt,$day,$month,$year;
open FILEOUT, $file;
print FILEOUT Resumen decadal \n ;
printf FILEOUT $meses[$month-1]/$year;#%d \n,$dec  ;
$form = %13s x @files ;
printf FILEOUT %23s . $form\n,sort keys %textos ;


The number of conversions exceeds the number of keys by 1.


for $line (5..50){


for $line ( 5 .. 5 + $#lfile0 ) {


@str=();
for (sort keys %textos){
push @str,${$textos{$_}}[$line];
}
$form = %13s x @files ;
$form = %-10s.$form.\n;
printf FILEOUT $form,$lfile0[$line-6],@str;

-^


}
close FILEOUT;


snip

--
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: lpr within perl

2008-02-01 Thread Chas. Owens
On Feb 1, 2008 2:08 PM, Grant [EMAIL PROTECTED] wrote:
 I am able to print from my remote server to my local printer server
 perfectly with 'lpr file.pdf'.  I'd like to be able to do that from
 within a perl script.  What is the simplest way?
snip

open my $printer, |-, /usr/bin/lpr
or die could not open command lpr: $!;

print $printer do it\n;

close $printer;


See also Net::LPR* and Net::Printer**.

* http://search.cpan.org/dist/Net-LPR/LPR.pod
** http://search.cpan.org/dist/Net-Printer/lib/Net/Printer.pm

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




Re: uninitialized value in printf

2008-02-01 Thread John W. Krahn

obdulio santana wrote:

I must mix 3 files, and produce a little report but in line 23 and 31 is a
warning of uninitalized value I  really don't see  the mistake.


use warnings;


use strict;


@lfile0 = DATA;
chomp @lfile0;
@meses = qw(ene feb mar abr may jun jul ago sep oct nov dic);
@files= glob 78*;
my %textos;
for (@files){
open FILE,$_;


You should *always* verify that the file opened correctly:

  open FILE, '', $_ or die Cannot open '$_' $!;



$textos{$_}=[FILE];
chomp @{$textos{$_}};
s/.{5}// for @{$textos{$_}};
}
($day,$month,$year) = (localtime)[3..5];
$dec = $day /10;
$month++;
$dec = 3 if $dec  1;
$year+=1900;
$file = sprintf vcl%02d%02d%4d.txt,$day,$month,$year;
open FILEOUT, $file;


You should *always* verify that the file opened correctly:

open FILEOUT, '', $file or die Cannot open '$file' $!;



print FILEOUT Resumen decadal \n ;
printf FILEOUT $meses[$month-1]/$year;#%d \n,$dec  ;
$form = %13s x @files ;
printf FILEOUT %23s . $form\n,sort keys %textos ;


You have one more printf format then you have keys in %textos:

printf FILEOUT '%23s' . ( '%13s' x ( @files - 1 ) ) . \n, sort keys 
%textos ;




for $line (5..50){
@str=();
for (sort keys %textos){
push @str,${$textos{$_}}[$line];
}
$form = %13s x @files ;
$form = %-10s.$form.\n;
printf FILEOUT $form,$lfile0[$line-6],@str;


$line starts out with a value of 5.  5 - 6 == -1.  $lfile0[ -1 ] is the 
*last* element of @lfile0.  Did you really want to start with the last 
element?


When $line contains 48, 49 or 50 the value of $lfile0[$line-6] is undef.



}
close FILEOUT;
__END__




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: How to avoid this greedy match?

2008-02-01 Thread News Howardz
Ajay  Rob, thanks for your perfect solutions!
It does pick up the last matched string if we add another greedy match pattern 
(.+ or .*) in front of the original regex.

And thanks for the replies from yitzle, John, Ruud as well.

BR
Howardz

- Original Message 
From: Rob Dixon [EMAIL PROTECTED]
To: beginners@perl.org
Cc: News Howardz [EMAIL PROTECTED]
Sent: Tuesday, January 29, 2008 10:02:48 PM
Subject: Re: How to avoid this greedy match?

News Howardz wrote:

 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?

Is this what you want? It will find the /last/ occurrence of the script
section containing 222.

Rob


use strict;
use warnings;

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

$str =~ /.*(script.*?222.*?\/script)/;

print $1;

**OUTPUT**

scripty222yy/script

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


  

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/