a Regular troble
hi listers: i am very sorry to say that i recently get in trouble with a Regular ! i want math the middle of 123 and 456 string! the Test Case below: -- 123faf456fafafafa->faf 33312323ff456456--->23ff 9123445677456-->4 - i have try a regular but it get trouble! can anyone help me? -- 继续上路。。
Re: a Regular troble
On Tue, Oct 16, 2012 at 8:40 PM, xiyoulaoyuanjia wrote: > hi listers: > i am very sorry to say that i recently get in trouble with a Regular ! > i want math the middle of 123 and 456 string! > the Test Case below: > -- > 123faf456fafafafa->faf > > 33312323ff456456--->23ff > > 9123445677456-->4 > - > i have try a regular but it get trouble! > can anyone help me? > > Can you let us know which reg-ex you tried? So that we can understand where did you make mistake. > > -- > 继续上路。。 > -- Praveen Kumar http://fedoraproject.org/wiki/User:Kumarpraveen http://fedoraproject.org/ http://kumar-pravin.blogspot.com
Re: a Regular troble
On Tue, Oct 16, 2012 at 10:10 AM, xiyoulaoyuanjia wrote: > i want math the middle of 123 and 456 string! > the Test Case below: > -- > 123faf456fafafafa->faf > > 33312323ff456456--->23ff Do you mean you want to add the 2 sets 3 digit chars/numbers found somewhere in the strings? Do you have any marker to let you know where those numbers will be found? Either side of the first non-digit string, maybe? -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: a Regular troble
On Oct 16, 2012, at 8:10 AM, xiyoulaoyuanjia wrote: > hi listers: > i am very sorry to say that i recently get in trouble with a Regular ! > i want math the middle of 123 and 456 string! > the Test Case below: > -- > 123faf456fafafafa->faf > > 33312323ff456456--->23ff > > 9123445677456-->4 > - > i have try a regular but it get trouble! > can anyone help me? The best way to get help with a Perl problem is to post a minimal program that demonstrates the problem you are having. Here is a program that might help: #!/usr/bin/perl use strict; use warnings; my @x = ( '123faf456fafafafa', '33312323ff456456', '9123445677456' ); for my $s ( @x ) { if( $s =~ m{ 123 (.*?) 456 }x ) { print "$s -> $1\n"; }else{ print "No match\n"; } } which produces: 123faf456fafafafa -> faf 33312323ff456456 -> 23ff 9123445677456 -> 4 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: simplestic perl module
Hello Shlomi, thx for the help. I tried and it worked. however I have few confusions. I tried it two ways (one yours and one from another website) I am not sure what is different between the two approaches. I do not know can you explain pl? from: http://www.tutorialspoint.com/perl/perl_modules.htm file: Mymodule.pm #!/usr/bin/perl package Mymodule; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); # IT WAS FAILING WITH my our @EXPORT = qw(myroutine); ... sub myroutine{ ... } file: perlscript.pl #!/usr/bin/perl use strict; use warnings; use Template; use Mymodule; my ($output)=myroutine($input); then used your method: and it worked, as expected. I am not sure what is the diff between two approaches? can you pl help explain? ty. file: Mymodule.pm #!/usr/bin/perl package Mymodule; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(myroutine); file: perlscript.pl #!/usr/bin/perl use strict; use warnings; use Template; use Mymodule qw(myroutine); my ($output)=myroutine($input); - Original Message - From: Shlomi Fish To: Rajeev Prasad Cc: perl list Sent: Tuesday, October 9, 2012 11:33 AM Subject: Re: simplestic perl module Hi Rajeev, On Tue, 9 Oct 2012 08:54:31 -0700 (PDT) Rajeev Prasad wrote: > I want to execute this routine which is to be supplied two(sometimes > three) string variables. and will return two string variables. I want > to keep this routine in a separate file. how to do it? > > > > something like: > > ($var1,$var2) = routine > > I am either looking to keep this routine in a file which has many > routines. OR to keep this routine in a separate file, which has ONLY > this routine. > > please suggest how to pass variables and accept the multiple values > returned by the routine. > Please see: * http://perl-begin.org/topics/modules-and-packages/ for comprehensive info and tutorials about modules in Perl. As a teaser, what you can do for example is: [CODE] # This is file MyModule.pm package MyModule; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(my_function); sub my_function { my ($first_s, $second_s) = @_; # Silly expressions: my $first_ret = $first_s . $second_s . "Hello"; my $second_ret = $second_s . "Lambda" . $first_s; return ($first_ret, $second_ret); } 1; [/CODE] And then do: [CODE] #!/usr/bin/perl use strict; use warnings; use MyModule qw(my_function); # Use my_function() [/CODE] But you really should learn about modules in Perl. Regards, Shlomi Fish > ty. -- - Shlomi Fish http://www.shlomifish.org/ Interview with Ben Collins-Sussman - http://shlom.in/sussman Knuth is not God! God has already released TeX version 4.0. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: simplestic perl module
Hi, I started to monitor this list not a while ago and just wanted to ask what is @ISA and @EXPORT here and how they are related to those "our" variables ? thanks, On 10/17/2012 8:07 AM, Rajeev Prasad wrote: Hello Shlomi, thx for the help. I tried and it worked. however I have few confusions. I tried it two ways (one yours and one from another website) I am not sure what is different between the two approaches. I do not know can you explain pl? from: http://www.tutorialspoint.com/perl/perl_modules.htm file: Mymodule.pm #!/usr/bin/perl package Mymodule; use strict; use warnings; require Exporter; our @ISA = qw(Exporter);# IT WAS FAILING WITH my our @EXPORT = qw(myroutine); ... sub myroutine{ ... } file: perlscript.pl #!/usr/bin/perl use strict; use warnings; use Template; use Mymodule; my ($output)=myroutine($input); then used your method: and it worked, as expected. I am not sure what is the diff between two approaches? can you pl help explain? ty. file: Mymodule.pm #!/usr/bin/perl package Mymodule; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(myroutine); file: perlscript.pl #!/usr/bin/perl use strict; use warnings; use Template; use Mymodule qw(myroutine); my ($output)=myroutine($input); - Original Message - From: Shlomi Fish To: Rajeev Prasad Cc: perl list Sent: Tuesday, October 9, 2012 11:33 AM Subject: Re: simplestic perl module Hi Rajeev, On Tue, 9 Oct 2012 08:54:31 -0700 (PDT) Rajeev Prasad wrote: I want to execute this routine which is to be supplied two(sometimes three) string variables. and will return two string variables. I want to keep this routine in a separate file. how to do it? something like: ($var1,$var2) = routine I am either looking to keep this routine in a file which has many routines. OR to keep this routine in a separate file, which has ONLY this routine. please suggest how to pass variables and accept the multiple values returned by the routine. Please see: * http://perl-begin.org/topics/modules-and-packages/ for comprehensive info and tutorials about modules in Perl. As a teaser, what you can do for example is: [CODE] # This is file MyModule.pm package MyModule; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(my_function); sub my_function { my ($first_s, $second_s) = @_; # Silly expressions: my $first_ret = $first_s . $second_s . "Hello"; my $second_ret = $second_s . "Lambda" . $first_s; return ($first_ret, $second_ret); } 1; [/CODE] And then do: [CODE] #!/usr/bin/perl use strict; use warnings; use MyModule qw(my_function); # Use my_function() [/CODE] But you really should learn about modules in Perl. Regards, Shlomi Fish ty. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/