Re: search and replace

2016-06-29 Thread John SJ Anderson
> On Jun 29, 2016, at 09:20, Uri Guttman wrote: > > since you are correct about modules being already there, why do you write > your own versions of > slurp_file and write_file? the module File::Slurp has those functions which > are stable, fast and debugged. Please

Re: search and replace

2016-06-29 Thread Eric de Hont
Op 29-06-16 om 19:26 schreef Uri Guttman: On 06/29/2016 01:17 PM, Eric de Hont wrote: Op 29-06-16 om 18:20 schreef Uri Guttman: since you are correct about modules being already there, why do you write your own versions of slurp_file and write_file? the module File::Slurp has those functions

Re: search and replace

2016-06-29 Thread Uri Guttman
On 06/29/2016 01:17 PM, Eric de Hont wrote: Op 29-06-16 om 18:20 schreef Uri Guttman: On 06/29/2016 06:03 AM, Eric de Hont wrote: sub slurp_file { my $file = shift; local $/; open my $fh, '<', $file or die "Can't open $_: $!\n"; $_ is not set anywhere. you likely meant to use

Re: search and replace

2016-06-29 Thread Eric de Hont
Op 29-06-16 om 18:20 schreef Uri Guttman: On 06/29/2016 06:03 AM, Eric de Hont wrote: sub slurp_file { my $file = shift; local $/; open my $fh, '<', $file or die "Can't open $_: $!\n"; $_ is not set anywhere. you likely meant to use $file O, dear. Just a bit too quick and

Re: search and replace

2016-06-29 Thread Uri Guttman
On 06/29/2016 06:03 AM, Eric de Hont wrote: Op 29-06-16 om 06:35 schreef Danny Wong: Hi Perl GURUs, I have a json file that needs parsing. Here is a typical string I’m searching for. I want to delete everything but the last 2 character “],”. ], [ "ansible",

Re: search and replace

2016-06-29 Thread Danny Wong
rl.org>" <beginners@perl.org<mailto:beginners@perl.org>> Subject: Re: search and replace Op 29-06-16 om 06:35 schreef Danny Wong: Hi Perl GURUs, I have a json file that needs parsing. Here is a typical string I’m searching for. I want to del

Re: search and replace

2016-06-29 Thread Eric de Hont
Op 29-06-16 om 06:35 schreef Danny Wong: Hi Perl GURUs, I have a json file that needs parsing. Here is a typical string I’m searching for. I want to delete everything but the last 2 character “],”. ], [ "ansible", "2.1.0.0-1ppa~trusty", false ], Here is

Re: search and replace

2016-06-29 Thread Shlomi Fish
Hi Danny, Please reply to all recipients. See below for my reply. On Wed, 29 Jun 2016 04:35:22 + Danny Wong wrote: > Hi Perl GURUs, > I have a json file that needs parsing. > Why not use a JSON parser? See http://perl-begin.org/uses/text-parsing/ . > Here is

Re: Search and replace trouble with a variable

2014-02-01 Thread Hal Wigoda
What error? (Sent from iPhone, so please accept my apologies in advance for any spelling or grammatical errors.) On Feb 1, 2014, at 2:40 AM, Omega -1911 1911...@gmail.com wrote: Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a

Re: Search and replace trouble with a variable

2014-02-01 Thread Shlomi Fish
Hi Omega, On Sat, 1 Feb 2014 03:40:01 -0500 Omega -1911 1911...@gmail.com wrote: Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since the database prefix will differ, I am simply trying to add:

Re: Search and replace trouble with a variable

2014-02-01 Thread Omega -1911
On Sat, Feb 1, 2014 at 4:57 AM, Shlomi Fish shlo...@shlomifish.org wrote: Hi Omega, On Sat, 1 Feb 2014 03:40:01 -0500 Omega -1911 1911...@gmail.com wrote: Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since

Re: Search and replace trouble with a variable

2014-02-01 Thread Shlomi Fish
Hi Omega, On Sat, 1 Feb 2014 11:36:20 -0500 Omega -1911 1911...@gmail.com wrote: Good advice Shlomi. Thank you again. I should have caught that with fresh eyes! You're welcome! ☺ Regards, Shlomi Fish -- - Shlomi Fish

Re: search and replace

