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 don’t use File::Slurp. Se

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 w

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 $f

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 dirty.

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
ers@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 delete everything but the last 2 character “],”. ], [ "a

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 wh

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 a typical string I’m searchin

search and replace

2016-06-28 Thread 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 what I tried: I slu

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 Fis

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 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 the database

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: > > ".$database

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

Search and replace trouble with a variable

2014-02-01 Thread Omega -1911
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: ".$database_prefix." to those lines. For example, instead of the line looking like: $sql = "SELECT * FROM

Re: search and replace

2012-08-18 Thread timothy adigun
Hi Irfan Sayed, Please check my comments below. On 8/18/12, Irfan Sayed 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/; > however, the stri

Re: search and replace

2012-08-17 Thread Irfan Sayed
thanks a lot regards irfan From: Shawn H Corey To: beginners@perl.org Cc: Irfan Sayed Sent: Saturday, August 18, 2012 6:50 AM Subject: Re: search and replace On Fri, 17 Aug 2012 18:02:23 -0700 (PDT) Irfan Sayed wrote: > i have string like this : &

Re: search and replace

2012-08-17 Thread Shawn H Corey
On Fri, 17 Aug 2012 18:02:23 -0700 (PDT) Irfan Sayed 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 it: $a =~ s/\Q$

search and replace

2012-08-17 Thread Irfan Sayed
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/; however, the string which i am getting is : $(c:\p4\abc)\convergence\trunk i need output like this : c:\p4\abc\conv

Re: search and replace

2012-08-16 Thread Shawn H Corey
On Thu, 16 Aug 2012 10:55:03 +0200 Gergely Buday 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 or alarm char

Re: search and replace

2012-08-16 Thread Irfan Sayed
Awesome thanks all for reply . got it regards irfan From: midhun To: Rob Coops Cc: Gergely Buday ; Irfan Sayed ; "beginners@perl.org" Sent: Thursday, August 16, 2012 2:41 PM Subject: Re: search and replace The issue is $cs_project = &qu

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 wrote

Re: search and replace

2012-08-16 Thread Rob Coops
On Thu, Aug 16, 2012 at 10:55 AM, Gergely Buday 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 it.

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 stri

search and replace

2012-08-16 Thread Irfan Sayed
hi, i have following code to search single "\" and replace it with "\\" but it is not doing as expected: $csproj_text = "C:\build.txt"; $csproj_text =~ s/\\//g; print "$csproj_text\n"; the output is : "Cuild.txt" instead the output should be : "C:\\build.txt" can someone please suggest, wha

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 dom

Re: search and replace with an array

2012-02-21 Thread Adams Paul
Sent from my LG phone "John W. Krahn" 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 regex

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 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 sam

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: > >

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

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

search and replace with an array

2012-02-20 Thread Chris Stinemetz
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/. I'm not sure if I'm using the best approach. I am getting t

Re: Search and replace w/ ignoring arbitrary characters

2011-08-10 Thread Frank Müller
in f[##o]o(ba##r) ? again, thanks for any ideas and hints, Frank On 9 Aug., 02:34, jwkr...@shaw.ca ("John W. Krahn") wrote: > Frank Müller wrote: > > dear all, > > Hello, > > > i want to make some search and replace within a string where I can > > define a s

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

Search and replace w/ ignoring arbitrary characters

2011-08-08 Thread Frank Müller
dear all, 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 sdkljfhs sjfh sdkj sdjkfh sdjfh

Re: Special characters and variables in search and replace expressions of regexps

2008-12-14 Thread John W. Krahn
Alexei A. Frounze wrote: Here's a sample program to show the problems I'm having with regexps: my $s = "a\tb"; $s contains a three character string, the 'a' character, the TAB character and the 'b' character. my $m1 = "\t"; $m1 contains a single TAB character. my $m2 = "\\t"; # both "\t

Special characters and variables in search and replace expressions of regexps

2008-12-14 Thread Alexei A. Frounze
Here's a sample program to show the problems I'm having with regexps: my $s = "a\tb"; my $m1 = "\t"; my $m2 = "\\t"; # both "\t" and "\\t" are treated specially my $r1 = "\t"; my $r2 = "\\t"; my $s1 = $s; my $s2 = $s; $s1 =~ s/$m1/$r1/; $s2 =~ s/$m1/$r2/; print "\"$s\" =~ s/$m1/$r1/ -> \"$s1\"\n"

Re: search and replace

2008-11-13 Thread [EMAIL PROTECTED]
interactive program to > > do this > > where I input the file name for the search and replace and the file > > name > > for the modified file to be saved. > > > Here is my code. > > Can anyone offer any suggestions? > > Thanks in advance. > > >

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? Th

Re: search and replace

2008-11-13 Thread [EMAIL PROTECTED]
interactive program to > > do this > > where I input the file name for the search and replace and the file > > name > > for the modified file to be saved. > > > Here is my code. > > Can anyone offer any suggestions? > > Thanks in advance. > > >

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 a

Re: search and replace

2008-11-12 Thread Chas. Owens
o > do this > where I input the file name for the search and replace and the file > name > for the modified file to be saved. > > Here is my code. > Can anyone offer any suggestions? > Thanks in advance. > > #!/usr/bin/perl -w > use strict; > > my $input; > my

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 searc

search and replace

2008-11-12 Thread [EMAIL PROTECTED]
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 name for the modified file to be

Re: perl reg. exp. (search and replace)

2008-11-03 Thread Anirban Adhikary
use strict; use warnings; my $string="fsdfsdfsdf fsdfsdfsdf"; my ($a,$b)=split(/\s+/,$string); my $new_string=$a."_".$b; print $new_string."\n"; Regards Anirban Adhikary. On Mon, Nov 3, 2008 at 2:15 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> Hi all, >> > > Hell

Re: perl reg. exp. (search and replace)

2008-11-03 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi all, Hello, I have a string which contains spaces. I need to replace those spaces with underscore, so I have written command like this $string="fsdfsdfsdf fsdfsdfsdf"; chomp($string1 = ($string =~ s/\s+$/_/g)); \s+$ matches one or more of any whitespace characte

perl reg. exp. (search and replace)

2008-11-02 Thread Irfan.Sayed
Hi all, I have a string which contains spaces. I need to replace those spaces with underscore, so I have written command like this $string="fsdfsdfsdf fsdfsdfsdf"; chomp($string1 = ($string =~ s/\s+$/_/g)); print "$string1\n"; but still $string1 is not printing proper result. Result sho

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 opti

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 opti

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 opti

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: > >

Re: search and replace command with output

2008-08-14 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, > >

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

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 usin

search and replace command with output

2008-08-14 Thread samrya
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 it is not possible using any of the switches, I don

Formatting output after search and replace

2008-04-30 Thread melody
I have 2 files one has the input and the other has data that will replace specific string in file 1 eg File 1 - Text| to be replaced Text| to be replaced Text| to be replaced Text| to be replaced Text| to be replaced File 2 - replaced1 replaced2 replaced3 Output --

Re: Formatting output after search and replace

2008-04-29 Thread Chas. Owens
On Tue, Apr 29, 2008 at 6:06 PM, melody <[EMAIL PROTECTED]> wrote: snip > #!/usr/bin/perl > use warnings; > use strict; snip Good, keep this up snip > my @array; > my @replacearray; snip Try to declare your variables where you initialize them. snip > open FHR,'<',"repl.txt"; > open OUT,'

Formatting output after search and replace

2008-04-29 Thread melody
I have 2 files one has the input and the other has data that will replace specific string in file 1 eg File 1 - Text| to be replaced Text| to be replaced Text| to be replaced Text| to be replaced Text| to be replaced File 2 - replaced1 replaced2 replaced3 Output --

Re: Search and Replace

2007-07-14 Thread Mr. Shawn H. Corey
Chas Owens wrote: Eh, writing "join version" was confusing. I am surprised no one called me on the real error: @LIST and @list aren't the same variable. That's because most people who read the mailing list do not run code as presented. You will find that most of the arguments here are about

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 ins

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 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 e

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 a

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 diff

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 0

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
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 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 ob

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; prin

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 = ; 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 ne

RE: Search and Replace

2007-07-13 Thread Joseph L. Casale
$!; So using your syntax escapes me at the moment:) Thanks! jlc -Original 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

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 FILEOU

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 FILEOU

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 P

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

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 replace

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: &

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
: 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. &

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 patte

RE: Search and Replace

2007-07-11 Thread Joseph L. Casale
hanks! jlc -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 t

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
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 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 o

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

Search and Replace

2007-07-11 Thread Joseph L. Casale
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 0.4617566 5.075023 24.2793

RE: Urgent :search and replace

2006-06-22 Thread Nagasamudram, Prasanna Kumar
Re: Urgent :search and replace Hi Ruud, Thanks for the input. I will take care of your inputs next time I post the message. The below solution did not work for me . My file runs almost to 1GB . All I have the string mentioned below. I even tried the following option perl -pi.bak -0777 -e 's/ab=

Re: Urgent :search and replace

2006-06-22 Thread Dr.Ruud
Preethi schreef: > The below solution ... should be above, but most probably snipped. Don't top-post, quote only relevant text, reply on each part that you quote. > did not work for me. My file runs almost to 1GB. What was the error message? Also show us the output of this: perl -wne ' $

Re: Urgent :search and replace

2006-06-22 Thread Preethi
ress "us" as Experts. Just explain your problem. Subject: search and replace on broken lines > I have wired problem , I have search and replace string in very huge > text file . The problem with the string is broken in the differenet > line. > > I'm having a string &#

Re: Urgent :search and replace

2006-06-22 Thread Dr.Ruud
Preethi schreef: Never put "Urgent" in the Subject. Never address "us" as Experts. Just explain your problem. Subject: search and replace on broken lines > I have wired problem , I have search and replace string in very huge > text file . The problem with t

RE: Urgent :search and replace

2006-06-22 Thread Vijayakumaran, Vinod
12:37 PM To: beginners@perl.org Subject: Urgent :search and replace Hi Experts, I have wired problem , I have search and replace string in very huge text file . The problem with the string is broken in the differenet line. I'm having a string 'ab=test1, db=test2,dc=test3' and I

Urgent :search and replace

2006-06-22 Thread Preethi
Hi Experts, I have wired problem , I have search and replace string in very huge text file . The problem with the string is broken in the differenet line. I'm having a string 'ab=test1, db=test2,dc=test3' and I want to replace this with 'ab=chk1,bc=chk2'. This string

Re: Perl script to search and replace a string in a file

2006-06-02 Thread Luke Bakken
>> > perl -pi -e 's/original text/new text/g' * >> >> Error: Can't do inplace edit without backup. > > You need either perl -pi.bak -e ... or an OS upgrade. Windows, > unfortunately, can't manage this. This isn't a Windows problem, this is a Perl on Windows problem that is solely in the Perl i

Re: Perl script to search and replace a string in a file

2006-06-02 Thread Michael Goldshteyn
"Paul Johnson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, Jun 01, 2006 at 08:11:49AM -0500, Michael Goldshteyn wrote: > >> "Ricky Zhou" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> > perl -pi -e 's/original text/new text/g' * >> >> Error: Can't do i

Re: Perl script to search and replace a string in a file

2006-06-01 Thread Paul Johnson
On Thu, Jun 01, 2006 at 08:11:49AM -0500, Michael Goldshteyn wrote: > "Ricky Zhou" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > perl -pi -e 's/original text/new text/g' * > > Error: Can't do inplace edit without backup. You need either perl -pi.bak -e ... or an OS upgrad

Re: Perl script to search and replace a string in a file

2006-06-01 Thread Michael Goldshteyn
"Ricky Zhou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > perl -pi -e 's/original text/new text/g' * Error: Can't do inplace edit without backup. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Perl script to search and replace a string in a file

2006-05-31 Thread Ricky Zhou
On 5/31/06, Nishi Bhonsle <[EMAIL PROTECTED]> wrote: I have the following script that takes in an input file, output file and replaces the string in the input file with some other string and writes out the output file. I want to change the script to traverse through a directory of files ie instea

RE: Perl script to search and replace a string in a file

2006-05-31 Thread Timothy Johnson
Check out the File::Find module. It should come standard with your distribution. -Original Message- From: Nishi Bhonsle [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 31, 2006 2:39 PM To: beginners@perl.org Subject: Perl script to search and replace a string in a file Hi: I have the

Perl script to search and replace a string in a file

2006-05-31 Thread Nishi Bhonsle
Hi: I have the following script that takes in an input file, output file and replaces the string in the input file with some other string and writes out the output file. I want to change the script to traverse through a directory of files ie instead of prompting for input and output files, the sc

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 t

  1   2   3   >