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

Re: Search one character against one string

2014-03-13 Thread Uri Guttman
On 03/12/2014 05:14 AM, Alex Chiang wrote: Thanks for your reply. I know the built-in index function, but I just can't figure out why it gives me the answer I don't expect :D you shouldn't expect some answer without checking the documentation. index is well documented so you must be looking

Re: Search one character against one string

2014-03-13 Thread Alex Chiang
Thanks for your reply. I know the built-in index function, but I just can't figure out why it gives me the answer I don't expect :D --- Regards ! Alex Chiang

Re: Search one character against one string

2014-03-13 Thread Alex Chiang
Thanks all, and thanks Nathan for your detailed explanation. Now I know the list got flattened before passing into subroutine. Cheers. --- Regards ! Alex Chiang

Re: Search one character against one string

2014-03-12 Thread Nathan Hilterbrand
First: @_[0] is "legit", in that it is a 1 element slice of the array @_.. but most likely is not at all what you really want. When an array is passed as a parameter to a subroutine in perl, it is "unrolled". In other words, each element of the array is passed as a single parameter. In ord

Re: Search one character against one string

2014-03-12 Thread Jing Yu
Is @_[0] even legit? On 12 Mar 2014, at 04:58, Alex Chiang wrote: > Hi there, > > I got a wired bug with the following perl script: > > 35 # return non-negative value if particular character is in string array > 36 # otherwise, return -1 > > sub is_in_string { > 38 # @s: string array, $c

Re: Search one character against one string

2014-03-12 Thread Robert Wohlfarth
On Tue, Mar 11, 2014 at 11:58 PM, Alex Chiang wrote: > sub is_in_string { > 38 # @s: string array, $c: character > 39 # passing array into sub > 40 my @s = @_[0]; my $c = $_[1]; > 44 my @ar = qw(t d s); > 45 my $c = "d"; > 46 my $res = &is_in_string( @ar, $c); This is a good example of how

Re: Search one character against one string

2014-03-12 Thread Bob goolsby
Mornin' -- Take a look at the index() function, unless you have a real need to reinvent one of the Perl builtin functions. (i.e. your home work assignment from your tescher demands it.) B On Tue, Mar 11, 2014 at 9:58 PM, Alex Chiang wrote: > Hi there, > > I got a wired bug with the following

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

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$

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

Re: search scalers of an array in another file

2012-06-21 Thread John W. Krahn
Wang, Li wrote: Dear list members Hello, I am a very beginner of perl programming. Welcome to the Perl beginners mailing list. I am trying to write a script to search all scalers of one array (geneIDFile) in another file (annotationFile). If it is found and matched, output the whole lin

Re: search scalers of an array in another file

2012-06-21 Thread Jim Gibson
On Jun 21, 2012, at 4:47 PM, Wang, Li wrote: > Dear list members > > I am a very beginner of perl programming. > I am trying to write a script to search all scalers of one array (geneIDFile) > in another file (annotationFile). If it is found and matched, output the > whole line of the annotat

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

Re: Search and replace w/ ignoring arbitrary characters

2011-08-10 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 useful

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 sdkl

Re: search replace saved to a variable

2009-09-03 Thread Jenda Krynicky
From: Noah Garrett Wallach > okay a step further - is there a way to make the following a one liner? > > (my $filename_cmd = $cmd[-1]) =~ s/\|//g; > $filename_cmd =~ s/\s+/\./g; > $filename_cmd =~ s/save.*//g; There's no point in making it a one liner. Plus anything may be writen

Re: Search single scalar variable for Multiple matches

2009-09-02 Thread Uri Guttman
> "NGW" == Noah Garrett Wallach writes: NGW> what is the cleanest way to search a multi-line single scalar variable NGW> full of configuration information. I want match on specific criteria NGW> and then save a portion of the matched information in a hash or hashes NGW> variable.

Re: search replace saved to a variable

2009-09-02 Thread Uri Guttman
> "NGW" == Noah Garrett Wallach writes: NGW> Jim Gibson wrote: >> At 7:22 PM -0700 9/2/09, Noah Garrett Wallach wrote: >>> Hi there, >>> >>> what is the way to collapse this search/replace to one line? >>> >>> my $filename_cmd = $cmd[-1]; >>> my $filename_cmd =~ s/\s/\./;

Re: search replace saved to a variable

2009-09-02 Thread Noah Garrett Wallach
Jim Gibson wrote: At 7:22 PM -0700 9/2/09, Noah Garrett Wallach wrote: Hi there, what is the way to collapse this search/replace to one line? my $filename_cmd = $cmd[-1]; my $filename_cmd =~ s/\s/\./; (my $filename_cmd = $cmd[-1]) =~ s/\s/\./; thanks, okay a step further -

Re: search replace saved to a variable

2009-09-02 Thread Jim Gibson
At 7:22 PM -0700 9/2/09, Noah Garrett Wallach wrote: Hi there, what is the way to collapse this search/replace to one line? my $filename_cmd = $cmd[-1]; my $filename_cmd =~ s/\s/\./; (my $filename_cmd = $cmd[-1]) =~ s/\s/\./; -- Jim Gibson jimsgib...@gmail.com -- To unsubscribe

Re: Search in LDAP using Perl

2009-08-07 Thread Juan Pablo Feria Gomez
> I m working on Net::LDAP module in perl to manage ldap database, > > but i dont know how can i get all the uid's and names of the groups, > i have try the Search function of Net::LDAP but still not able to get it, > Alpesh, take a look on http://www.linuxjournal.com/article/7086 Is your LDAP di

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 th

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]
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 th

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

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