2012-08-18 Thread timothy adigun
Hi Irfan Sayed, Please check my comments below. On 8/18/12, Irfan Sayed irfan_sayed2...@yahoo.com wrote: hi, i have string like this : $a = '$(workspace)\convergence\trunk'; i need to replace $(workspace) with 'c:\p4\abc' i wrote regex like this : $a =~ s/$\(workspace)/c:\\p4\\abc/;

Re: search and replace

2012-08-17 Thread Shawn H Corey
On Fri, 17 Aug 2012 18:02:23 -0700 (PDT) Irfan Sayed irfan_sayed2...@yahoo.com wrote: i have string like this : $a = '$(workspace)\convergence\trunk'; i need to replace $(workspace) with 'c:\p4\abc' i wrote regex like this : $a =~ s/$\(workspace)/c:\\p4\\abc/; The easy way is to quote

Re: search and replace

2012-08-17 Thread Irfan Sayed
thanks a lot regards irfan From: Shawn H Corey shawnhco...@gmail.com To: beginners@perl.org Cc: Irfan Sayed irfan_sayed2...@yahoo.com Sent: Saturday, August 18, 2012 6:50 AM Subject: Re: search and replace On Fri, 17 Aug 2012 18:02:23 -0700 (PDT) Irfan

Re: search and replace

2012-08-16 Thread Gergely Buday
Here is the correct version: #!/usr/bin/perl $csproj_text = C:\\build.txt; $csproj_text =~ s/\\//g; print $csproj_text\n; Notice that in order to put a literal backslash into a perl string, you should escape it. In your original program, you have put a \b, a bell character into the string.

Re: search and replace

2012-08-16 Thread Rob Coops
On Thu, Aug 16, 2012 at 10:55 AM, Gergely Buday gbu...@gmail.com wrote: Here is the correct version: #!/usr/bin/perl $csproj_text = C:\\build.txt; $csproj_text =~ s/\\//g; print $csproj_text\n; Notice that in order to put a literal backslash into a perl string, you should escape

Re: search and replace

2012-08-16 Thread midhun
The issue is $cs_project = C:\build.txt; ## In Double quotes takes the string as C:build.txt.since its an escape character That's the reason why Rob suggested to put the string in Single quotes. Both Gergely and Rob are right. Cheers, Midhun On Thu, Aug 16, 2012 at 2:29 PM, Rob Coops

Re: search and replace

2012-08-16 Thread Irfan Sayed
, 2012 2:41 PM Subject: Re: search and replace The issue is $cs_project = C:\build.txt; ## In Double quotes takes the string as C:build.txt.since its an escape character That's the reason why Rob suggested to put the string in Single quotes. Both Gergely  and Rob are right. Cheers, Midhun

Re: search and replace

2012-08-16 Thread Shawn H Corey
On Thu, 16 Aug 2012 10:55:03 +0200 Gergely Buday gbu...@gmail.com wrote: Notice that in order to put a literal backslash into a perl string, you should escape it. In your original program, you have put a \b, a bell character into the string. Actually, \b is the backspace character. The bell

Re: search and replace with an array

2012-02-21 Thread Adams Paul
Sent from my LG phone John W. Krahn jwkr...@shaw.ca wrote: Chris Stinemetz wrote: I am trying ot find a way to use an array as a reference to remove lines from a file. The array @keyFields has the elements rcsm and cdmno. My objective is to remove any line from the input that matches the

Re: search and replace with an array

2012-02-21 Thread Shawn H Corey
On 12-02-21 11:37 AM, Adams Paul wrote: Sent from my LG phone Is this is what is called a bum dial? -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. It's Mutual Aid, not fierce competition, that's the

Re: search and replace with an array

2012-02-20 Thread Chris Stinemetz
Looks like I was able to figure it out with the below: But how do I remove all the blank lines? Output: cdmno=1 rdnt_cdmno=1 cdmno=2 rcsm=801 rcsm=801 rcsm=802 #!/usr/bin/perl use warnings; use strict; my $file = nonKeys.txt; my $newFile = cleanKeys.txt; my @keyFields =

RE: search and replace with an array

2012-02-20 Thread Wagner, David --- Sr Programmer Analyst --- CFS
-Original Message- From: Chris Stinemetz [mailto:chrisstinem...@gmail.com] Sent: Monday, February 20, 2012 13:51 To: beginners@perl.org Subject: Re: search and replace with an array Looks like I was able to figure it out with the below: But how do I remove all the blank lines? Output

RE: search and replace with an array

