RE: Regular expression question
Title: Regular expression question From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cai, Lucy (L.)Sent: Monday, July 31, 2006 17:21To: Cai, Lucy (L.); perl-win32-users@listserv.ActiveState.com; perl-unix-users@listserv.ActiveState.com; [EMAIL PROTECTED]; [EMAIL PROTECTED]Subject: Regular _expression_ question I have a file such as: My $file = "c:\temp\zips\ok.txt"; How can I split the $file to get the only path: My $dir = "c:\temp\zips"; My $file = "ok.txt"; Thanks in advance! Lucy Better to use File::Basename which will break it out foryou. Comes as part of std Perl. Wags ;) ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ** ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regular expression question
Title: Regular expression question Cai, Lucy (L.) wrote, on Monday, July 31, 2006 8:21 PM : My $file = "c:\temp\zips\ok.txt"; : How can I split the $file to get the only path: : My $dir = "c:\temp\zips";: My $file = "ok.txt"; May I suggest you use File:Basename instead of a regex? Joe Joseph Discenza, Senior Programmer/Analystmailto:[EMAIL PROTECTED]Carleton Inc. http://www.carletoninc.com574.243.6040 ext. 300Fax: 574.243.6060 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of : Cai, Lucy (L.); perl-win32-users@listserv.ActiveState.com; perl-unix-users@listserv.ActiveState.com; [EMAIL PROTECTED]; [EMAIL PROTECTED]Subject: Regular _expression_ question I have a file such as: Thanks in advance! Lucy ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular expression question
At 09:45 PM 4/26/2006 -0400, Cai, Lucy \(L.\) wrote: return (($Output =~ /.*\(ucmvob\)/s*$/) ? 1 : 0); $Output =/vobs/na_mscs_pvob /ccstore/ecc/vobs_fcis321/na_mscs_pvob.vbs public (ucmvob,replicated) What I want to do is if this tring include word ucmvob, then return 1, else return 0. If u just want the word ucmvob then u don't need any of the rest of the regex u put in there. And I think the outer parenthesis on the return could be messing u up too. Not sure without testing but that could be trying to return an array. This will work: $Output =~ m/ucmvob/ ? return 1 : return 0; If u want to retain ur previous return format then do this: return scalar $Output =~ m/ucmvob/; # returns no. of matches i.e. 1 or 0 -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regular expression question
Well, there are a couple of issues here. First off, I don't think this would even compile, because you used /s instead of \s. Secondly, your regex is looking for: .* zero or more of any character (unnecessary, since you didn't anchor the start of the string) \(ucmvob\) the string '(ucmvob)' \s* zero or more whitespace characters $ the end of the string -- I think what you might be looking for is something similar to this: /\(ucmvob\)/ or possibly this: /\(ucmvob,.*?\)/ which would match 'ucmvob', a comma, and any other text (non-greedy match) between parentheses. Of course, I can't test this where I am, but that should get you started. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cai, Lucy (L.) Sent: Wednesday, April 26, 2006 6:46 PM To: perl-win32-users@listserv.ActiveState.com Cc: perl-win32-users@listserv.ActiveState.com Subject: Regular expression question Hi, all, I have a question about regular expression: my code is like this: ** sub IsPVob { my ($Vob) = @_; my $Output = `cleartool lsvob $Vob`; die IsPVob can't list vob $Vob if $?; return (($Output =~ /.*\(ucmvob\)/s*$/) ? 1 : 0); } ** $Output =/vobs/na_mscs_pvob /ccstore/ecc/vobs_fcis321/na_mscs_pvob.vbs public (ucmvob,replicated) What I want to do is if this tring include word ucmvob, then return 1, else return 0. My code does not work, it return 0. Could you please see why it is like this? or do you have a better idea? Thanks a lot inadvance! Lucy ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular expression question
Cai, Lucy (L.) [EMAIL PROTECTED] graced perl with these words of wisdom: return (($Output =~ /.*\(ucmvob\)/s*$/) ? 1 : 0); } ** $Output =/vobs/na_mscs_pvob /ccstore/ecc/vobs_fcis321/na_mscs_pvob.vbs public (ucmvob,replicated) What I want to do is if this tring include word ucmvob, then return 1, else return 0. If I understand your code correctly, you're looking for the string (ucmvob) -- note that you don't have anything in your regex between the b and the escaped close partentheses. In $Output, that string doesn't exist, as the b in ucmvob is followed by a comma. -- Ted fedya at bestweb dot net Oh Marge, anyone can miss Canada, all tucked away down there --Homer Simpson ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
Thanks for the replying. I have another question, if I have a string like $a = this is a (test); How can I change it to $a = this_is_a_test; How can I remove ()? Thanks Lixin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of $Bill Luebkert Sent: Wednesday, March 31, 2004 8:27 PM To: [EMAIL PROTECTED] Subject: Re: regular expression question Wagner, David --- Senior Programmer Analyst --- WGO wrote: Hey guys - what's with the HTML ? From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 16:49 To: [EMAIL PROTECTED] Subject: regular expression question I have a $a which $a = this is a test; How can I change $a like: $a = this_is_a_test; No problem using $a, but if I were you, I would not. In the Perl sort $a, $b are the default variables to use and I would stay away if I were you. That said, $a =~ s/ /_/g; You could also use tr (slightly faster) : $a =~ tr/ /_/; -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
$a = this is a (test); $a =~ s/\W+/_/g; HTH -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Thursday, April 01, 2004 11:28 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: regular expression question Thanks for the replying. I have another question, if I have a string like $a = this is a (test); How can I change it to $a = this_is_a_test; How can I remove ()? Thanks Lixin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of $Bill Luebkert Sent: Wednesday, March 31, 2004 8:27 PM To: [EMAIL PROTECTED] Subject: Re: regular expression question Wagner, David --- Senior Programmer Analyst --- WGO wrote: Hey guys - what's with the HTML ? From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 16:49 To: [EMAIL PROTECTED] Subject: regular expression question I have a $a which $a = this is a test; How can I change $a like: $a = this_is_a_test; No problem using $a, but if I were you, I would not. In the Perl sort $a, $b are the default variables to use and I would stay away if I were you. That said, $a =~ s/ /_/g; You could also use tr (slightly faster) : $a =~ tr/ /_/; -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
$a =~ s/ /_/g; $a =~ s/[()]//g; or $a =~ tr/ ()/_/d; Peter Guzis Web Administrator, Sr. ENCAD, Inc. - A Kodak Company email: [EMAIL PROTECTED] www.encad.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, April 01, 2004 9:28 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: regular expression question Thanks for the replying. I have another question, if I have a string like $a = this is a (test); How can I change it to $a = this_is_a_test; How can I remove ()? Thanks Lixin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of $Bill Luebkert Sent: Wednesday, March 31, 2004 8:27 PM To: [EMAIL PROTECTED] Subject: Re: regular expression question Wagner, David --- Senior Programmer Analyst --- WGO wrote: Hey guys - what's with the HTML ? From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 16:49 To: [EMAIL PROTECTED] Subject: regular expression question I have a $a which $a = this is a test; How can I change $a like: $a = this_is_a_test; No problem using $a, but if I were you, I would not. In the Perl sort $a, $b are the default variables to use and I would stay away if I were you. That said, $a =~ s/ /_/g; You could also use tr (slightly faster) : $a =~ tr/ /_/; -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: regular expression question
Stacy Doss wrote: $a = "this is a (test)"; $a =~ s/\W+/_/g; HTH -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of [EMAIL PROTECTED] Sent: Thursday, April 01, 2004 11:28 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: regular _expression_ question Thanks for the replying. I have another question, if I have a string like $a = "this is a (test)"; How can I change it to $a = "this_is_a_test"; How can I remove ()? Thanks Lixin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of $Bill Luebkert Sent: Wednesday, March 31, 2004 8:27 PM To: [EMAIL PROTECTED] Subject: Re: regular _expression_ question Wagner, David --- Senior Programmer Analyst --- WGO wrote: Hey guys - what's with the HTML ? From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 16:49 To: [EMAIL PROTECTED] Subject: regular _expression_ question I have a $a which $a = "this is a test"; How can I change $a like: $a = "this_is_a_test"; No problem using $a, but if I were you, I would not. In the Perl sort $a, $b are the default variables to use and I would stay away if I were you. That said, $a =~ s/ /_/g; You could also use tr (slightly faster) : $a =~ tr/ /_/; -- hi, you might want to add the following statement after words: $a =~ s/__/_/g; # for viewing reasons... regards, topdog "i have slipped the surly bonds of earth, and danced the skies on laughter-silvered wings;" --john gillespie magee jr. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: regular expression question
Wagner, David --- Senior Programmer Analyst --- WGO wrote: Hey guys - what's with the HTML ? From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 16:49 To: [EMAIL PROTECTED] Subject: regular expression question I have a $a which $a = this is a test; How can I change $a like: $a = this_is_a_test; No problem using $a, but if I were you, I would not. In the Perl sort $a, $b are the default variables to use and I would stay away if I were you. That said, $a =~ s/ /_/g; You could also use tr (slightly faster) : $a =~ tr/ /_/; -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: regular expression question
[EMAIL PROTECTED] schrieb: I have a txt file like the bottom (I use cleardiff to compare 2 files and get this file): I would recommend that you look at Parse::RecDescent. Go grab the distribution from CPAN and have a look at the tutorial - the first example shows you how to parse a diff. http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search?site=ftp.funet.fi;join=and;stem=no;arrange=file;case=clike;download=auto;age=;distinfo=3453 HTH, Thomas ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
The easiest way to reference all but the first character of a string is probably: $rest=substr $var,1; You could also use a regex. Maybe search for a line that starts with and then return 0 or more characters matching anything after that: $var=~/^(.*)/; $rest=$1; You could also use rindex and select all the characters but one. Basically, there are a lot of possibilities... a weekend with the Camel book or perldoc would probably be rather informative. Chris -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2003 11:58 AM To: [EMAIL PROTECTED] Subject: RE: regular expression question I have another question, I have string like GENERATION 116, How can I get rid of , of the string? Thanks Lixin -Original Message- From: Todd Hayward [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2003 11:30 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: regular expression question load the file into a file handle, and iterate through it line by line. Pipe each line to the file handle (the | is not a typo in the example)... So, open(fHandle, myfile.txt|); while (defined ($line = fHandle)){ if ($line ~= /generic/ig){ do something} }; Hope this helps, NuTs - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 28, 2003 9:40 AM Subject: regular expression question Dear all I have a txt file like the bottom (I use cleardiff to compare 2 files and get this file): I will check whether the line includes ___GENERIC_MULTILINE___ or not, if it includes, I will get the following information GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 without sign, How can I do it? Thanks a lot in advance! Lixin # 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 24c24,30 ___GENERIC_MULTILINE___ --- GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 ## ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
I have another question, I have string like GENERATION 116, How can I get rid of , of the string? If you want to remove the 1st character if it is a , then use this... $var =~ s///; $var =~ s/^//; #This removes it only if it is the first character ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: regular expression question
This works: open (INPUT ,your_input.txt) || die $!; open (OUTPUT, your_output.txt) || die $!; while (INPUT) { if (m/GENERIC_MULTILINE/) { $_=GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116\n;} print OUTPUT $_;} close (OUTPUT); close (INPUT); viktoras [EMAIL PROTECTED] wrote: Dear all I have a txt file like the bottom (I use cleardiff to compare 2 files and get this file): I will check whether the line includes ___GENERIC_MULTILINE___ or not, if it includes, I will get the following information GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 without sign, How can I do it? Thanks a lot in advance! Lixin # 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 24c24,30 ___GENERIC_MULTILINE___ --- GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 ## ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs -- Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with [EMAIL PROTECTED] http://shopnow.netscape.com/ ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
Thanks a lot for your great help, another question, if I want to switch all \n to \\n in a string how can I do it? Like $var = This is a book\nThat is a desk\nwho is that man?\n; I did like $var =~ s/\n/\\n/g; but it does nt work. What is wrong with it? Thanks Lixin -Original Message- From: Todd Hayward [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2003 12:26 PM To: [EMAIL PROTECTED] Subject: Re: regular expression question Borrowing from the previous example of: open(fHandle, myfile.txt|); while (defined ($line = fHandle)){ if ($line ~= /generic/ig){ do something} }; Add this line: $line =~ s/\//g; This is what your code block should look like: open(fHandle, myfile.txt|); while (defined ($line = fHandle)){ $line =~ s/\//g; if ($line =~ /generic/ig){ do something} }; The 3rd line will effectively delete any instance of that it finds. If you want it to only remove the first instance of from each line, remove the g from the end. This makes it global to the string, thus substituting no character for each it finds. HTH, NuTs - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 28, 2003 10:58 AM Subject: RE: regular expression question I have another question, I have string like GENERATION 116, How can I get rid of , of the string? Thanks Lixin -Original Message- From: Todd Hayward [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2003 11:30 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: regular expression question load the file into a file handle, and iterate through it line by line. Pipe each line to the file handle (the | is not a typo in the example)... So, open(fHandle, myfile.txt|); while (defined ($line = fHandle)){ if ($line ~= /generic/ig){ do something} }; Hope this helps, NuTs - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 28, 2003 9:40 AM Subject: regular expression question Dear all I have a txt file like the bottom (I use cleardiff to compare 2 files and get this file): I will check whether the line includes ___GENERIC_MULTILINE___ or not, if it includes, I will get the following information GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 without sign, How can I do it? Thanks a lot in advance! Lixin # 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 24c24,30 ___GENERIC_MULTILINE___ --- GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 ## ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
I have another question, I have string like GENERATION 116, How can I get rid of , of the string? Thanks Lixin -Original Message- From: Todd Hayward [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2003 11:30 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: regular expression question load the file into a file handle, and iterate through it line by line. Pipe each line to the file handle (the | is not a typo in the example)... So, open(fHandle, myfile.txt|); while (defined ($line = fHandle)){ if ($line ~= /generic/ig){ do something} }; Hope this helps, NuTs - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 28, 2003 9:40 AM Subject: regular expression question Dear all I have a txt file like the bottom (I use cleardiff to compare 2 files and get this file): I will check whether the line includes ___GENERIC_MULTILINE___ or not, if it includes, I will get the following information GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 without sign, How can I do it? Thanks a lot in advance! Lixin # 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 24c24,30 ___GENERIC_MULTILINE___ --- GENERATION 116 # Impossible dependency # Needed to prevent FC4700 to CX-series upgrades DEPEND Navisphere 2.0.0.0.0 DEPEND Navisphere 1.0.0.0.0 GENDEPEND Navisphere 116 3,4c3,4 REVISION ___INTERNAL_REV___ DISPLAYREV ___EXTERNAL_REV___ --- REVISION 02041405.002 DISPLAYREV 02.04.1.40.5.002 ## ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: regular expression question
On Fri, 22 Nov 2002 [EMAIL PROTECTED] wrote: all, I want to check the first line of the file if it is machine or not, like The first line of the file is: Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM. my code is like: if (!-z $file) { open(LOG_FILE, $file) or warn can not open $file:$!\n; my @read_lines = LOG_FILE; close (LOG_FILE); next unless chomp($read_lines[0]) =~ m#\\nest and \toolbox VOBs\#; } it did not work for regular expression, can you help me to figure what is wrong with it? You are performing your regex match on the result of the function call: chomp($read_lines[0]). The value of chomp will be 1 if it removed a new-line character from the end of $read_lines[0] and it will be zero if it didn't remove a new-line character, i.e. if the last character was not the new-line character (actually the $/ string which has a default value of \n). Somehow I don't believe that your regex will match either a 1 or a 0. However, even if you anchor the regex on the variable $read_lines[0], I don't believe that the regex match string is correct considering that fact that it contains the representation of a new-line character (the \n) and a tab (the \t). Also note that it is not necessary to escape the double quote characters inside the regex match string unless the quote is used to delimit the match string (you used # to delimit the regex match string, my code below uses the default regex delimter, /) I believe the the following will fix your problem as far as the regex is concerned: next unless $read_lines[0] =~ /\\nest and \\toolbox VOBs/; Take out the chomp, it serves no purpose based on the code fragment you showed. Also reconsider your logic. Exactly what do you expect to happen if the regex doesn't match, i.e. if the 'next' is done what code will then execute next? [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
On Fri, 22 Nov 2002, Stovall, Adrian M. wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 4:38 PM To: Stovall, Adrian M.; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: regular expression question I tried that, it does not work for me! Lixin This code should print yes, if it does, then the code works for you... $line = 'Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM.'; print $line\n; if ($line =~ m#\\\nest and \\toolbox VOBs\#) { print yes; } else { print no; } Your code may work fine but as long as his code is archoring the regex to the result of the function call: chomp($read_lines[0]) it won't. Unless of course he changes the regex match string to: m#^[01]$#; Note that the result of doing chomp on a scalar will be one of two values, 0 or 1. [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
Sorry, I did not state quite clear, if it is machine or not, I want to say if I it is the right file or not... Lixin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 5:07 PM Cc: [EMAIL PROTECTED] Subject: regular expression question all, I want to check the first line of the file if it is machine or not, like The first line of the file is: Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM. my code is like: if (!-z $file) { open(LOG_FILE, $file) or warn can not open $file:$!\n; my @read_lines = LOG_FILE; close (LOG_FILE); next unless chomp($read_lines[0]) =~ m#\\nest and \toolbox VOBs\#; } it did not work for regular expression, can you help me to figure what is wrong with it? Thanks a lot! Lixin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
Cai Lixin said: all, I want to check the first line of the file if it is machine or not, like The first line of the file is: Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM. my code is like: if (!-z $file) { open(LOG_FILE, $file) or warn can not open $file:$!\n; my @read_lines = LOG_FILE; close (LOG_FILE); next unless chomp($read_lines[0]) =~ m#\\nest and \toolbox VOBs\#; } it did not work for regular expression, can you help me to figure what is wrong with it? You forgot to escape the backslashes...change your code to read: next unless chomp($read_lines[0]) =~ m#\\\nest and \\toolbox VOBs\#) perl -e sub Sub{return reverse(@_);}$_='.$yyye k ca i Xl $yyye jX $yyye hto ZfX tq $uQ';s+[ \$]++g;s-j-P-;s^yyy^r^g;s:i:H:;s!X! !g;s|Z|n|;s*Q*J*;s{q}{s}g;s(f)(A);$print=join('',Sub(split('')));system( 'echo',$print); To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the engineer, the glass is twice as big as it needs to be. Adrian Okay, I won't top-post unless it's an emergency Stovall ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
I tried that, it does not work for me! Lixin -Original Message- From: Stovall, Adrian M. [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 5:28 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: regular expression question Cai Lixin said: all, I want to check the first line of the file if it is machine or not, like The first line of the file is: Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM. my code is like: if (!-z $file) { open(LOG_FILE, $file) or warn can not open $file:$!\n; my @read_lines = LOG_FILE; close (LOG_FILE); next unless chomp($read_lines[0]) =~ m#\\nest and \toolbox VOBs\#; } it did not work for regular expression, can you help me to figure what is wrong with it? You forgot to escape the backslashes...change your code to read: next unless chomp($read_lines[0]) =~ m#\\\nest and \\toolbox VOBs\#) perl -e sub Sub{return reverse(@_);}$_='.$yyye k ca i Xl $yyye jX $yyye hto ZfX tq $uQ';s+[ \$]++g;s-j-P-;s^yyy^r^g;s:i:H:;s!X! !g;s|Z|n|;s*Q*J*;s{q}{s}g;s(f)(A);$print=join('',Sub(split('')));system( 'echo',$print); To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the engineer, the glass is twice as big as it needs to be. Adrian Okay, I won't top-post unless it's an emergency Stovall ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 4:38 PM To: Stovall, Adrian M.; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: regular expression question I tried that, it does not work for me! Lixin This code should print yes, if it does, then the code works for you... $line = 'Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM.'; print $line\n; if ($line =~ m#\\\nest and \\toolbox VOBs\#) { print yes; } else { print no; } perl -e sub Sub{return reverse(@_);}$i='ohce';$_='.$yyye k ca i Xl $yyye jX $yyyehto ZfX tq $uQ';s+[ \$]++g;s-j-P-;s^yyy^r^g;s:i:H:;s!X! !g;s|Z|n|;s*Q*J*;s{q}{s}g;s(f)(A);system(join('',Sub(split('',$i))),(joi n('',Sub(split(''); To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the engineer, the glass is twice as big as it needs to be. Adrian Okay, I won't top-post unless it's an emergency Stovall ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
Yes, it works fine for me! Thanks a lot! Have a nice day. Lixin -Original Message- From: Stovall, Adrian M. [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 5:42 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: regular expression question -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, November 22, 2002 4:38 PM To: Stovall, Adrian M.; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: regular expression question I tried that, it does not work for me! Lixin This code should print yes, if it does, then the code works for you... $line = 'Job \nest and \toolbox VOBs began execution on 9/6/02 at 2:00:11 AM.'; print $line\n; if ($line =~ m#\\\nest and \\toolbox VOBs\#) { print yes; } else { print no; } perl -e sub Sub{return reverse(@_);}$i='ohce';$_='.$yyye k ca i Xl $yyye jX $yyyehto ZfX tq $uQ';s+[ \$]++g;s-j-P-;s^yyy^r^g;s:i:H:;s!X! !g;s|Z|n|;s*Q*J*;s{q}{s}g;s(f)(A);system(join('',Sub(split('',$i))),(joi n('',Sub(split(''); To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the engineer, the glass is twice as big as it needs to be. Adrian Okay, I won't top-post unless it's an emergency Stovall ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression Question
Try this # my $text = this is a website: www.hello-world.com and an e-mail: [EMAIL PROTECTED]; @found = $text =~ m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g; print Found something interesting:\n, join \n, @found if @found; # which uses the m//g operation in a list context. Explanation from the perlop manpage: The /g modifier specifies global pattern matching--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern. In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match. The position after the last match can be read or set using the pos() function; see pos in the perlfunc manpage. A failed match normally resets the search position to the beginning of the string, but you can avoid that by adding the /c modifier (e.g. m//gc). Modifying the target string also resets the search position. Tim _ Tim Moose | T R I L O G Y voice (512) 874-5342 fax (512) 874-8500 Joseph Youngquist [EMAIL PROTECTED] Sent by: [EMAIL PROTECTED] 03/04/2002 02:23 PM To: [EMAIL PROTECTED] cc: Subject:Regular Expression Question Hello all, I hope some RegEx guru could answer why this stops once it finds the first occurrence of the expression. m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g This is trying to find web addresses and e-mail addresses from any thing that is sent to it... So far, I'm able to get somesite.com, www.somesite.somedomain or john.doe@somedomain, etc... The thing that's not working, is of you have more than one of these on a line sent to it. so: my $text = this is a website: www.hello-world.com and an e-mail: [EMAIL PROTECTED] if($text =~ m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g) { print Found something interesting!\n\t$1\n; } Thank you for the extra eye-balls, Joe Y. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regular Expression Question
Only problem with using html::parser is I'm not parsing an html document... There are no html tags to hook onto ... if there were, I'd be happy. What the domain my script must do is this...say we have some text: Once upon a time, in a galaxy far, far away. Yogi ([EMAIL PROTECTED]) found a family where the Chi (for more information see: www.yedi-chi.ye) was strong. Now, I need to wrap the e-mail addresses and web URLs with the html mark-up to allow people to click on the link instead of copy and paste Now if html::parser can re-wrap html on text that'd be slick but I'm not familiar with the package. Anyone out there know if this is possible with the package? Now...if this were a GUI where one was trapping events from a Text control and adding a style to make the email or URL be blue underlined text, there wouldn't be a need for html. Thanks for the idea, I'll poke about with it...if no one sends a yes/no to the question above. Joe Y. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Jeffrey Sent: Monday, March 04, 2002 3:51 PM To: [EMAIL PROTECTED] Subject: RE: Regular Expression Question I've never used the module, but you might want to look at HTML::Parser, and avoid the reinvention of that round thingy (aka the Wheel). ;) --- Morse, Richard E. [EMAIL PROTECTED] wrote: I think that you may need to do this in a while loop: my @items while($text =~ m/your string here/g) { push @items, $1; } print join(\n, @items); HTH, Ricky -Original Message- From: Joseph Youngquist [mailto:[EMAIL PROTECTED]] Sent: Monday 04 March 2002 3:23 PM To: [EMAIL PROTECTED] Subject: Regular Expression Question Hello all, I hope some RegEx guru could answer why this stops once it finds the first occurrence of the expression. m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g This is trying to find web addresses and e-mail addresses from any thing that is sent to it... So far, I'm able to get somesite.com, www.somesite.somedomain or john.doe@somedomain, etc... The thing that's not working, is of you have more than one of these on a line sent to it. so: my $text = this is a website: www.hello-world.com and an e-mail: [EMAIL PROTECTED] if($text =~ m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g) { print Found something interesting!\n\t$1\n; } Thank you for the extra eye-balls, Joe Y. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs = Jeffrey Hottle nkuvu at monkey yahoo dot com (remove the animal to email me!) __ Do You Yahoo!? Yahoo! Sports - sign up for Fantasy Baseball http://sports.yahoo.com ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regular Expression Question
Thanks, this did the trick...although when I tried this before I got an infinit loop...bahh just my programing :)...any how, the while($text =~ m/blah/g) { ... } works. Again, thank you Joe Y. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Morse, Richard E. Sent: Monday, March 04, 2002 3:32 PM To: 'Joseph Youngquist'; [EMAIL PROTECTED] Subject: RE: Regular Expression Question I think that you may need to do this in a while loop: my @items while($text =~ m/your string here/g) { push @items, $1; } print join(\n, @items); HTH, Ricky -Original Message- From: Joseph Youngquist [mailto:[EMAIL PROTECTED]] Sent: Monday 04 March 2002 3:23 PM To: [EMAIL PROTECTED] Subject: Regular Expression Question Hello all, I hope some RegEx guru could answer why this stops once it finds the first occurrence of the expression. m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g This is trying to find web addresses and e-mail addresses from any thing that is sent to it... So far, I'm able to get somesite.com, www.somesite.somedomain or john.doe@somedomain, etc... The thing that's not working, is of you have more than one of these on a line sent to it. so: my $text = this is a website: www.hello-world.com and an e-mail: [EMAIL PROTECTED] if($text =~ m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g) { print Found something interesting!\n\t$1\n; } Thank you for the extra eye-balls, Joe Y. ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression Question
Resending because I never saw the message post. Sorry if duplicate. Try this # my $text = this is a website: www.hello-world.com and an e-mail: [EMAIL PROTECTED]; @found = $text =~ m/\s+((?:[\w\d\-\~]{2,}[@|\.](?:[\w\d\-\~]{2,}\.?)+))/g; print Found something interesting:\n, join \n, @found if @found; # which uses the m//g operation in a list context. Explanation from the perlop manpage: The /g modifier specifies global pattern matching--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern. In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match. The position after the last match can be read or set using the pos() function; see pos in the perlfunc manpage. A failed match normally resets the search position to the beginning of the string, but you can avoid that by adding the /c modifier (e.g. m//gc). Modifying the target string also resets the search position. Tim _ Tim Moose | T R I L O G Y voice (512) 874-5342 fax (512) 874-8500 ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: regular expression question
$OK = c:\\some\\dir\\file; $OK =~ /(.*)(\\.*)$/; $OK1 = $1; ...of course it isn't portable across operating systems, and it assumes that filenames can't contain \. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of [EMAIL PROTECTED] Sent: Thursday, May 31, 2001 4:17 PM To: [EMAIL PROTECTED] Subject: regular expression question Dear all, I have a question about a regular expression, for example $OK = c:\\temp\\test\\test1\\test2; How can I do to make me get $OK1 = c:\\temp\\test\\test1; That means I do not want the last part of the directory. Thanks in advance! Lixin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: regular expression question
No regex in answer here but... Is this what you want? use File::Basename; $OK = c:\\temp\\test\\test1\\test2; $OK1 = dirname($OK); print dir of $OK is $OK1\n; - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, May 31, 2001 5:17 PM Subject: regular expression question Dear all, I have a question about a regular expression, for example $OK = c:\\temp\\test\\test1\\test2; How can I do to make me get $OK1 = c:\\temp\\test\\test1; That means I do not want the last part of the directory. Thanks in advance! Lixin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: regular expression question
Not really a regex approach but here is my submittion: $OK = c:\\temp\\test\\test1\\test2; $your_answer = substr($OK, 0, rindex($OK, \\)); # print $your_answer,\n; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 31, 2001 2:17 PM To: [EMAIL PROTECTED] Subject: regular expression question Dear all, I have a question about a regular expression, for example $OK = c:\\temp\\test\\test1\\test2; How can I do to make me get $OK1 = c:\\temp\\test\\test1; That means I do not want the last part of the directory. Thanks in advance! Lixin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
RE: Regular Expression question
(un-jeopardied) Wagner-David wrote, on Friday, March 02, 2001 13:08 : steve silvers [mailto:[EMAIL PROTECTED]] wrote : Say I search on (perl and oracle). : : if ($query-{Find} =~ /and/i) { : Run my sql statement ie: perl and oracle : } : : if ($query-{Find} =~ /or/i) { : Run my sql statement ie: perl or oracle : } : : Does anyone have a good routine to take (perl and oracle), get : rid of the : white space before and, get rid of and, get rid of the white : space after and : : then just have: : : if ($query-{Find} =~ /and/i) { : $sql = "SELECT bla, bla FROM table"; : $sql.= ' WHERE '; : $sql.= " column LIKE "; : $sql.= "perl AND column LIKE oracle"; : } : I believe you would want as part of the check for and or or to be : \sand\s , \sor\s otherwise if a word has or like word or and, your check : would give incorrect hits. : : Are you limited only to two(ie, perl or oracle) or could : it be more? : I think you want to take the case of more than 2 but less than : some number : which may cause too much overhead(ie 10 items within or/and may take a : performance hit). : : you could do a split(/\s+and\s+/, $query-{Find}) and same : thing for : or. I'd split on or first to preserve algebraic precedence (assuming there are no parentheses) of and over or. Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 219.243.6040 ext. 300fax: 219.243.6060 Providing Financial Solutions and Compliance for over 30 Years ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Regular Expression question
steve silvers wrote: I'm calling a bunch of rows from my database. In the while loop. while(my $Dataref = $sth-fetchrow_hashref) { my %Data = %{$Dataref}; my $text = ($Data{val}); $text = (/(www\.[\w\.\-\/\\=\+\%\:\?]*[a-zA-Z\/0-9])[\001\074]*/) $emailaddress = $1; print qq($emailaddress); } In the above regex each row has a text column, with lots of text in them. When I run this through the loop it finds the email address and I have another part that turnes it into a hyperlink. The back reference works great. Now the problem im having is when there is more than one email address. Does anyone know how I can modify this so that it will look past the first email address and also capture the second, third, etc... i have several comments on your code, Steve. while(my $Dataref = $sth-fetchrow_hashref) { my %Data = %{$Dataref}; my $text = ($Data{val}); you could redo the sql statement so that it only returned the column you are interested in. then you could use fetchrow_array instead. i only use hashref when it is truly necessary. like so: $sth = $dbh-prepare("SELECT TEXTCOLUMN FROM TABLENAME"); $sth-execute; while (($text) = $sth-fetchrow_array) { ... } $text = (/(www\.[\w\.\-\/\\=\+\%\:\?]*[a-zA-Z\/0-9])[\001\074]*/) $emailaddress = $1; print qq($emailaddress); } i presume you meant $text =~ not $text = yes? you could also do this: ($email) = ($text =~ /..(..)../); and avoid the use of the intermediate $1. note that the parentheses are required around $email to put the regular expression in 'list' context. your statement: print qq($emailaddress); is equivalent to: print "$emailaddress"; which is the same as simply: print $emailaddress; the interpolation of the scalar inside of the double quoted string is not necessary (unless, of course, you wanted to append "\n"). $text = (/(www\.[\w\.\-\/\\=\+\%\:\?]*[a-zA-Z\/0-9])[\001\074]*/) a very complex regular expression! you could use the /x modifier to spread it across several lines. i'm glad it works for you. it looks as if you are gathering _web_ addresses (with the 'www.') not email addresses (which would contain an '@'). note that web addresses do not _have_ to start with 'www.'; most do but not all. what does the [\001\074]* do at the end there??? Now the problem im having is when there is more than one email address. Does anyone know how I can modify this so that it will look past the first email address and also capture the second, third, etc... yes. there is a VERY COOL feature of perl regular expressions where it will do the match for you _globally_ and return all matched subexpressions in one fell swoop.to illustrate this: $s = "blah 45 oops 234 lala*()3 !!23 --456%%"; @nums = ($s =~ /(\d+)/g); print "@nums\n"; this prints: 45 234 3 23 456 the code above extracts just the _numbers_ from the string into separate elements of the array. the key points are the g modifer on the regular expression and assigning the results of the regular expression to an array which puts it in list context. you can use this to get all the web addresses into an array which you can then loop over! @web = ($text =~ /...(..).../g); for my $w (@web) { print "A HREF=$w$w/ABR\n"; } how's that! and if you wanted to gather them from all records before conversion to hyperlinks: push @web, ($text =~ (/...(..).../g); this would also put the regular expression into list context. hope this helps, Jon ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Regular Expression question
I am curious, why does this exact same question keep showing up, from different people (I believe) and with a spaced regularity over and over again? I don't know, but you are right. The most FAQ is : How to send attachments? The second place is reserved to: How to fetch rows? The third : How to split line? This is due to lack of proper (or any) search capability in mail archive. I wonder will there be any?? Why doesn't someone write a FAQ regarding all questions (and answers) that pops up every week or two? this will bring a great relief to everyone. And then the guys from ActiveState should insert notification for newcomers to check the FAQ first. -- "If you were supposed to understand it, we wouldn't call it code." -=- Knezevic Nikola -=- ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users