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