2012-02-20 Thread Ken Slater
-Original Message- From: Chris Stinemetz [mailto:chrisstinem...@gmail.com] Sent: Monday, February 20, 2012 3:51 PM To: beginners@perl.org Subject: Re: search and replace with an array Looks like I was able to figure it out with the below: But how do I remove all the blank lines

Re: search and replace with an array

2012-02-20 Thread John W. Krahn
Chris Stinemetz wrote: I am trying ot find a way to use an array as a reference to remove lines from a file. The array @keyFields has the elements rcsm and cdmno. My objective is to remove any line from the input that matches the regex /rcsm\d/ and cdmno\d/. AND means matching BOTH in the same

Re: search and replace with an array

2012-02-20 Thread Chris Stinemetz
Thank you everyone that replied. Your suggestions helped me with finding a solution. Take care, Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Search and replace w/ ignoring arbitrary characters

2011-08-11 Thread Frank Müller
hi, thank you for your solution which works perfect for the data i have given. the trouble is: my data looks a little more complex as I have lots of accented characters so with your code I need to specify each of those characters in the tr/// part. I reckon the other way around would be more

Re: Search and replace w/ ignoring arbitrary characters

2011-08-08 Thread John W. Krahn
Frank Müller wrote: dear all, Hello, i want to make some search and replace within a string where I can define a set of characters, especially parenthesis, brackets etc., which are to be ignored. For example, I have the following string: sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh

Re: search and replace

2008-11-13 Thread [EMAIL PROTECTED]
On Nov 12, 6:55 am, [EMAIL PROTECTED] (Rob Dixon) wrote: [EMAIL PROTECTED] wrote: Hi I am new to this group and to Perl. I am having trouble with searching and replacing a pattern in a file and then copying to a new file.  I am trying to write an interactive program to do this where

Re: search and replace

2008-11-13 Thread Mr. Shawn H. Corey
On Wed, 2008-11-12 at 13:00 -0800, [EMAIL PROTECTED] wrote: I think I understand most of your suggestions but I'm not very clear in this line: print $out $_;# in the while loop below. while ($in) { s/\Q$search/$replace/g; print $out $_; What is the $_ variable? The $_

Re: search and replace

2008-11-13 Thread [EMAIL PROTECTED]
On Nov 12, 6:55 am, [EMAIL PROTECTED] (Rob Dixon) wrote: [EMAIL PROTECTED] wrote: Hi I am new to this group and to Perl. I am having trouble with searching and replacing a pattern in a file and then copying to a new file.  I am trying to write an interactive program to do this where

Re: search and replace

2008-11-12 Thread Rob Dixon
[EMAIL PROTECTED] wrote: Hi I am new to this group and to Perl. I am having trouble with searching and replacing a pattern in a file and then copying to a new file. I am trying to write an interactive program to do this where I input the file name for the search and replace and the file

Re: search and replace

2008-11-12 Thread Chas. Owens
On Tue, Nov 11, 2008 at 09:52, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi I am new to this group and to Perl. I am having trouble with searching and replacing a pattern in a file and then copying to a new file. I am trying to write an interactive program to do this where I input the

Re: search and replace

2008-11-12 Thread Jay Savage
On Tue, Nov 11, 2008 at 9:52 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi I am new to this group and to Perl. [snip] #!/usr/bin/perl -w use strict; If you really have warnings enabled, you should be seeing lots of warnings like bareword found where operator expected pointing at this

Re: search and replace command with output

2008-08-19 Thread Ron Bergin
On Aug 13, 1:44 pm, [EMAIL PROTECTED] wrote: Hi, I am trying to search replace a string in a file using the below perl command on unix. perl -pi -e 's/OLD/NEW/g' repltest.txt But I want the above command to display what lines were replaced. Is it possible using some switch options? If

Re: search and replace command with output

2008-08-19 Thread kens
On Aug 13, 4:44 pm, [EMAIL PROTECTED] wrote: Hi, I am trying to search replace a string in a file using the below perl command on unix. perl -pi -e 's/OLD/NEW/g' repltest.txt But I want the above command to display what lines were replaced. Is it possible using some switch options? If

Re: search and replace command with output

2008-08-19 Thread kens
On Aug 13, 4:44 pm, [EMAIL PROTECTED] wrote: Hi, I am trying to search replace a string in a file using the below perl command on unix. perl -pi -e 's/OLD/NEW/g' repltest.txt But I want the above command to display what lines were replaced. Is it possible using some switch options? If