Re: search value in array

2008-08-28 Thread Rob Dixon
Irfan J Sayed (isayed) wrote: > Hi All, > > I want to search whether specific value/data is there are not in Array. > For example lets say i have array as follows. > > @test = (1,2,3,4,5); > $rel1=4; > > I need to check whether 4 is there or not. I have one method as follows. > > if (grep /

Re: search value in array

2008-08-28 Thread Raymond Wan
Hi Irfan, Irfan J Sayed (isayed) wrote: if (grep /^$rel1$/, @test) { print "Result = $rel1\n"; } but i think this is not the proper way because if i use grep then it would be a platform dependant. The grep you are using is not the grep provided by the operating system, but the

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

Re: Search for IP address and delete from file

2007-10-18 Thread Matthew Whipple
> > > mv $TMP_FILE $FILE_NAME > > > > Be careful, the 192.168.0.0 can also match a line with 192.168.010 in > > it. See also the -F option of grep. > > > > -- > > Affijn, Ruud > > > > "Gewoon is een tijger." > > > > Good point, bad example (although natural continuation of previous > discuss

Re: Search for IP address and delete from file

2007-10-18 Thread Matthew Whipple
On Fri, 2007-10-19 at 01:55 +0200, Dr.Ruud wrote: > yitzle schreef: > > > If you are on a Linux machine, it might just be easier > > to use the grep command with a shell script. > > > > FILE_NAME="./log" > > TMP_FILE="./tmp" > > IP_TO_REMOVE="192.168.0.0|192.168.0.255" > > > > COUNT=`grep $IP_TO_R

Re: Search for IP address and delete from file

2007-10-18 Thread Dr.Ruud
yitzle schreef: > If you are on a Linux machine, it might just be easier > to use the grep command with a shell script. > > FILE_NAME="./log" > TMP_FILE="./tmp" > IP_TO_REMOVE="192.168.0.0|192.168.0.255" > > COUNT=`grep $IP_TO_REMOVE $FILE_NAME | wc -l` > echo "The IPs occur $COUNT times" > > grep

Re: Search for IP address and delete from file

2007-10-17 Thread Phillip Gonzalez
FreeBSD, and that's actually what I ended up doing basically using cat and grep -v. Thanks, On Oct 17, 2007, at 9:14 PM, yitzle wrote: If you are on a Linux machine, it might just be easier to use the grep command with a shell script. FILE_NAME="./log" TMP_FILE="./tmp" IP_TO_REMOVE="192.16

Re: Search for IP address and delete from file

2007-10-17 Thread yitzle
If you are on a Linux machine, it might just be easier to use the grep command with a shell script. FILE_NAME="./log" TMP_FILE="./tmp" IP_TO_REMOVE="192.168.0.0|192.168.0.255" COUNT=`grep $IP_TO_REMOVE $FILE_NAME | wc -l` echo "The IPs occur $COUNT times" grep -v $IP_TO_REMOVE $FILE_NAME > $TMP_

Re: Search for IP address and delete from file

2007-10-17 Thread Jeff Pang
On 10/18/07, Phillip Gonzalez <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to search a .txt file for matching ip addresses. I then want to > delete those ip >addresses. > The better way for finding an IP from given list is to use Net::IP module from CPAN rather than using regex I think. -- T

Re: Search for IP address and delete from file

2007-10-17 Thread Phillip Gonzalez
They have all been helpful. Thanks, On Oct 17, 2007, at 4:40 PM, Matthew Whipple wrote: Matthew Whipple wrote: yitzle wrote: Take a look at the grep function http://perldoc.perl.org/functions/grep.html Also of potential use is the qr// quote operator: http://perldoc.perl.org/perlop.html#

Re: Search for IP address and delete from file

2007-10-17 Thread Matthew Whipple
Matthew Whipple wrote: > yitzle wrote: > >> Take a look at the grep function >> http://perldoc.perl.org/functions/grep.html >> >> Also of potential use is the qr// quote operator: >> http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators >> >> This lets you do: >> >> my $ip_search = qr/

Re: Search for IP address and delete from file

2007-10-17 Thread Matthew Whipple
yitzle wrote: > Take a look at the grep function > http://perldoc.perl.org/functions/grep.html > > Also of potential use is the qr// quote operator: > http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators > > This lets you do: > > my $ip_search = qr/$ip_string/; > my @lines_with_ip = grep

Re: Search for IP address and delete from file

2007-10-17 Thread yitzle
Take a look at the grep function http://perldoc.perl.org/functions/grep.html Also of potential use is the qr// quote operator: http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators This lets you do: my $ip_search = qr/$ip_string/; my @lines_with_ip = grep /$ip_search/, @raw_data; # or

Re: search replace one liner problem

2007-10-09 Thread jrpfinch
Thanks very much - this works Jon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: search replace one liner problem

2007-09-17 Thread John W. Krahn
jrpfinch wrote: I would like to execute the following regex on a file: s/(\$Revision:\s+)(\d+\.\d+)(\s+\$.+use constant VERSION\s+=> ")(.+?) (")/$1$2$3Revision $2$5/gs I am doing this in bash as follows: REGEX='s/(\$Revision:\s+)(\d+\.\d+)(\s+\$.+use constant VERSION\s+=> ") (.+?)(")/$1$2$3Rev

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 ju

Re: search POD about AUTOLOAD

2006-09-21 Thread chen li
--- Jeff Pang <[EMAIL PROTECTED]> wrote: > > >I want to read some information about AUTOLOAD in > POD. > > Hi, > > Got these pieces from Schwartz's book and hope it > helps. Hi Jeff, Thank you very much, Li __ Do You Yahoo!? Tired of spam? Ya

Re: search POD about AUTOLOAD

2006-09-21 Thread chen li
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > > I want to read some information about AUTOLOAD in > POD. > > But I get nothing when I type "perldoc -f/-q > > AUTOLOAD". > > Any comments? > > perlsub has an "Autoloading" section: > > perldoc perlsub > > Also the "AUTOLOAD: Proxy Methods" s

  1   2   3   4   >