Re: search and replace command with output

2008-08-18 Thread Xavier Mas
El Thursday 14 August 2008 17:30:43 [EMAIL PROTECTED] va escriure: Xavier, Thanks for the tip but can you help me by pasting the code too? It might take 2 mins for you but I will have to fiddle with it longer :( Regards. On Aug 14, 6:02 am, [EMAIL PROTECTED] (Xavier Mas) wrote: El

Re: search and replace command with output

2008-08-15 Thread samrya
Xavier, Thanks for the tip but can you help me by pasting the code too? It might take 2 mins for you but I will have to fiddle with it longer :( Regards. On Aug 14, 6:02 am, [EMAIL PROTECTED] (Xavier Mas) wrote: El Wednesday 13 August 2008 22:44:11 [EMAIL PROTECTED] va escriure: Hi, I

Re: search and replace command with output

2008-08-14 Thread Mr. Shawn H. Corey
On Wed, 2008-08-13 at 13:44 -0700, [EMAIL PROTECTED] wrote: Hi, I am trying to search replace a string in a file using the below perl command on unix. perl -pi -e 's/OLD/NEW/g' repltest.txt But I want the above command to display what lines were replaced. Is it possible using some

Re: search and replace command with output

2008-08-14 Thread Xavier Mas
El Wednesday 13 August 2008 22:44:11 [EMAIL PROTECTED] va escriure: Hi, I am trying to search replace a string in a file using the below perl command on unix. perl -pi -e 's/OLD/NEW/g' repltest.txt But I want the above command to display what lines were replaced. Is it possible using

Re: Search and Replace

2007-07-14 Thread Rob Dixon
Joseph L. Casale wrote: From: Rob Dixon Joseph L. Casale wrote: One of these scripts has a loop like this: for my $line (@lines){ my $line2 = $line; $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2/; print FILEOUT $line; $line2 =~ s/(\S+)\s+(\S+)\s+(\S+)/Z[$3+DPad]/; print FILEOUT $line2;

Re: Search and Replace

2007-07-14 Thread Dr.Ruud
Chas Owens schreef: print $out X$x Y$y\n, Z[$z+DPad]\n, M98PDRILL.SUBL1\n, G90\n, G00 Z[CPlane]\n; Never use multiple print statements when you can use just one. In general that's true, but because of the Never I have to object. :) Sometimes

Re: Search and Replace

2007-07-14 Thread Mr. Shawn H. Corey
Joseph L. Casale wrote: OK, I saw your example and noted it. I intended on using next time as I know there will be:) But now I am convinced, as the lack of error checking in my script worries me. I'll take yours and fit it in! I do need to read up on what you're doing as I am not clear on its

Re: Search and Replace

2007-07-14 Thread Chas Owens
On 7/14/07, Dr.Ruud [EMAIL PROTECTED] wrote: snip Never use multiple print statements when you can use just one. In general that's true, but because of the Never I have to object. :) Sometimes multiple print statements look like only one, I am thinking of the print for LIST construct.

Re: Search and Replace

2007-07-14 Thread Mr. Shawn H. Corey
Chas Owens wrote: By the way, an easier way to write the join version is print map { $_\n } @list; BTW, that's not the same. Join inserts its string between each element, map (in this case) appends it to the end. A subtle difference that may lead to confusion and errors. -- Just my

Re: Search and Replace

2007-07-14 Thread Chas Owens
On 7/14/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chas Owens wrote: By the way, an easier way to write the join version is print map { $_\n } @list; BTW, that's not the same. Join inserts its string between each element, map (in this case) appends it to the end. A subtle difference

Re: Search and Replace

2007-07-14 Thread Mr. Shawn H. Corey
Chas Owens wrote: The code I am referring to is print +(join \n, @LIST), \n ; Which does the same thing as print map { $_\n } @list; The only difference between them is if $, is set. True, in this case they are. But the way you stated your preferences implied they are the same, or at

Re: Search and Replace

2007-07-14 Thread Rob Dixon
Chas Owens wrote: On 7/14/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chas Owens wrote: By the way, an easier way to write the join version is print map { $_\n } @list; BTW, that's not the same. Join inserts its string between each element, map (in this case) appends it to the end.

Re: Search and Replace

2007-07-14 Thread Rob Dixon
Rob Dixon wrote: Chas Owens wrote: On 7/14/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chas Owens wrote: By the way, an easier way to write the join version is print map { $_\n } @list; BTW, that's not the same. Join inserts its string between each element, map (in this case)

Re: Search and Replace

2007-07-14 Thread Chas Owens
On 7/14/07, Rob Dixon [EMAIL PROTECTED] wrote: Chas Owens wrote: On 7/14/07, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: Chas Owens wrote: By the way, an easier way to write the join version is print map { $_\n } @list; BTW, that's not the same. Join inserts its string between each

RE: Search and Replace

2007-07-13 Thread Joseph L. Casale
One of these scripts has a loop like this: for my $line (@lines){ my $line2 = $line; $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2/; print FILEOUT $line; $line2 =~ s/(\S+)\s+(\S+)\s+(\S+)/Z[$3+DPad]/; print FILEOUT $line2; print FILEOUT M98PDRILL.SUBL1\n; print FILEOUT G90\n; print FILEOUT G00

Re: Search and Replace

2007-07-13 Thread Tom Phoenix
On 7/13/07, Joseph L. Casale [EMAIL PROTECTED] wrote: What would be a wise way of trapping a condition such as the line read and passed into the loop is not 3 sets of numbers and if so, skip? Use the 'next' operator. It's documented in perlfunc. Hope this helps! --Tom Phoenix Stonehenge

Re: Search and Replace

2007-07-13 Thread Rob Dixon
Joseph L. Casale wrote: One of these scripts has a loop like this: for my $line (@lines){ my $line2 = $line; $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2/; print FILEOUT $line; $line2 =~ s/(\S+)\s+(\S+)\s+(\S+)/Z[$3+DPad]/; print FILEOUT $line2; print FILEOUT M98PDRILL.SUBL1\n; print FILEOUT

Re: Search and Replace

2007-07-13 Thread Rob Dixon
Joseph L. Casale wrote: One of these scripts has a loop like this: for my $line (@lines){ my $line2 = $line; $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2/; print FILEOUT $line; $line2 =~ s/(\S+)\s+(\S+)\s+(\S+)/Z[$3+DPad]/; print FILEOUT $line2; print FILEOUT M98PDRILL.SUBL1\n; print FILEOUT

RE: Search and Replace

2007-07-13 Thread Joseph L. Casale
Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Friday, July 13, 2007 7:09 PM To: beginners@perl.org Cc: Joseph L. Casale Subject: Re: Search and Replace Joseph L. Casale wrote: One of these scripts has a loop like this: for my $line (@lines){ my $line2 = $line; $line =~ s/(\S

Re: Search and Replace

2007-07-13 Thread Chas Owens
On 7/13/07, Joseph L. Casale [EMAIL PROTECTED] wrote: snip open (FILEIN, $ARGV[0]) or die $!; my @lines = FILEIN; snip In list context the operatot returns all lines, but in scalar context it returns on line at a time. This can be used with a while loop to walk over the file in pieces (a

RE: Search and Replace

2007-07-12 Thread Joseph L. Casale
: Wednesday, July 11, 2007 4:52 PM To: Joseph L. Casale Cc: beginners@perl.org Subject: Re: Search and Replace Joseph L. Casale wrote: Paul, Reading the perlre doc I am starting to understand this line: $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 Z$3/; I have a few questions. 1. What is the tilde

Re: Search and Replace

2007-07-12 Thread Rob Dixon
Joseph L. Casale wrote: How can I make this expression: $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 Z$3/ Add some numerical value to the Z$3 part, so if $3 was 3.14, I want it to be Z4.14 for example by adding 1 to it. May I reply amending my original solution to your problem, which seems to me

RE: Search and Replace

2007-07-12 Thread Joseph L. Casale
Ok Rob, I'll have a look. Thanks! jlc -Original Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Thursday, July 12, 2007 1:22 PM To: beginners@perl.org Cc: Joseph L. Casale Subject: Re: Search and Replace Joseph L. Casale wrote: How can I make this expression: $line =~ s/(\S

Re: Search and Replace

2007-07-12 Thread Chas Owens
On 7/12/07, Joseph L. Casale [EMAIL PROTECTED] wrote: Hi All, How can I make this expression: $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 Z$3/ Add some numerical value to the Z$3 part, so if $3 was 3.14, I want it to be Z4.14 for example by adding 1 to it. Use the e option to turn the

RE: Search and Replace

2007-07-11 Thread Moon, John
From: Joseph L. Casale [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 11, 2007 1:51 PM To: beginners@perl.org Subject: Search and Replace Hi, Know that I am learning perl, I am expected to use it at work :) Problem is I am still to green for the current problem I have. The data is always left

Re: Search and Replace

2007-07-11 Thread Paul Lalli
On Jul 11, 1:50 pm, [EMAIL PROTECTED] (Joseph L. Casale) wrote: Hi, Know that I am learning perl, I am expected to use it at work :) Problem is I am still to green for the current problem I have. The data is always left justified and has a space between each value. I have a text file of

RE: Search and Replace

2007-07-11 Thread Joseph L. Casale
To: beginners@perl.org Subject: Re: Search and Replace On Jul 11, 1:50 pm, [EMAIL PROTECTED] (Joseph L. Casale) wrote: Hi, Know that I am learning perl, I am expected to use it at work :) Problem is I am still to green for the current problem I have. The data is always left justified and has

Re: Search and Replace

2007-07-11 Thread Rob Dixon
Joseph L. Casale wrote: Hi, Know that I am learning perl, I am expected to use it at work :) Problem is I am still to green for the current problem I have. The data is always left justified and has a space between each value. I have a text file of about ~500 lines like this: -11.67326 23.95923

RE: Search and Replace

2007-07-11 Thread Joseph L. Casale
-Original Message- From: Paul Lalli [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 11, 2007 12:30 PM To: beginners@perl.org Subject: Re: Search and Replace On Jul 11, 1:50 pm, [EMAIL PROTECTED] (Joseph L. Casale) wrote: Hi, Know that I am learning perl, I am expected to use it at work :) Problem

Re: Search and Replace

2007-07-11 Thread Mr. Shawn H. Corey
Joseph L. Casale wrote: Paul, Reading the perlre doc I am starting to understand this line: $line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 Z$3/; I have a few questions. 1. What is the tilde for? From `perldoc perlop`: Binding Operators Binary =~ binds a scalar expression to a

Re: search and replace content of file - pattern: hash

2006-03-25 Thread Jeff Pang
Hello, I would like to search content of file and as a pattern to use hash, but I can't find out how to do that. Situation: %hash = ( key1 = value1, ... keyn = valuen); Hello, Here it's easy to access the hash's value via its key,simply as: $hash{key1}; I think you would want

Re: Search and replace values in a fixed-width file

2006-02-10 Thread Chas Owens
On 2/10/06, Ken Hill [EMAIL PROTECTED] wrote: I have the following perl script that reads a fixed-width file and replaces values in various sections of the file. --- open (IN, ' in.txt'); open (OUT, ' out_test.txt'); while (IN) { chomp;

Re: Search and replace values in a fixed-width file

2006-02-10 Thread Chas Owens
On 2/10/06, Chas Owens [EMAIL PROTECTED] wrote: On 2/10/06, Ken Hill [EMAIL PROTECTED] wrote: I have the following perl script that reads a fixed-width file and replaces values in various sections of the file. --- open (IN, ' in.txt'); open

Re: Search and replace values in a fixed-width file

2006-02-10 Thread John W. Krahn
Ken Hill wrote: I have the following perl script that reads a fixed-width file and replaces values in various sections of the file. --- open (IN, ' in.txt'); open (OUT, ' out_test.txt'); You should verify that the files were opened successfully

Re: search and replace in html text

2005-10-28 Thread Jeff 'japhy' Pinyan
On Oct 28, Matthias Leopold said: i want to search for a pattern in html text and replace only those occurences that are not enclosed inside (html tag, not perl operator). It's easiest to use a real HTML parser. Otherwise, you'll probably get false positives and what-not. $string =~

Re: search and replace

2005-07-23 Thread Jeff 'japhy' Pinyan
On Jul 23, Tom Allison said: ($lineExtract, $_) = /(^\w+\.dat\|)(.+)$/o; (I like to add the regex option 'o' at the end to improve performance.) This is a common misconception. The purpose and effects of the /o modifier (as well as the /s and /m modifiers) are unclear to a lot of Perl

Re: search and replace

2005-07-23 Thread Tom Allison
Jeff 'japhy' Pinyan wrote: On Jul 23, Tom Allison said: ($lineExtract, $_) = /(^\w+\.dat\|)(.+)$/o; (I like to add the regex option 'o' at the end to improve performance.) This is a common misconception. The purpose and effects of the /o modifier (as well as the /s and /m modifiers) are

Re: search and replace

2005-07-23 Thread Jeff 'japhy' Pinyan
On Jul 23, Tom Allison said: Jeff 'japhy' Pinyan wrote: The /o modifier tells the internal regex compiler that, after this regex has been compiled 'o'nce, it is never to be compiled again. Well, what good is that? you ask. For your average regex, there is absolutely no difference, no

Re: search and replace

2005-07-22 Thread Jeff 'japhy' Pinyan
On Jul 22, Brent Clark said: Think I have a better unstanding of the use of () for my regex search, but this morning I have a new set of problems, whereby I need to perform a search and replace and then pass on to the new variable. My current code is as so, and works: $_ =~

Re: search and replace

2005-07-22 Thread Tom Allison
Brent Clark wrote: Hi all Think I have a better unstanding of the use of () for my regex search, but this morning I have a new set of problems, whereby I need to perform a search and replace and then pass on to the new variable. My current code is as so, and works: $_ =~ s/(^\w+\.dat\|)//;

RE: search and replace confusion

2005-05-26 Thread Moon, John
Subject: search and replace confusion What I'm trying to do with the following code is convert some iCal files so that a specific application will read them. The problem is that this application can't deal with entries that have a date but no time. (Full examples below.) For example, if I have

RE: search and replace confusion

2005-05-26 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Jason Balicki wrote: What I'm trying to do with the following code is convert some iCal files so that a specific application will read them. The problem is that this application can't deal with entries that have a date but no time. (Full examples below.) For example, if I have a

RE: search and replace confusion

2005-05-26 Thread Jason Balicki
Wagner, David --- Senior Programmer Analyst --- WGO mailto:[EMAIL PROTECTED] wrote: The above seems to be what you stated you wanted. I did nothing else in processing. I am running on AS Perl 5.8.3 build 809 Thanks, any guesses as to what's wrong with my outer loop? --J(K) -- To

RE: search and replace confusion

2005-05-26 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Jason Balicki wrote: Wagner, David --- Senior Programmer Analyst --- WGO mailto:[EMAIL PROTECTED] wrote: The above seems to be what you stated you wanted. I did nothing else in processing. I am running on AS Perl 5.8.3 build 809 Thanks, any guesses as to what's wrong with my outer

RE: search and replace confusion

2005-05-26 Thread Charles K. Clarkson
Jason Balicki mailto:[EMAIL PROTECTED] wrote: : in the file, I want to convert it to: : : DTSTART:20050616T07Z : : But with my code below this line prints as: : : T07Z20050616 : : overwriting instead of appending the time value. Not when I tried it. It was appended. I did

RE: search and replace confusion

2005-05-26 Thread Jason Balicki
Wagner, David --- Senior Programmer Analyst --- WGO are the files you are processing from the same environment or a different one? If different, then it might be invalid translation of Well, I'm processing from a Linux box, and the files are created on the same box, however your comment tipped

re: Search And Replace

2005-01-07 Thread William Black
Hello All I'm tryiing to search and replace in both perl and korn shell. For Example: X=G1234V00 I want to replace all occurences of 'V' with 'v' in both perl and korn shell William Black -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: Search And Replace

2005-01-07 Thread José Pedro Silva Pinto
Hi, do perl -pi -e 's/Old_value/new_value/g' Our_File Bye -Original Message- From: William Black [mailto:[EMAIL PROTECTED] Sent: sexta-feira, 7 de Janeiro de 2005 14:42 To: beginners@perl.org Subject: re: Search And Replace Hello All I'm tryiing to search and replace in both perl

RE: Search And Replace

2005-01-07 Thread Adamiec, Larry
-Original Message- From: William Black [mailto:[EMAIL PROTECTED] Sent: Friday, January 07, 2005 08:42 To: beginners@perl.org Subject: re: Search And Replace Hello All I'm tryiing to search and replace in both perl and korn shell. For Example: X=G1234V00 I want

RE: Search And Replace

2005-01-07 Thread pablo wablo
Subject: re: Search And Replace Hello All I'm tryiing to search and replace in both perl and korn shell. For Example: X=G1234V00 I want to replace all occurences of 'V' with 'v' in both perl and korn shell William Black In Perl, you can use ucase and lcase

RE: Search and Replace

2004-07-26 Thread Charles K. Clarkson
Mallik [EMAIL PROTECTED] wrote: : I have the below string. : : $str = iabd a bdkf a kdfkj akdfakjkf; : : I want to replace all the 'a' s prceeded and : followed by spaces with 'A'. : : The output should be like this : : $str = iabd Abdkf A kdfkj akdfakjkf; : : Any easy reg exp?

Re: search and replace array variables contents

2004-07-21 Thread Prasanna Kothari
Hi, For replacing the contents of an array : This code snippet replaces the string MODIFIED by MOD foreach(@arr) { s/MODIFIED/MOD/g; } foreach(@arr) { print $_\n; } This is a round about way of assigning values of one array to another. #!/usr/bin/perl -w @arr1 = (This,is,something,cool); @arr2 =

Re: search and replace array variables contents

2004-07-20 Thread Ramprasad A Padmanabhan
On Tue, 2004-07-20 at 15:42, Baskaran wrote: Dear sir, I have two array variables. I want to find $a[1] and replace $b[1] in a file. ($a[1],$b[1] are array variables) How to find and replace the variable contents. for ($i=0;$i$totalnum;$i++){ s/$a[i]/$b[i]/g; } You have almost

RE: search and replace array variables contents

2004-07-20 Thread Moon, John
Dear sir, I have two array variables. I want to find $a[1] and replace $b[1] in a file. ($a[1],$b[1] are array variables) How to find and replace the variable contents. for ($i=0;$i$totalnum;$i++){ s/$a[i]/$b[i]/g; } Is it possible to do search and replace or kindly suggest me an idea

Re: search an replace

2004-01-22 Thread Steve Grazzini
rmck wrote: But I run this system call and it took allnight to run :( You were asking perl to rewrite the whole file for every line you wanted to change. #!/usr/bin/perl use strict; use warnings;# or just use Foo::Monkey :-) use POSIX qw(strftime); die Usage: $0 FILES\n

Re: search an replace

2004-01-22 Thread James Edward Gray II
On Jan 22, 2004, at 10:13 AM, rmck wrote: Hi Hello. This scripts sucks in a 109mb file and i'm trying to do a search and replace on unxtime to the format from strftime. Which is working... But I run this system call and it took allnight to run :( So I killed it... Any other suggestions to

RE: search an replace

2004-01-22 Thread Dan Muey
Hi This scripts sucks in a 109mb file and i'm trying to do a search and replace on unxtime to the format from strftime. Which is working... But I run this system call and it took allnight to run :( So I killed it... Any other suggestions to reach my goal. Yes it looks

RE: search an replace

2004-01-22 Thread Bob Showalter
Steve Grazzini wrote: rmck wrote: But I run this system call and it took allnight to run :( You were asking perl to rewrite the whole file for every line you wanted to change. #!/usr/bin/perl use strict; use warnings;# or just use Foo::Monkey :-) use POSIX

RE: Search and replace pattern in a file

2004-01-19 Thread Hanson, Rob
I think you will like this, it does exactly whay you described... perl -pi.bak 's|ReplaceThis|WithThis|' * This does everything you want, AND makes a backup of each file. You can only perform a substitution on a single line though (AFAIK). See perldoc perlrun for all of the details. WARNING:

RE: Search and replace pattern in a file

2004-01-19 Thread Hanson, Rob
Sorry, my bad. Forgot the -e switch... perl -pi.bak -e 's|ReplaceThis|WithThis|' * Rob -Original Message- From: Hanson, Rob Sent: Monday, January 19, 2004 8:04 PM To: 'Perl'; [EMAIL PROTECTED] Subject: RE: Search and replace pattern in a file I think you will like this, it does

RE: Search and Replace question

2003-12-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Saju Palayur wrote: Hi I am trying to do some thing like this, but am getting the wrong output. Can somebody tell if my regular expression is wrong or not? -Perl script--- $line = ABCXYZGwcTI\\ABCXYZIntValTI; $line=~s/ABCXYZ(.*)TI/Hello$1/g;

Re: Search and Replace question

2003-12-11 Thread david
Saju Palayur wrote: Hi I am trying to do some thing like this, but am getting the wrong output. Can somebody tell if my regular expression is wrong or not? -Perl script--- $line = ABCXYZGwcTI\\ABCXYZIntValTI; $line=~s/ABCXYZ(.*)TI/Hello$1/g;

  1   2   >