Re: global substitution with files

2007-08-24 Thread John W. Krahn
Dr.Ruud wrote: Gunnar Hjalmarsson schreef: my $content = do { local $/; <$file> }; That idiom uses an extra buffer, as big as the file. my $content; { local $/; $content = } Or: read( FH, my $content, -s FH ) == -s FH or warn "Could not read the entire file.\n"; John

Re: global substitution with files

2007-08-24 Thread Gunnar Hjalmarsson
Dr.Ruud wrote: Gunnar Hjalmarsson schreef: Dr.Ruud: Gunnar Hjalmarsson: my $content = do { local $/; <$file> }; That idiom uses an extra buffer, as big as the file. my $content; { local $/; $content = } Does it? In that case, why is it mentioned at http://faq.perl.org/perlfa

Re: global substitution with files

2007-08-24 Thread Dr.Ruud
Gunnar Hjalmarsson schreef: > Dr.Ruud: >> Gunnar Hjalmarsson: >>> my $content = do { local $/; <$file> }; >> >> That idiom uses an extra buffer, as big as the file. >> >>my $content; { local $/; $content = } > > Does it? In that case, why is it mentioned at > http://faq.perl.org/perl

Re: global substitution with files

2007-08-24 Thread Gunnar Hjalmarsson
Dr.Ruud wrote: Gunnar Hjalmarsson schreef: my $content = do { local $/; <$file> }; That idiom uses an extra buffer, as big as the file. my $content; { local $/; $content = } Does it? In that case, why is it mentioned at http://faq.perl.org/perlfaq5.html#How_can_I_read_in_an

Re: global substitution with files

2007-08-24 Thread Dr.Ruud
Gunnar Hjalmarsson schreef: > my $content = do { local $/; <$file> }; That idiom uses an extra buffer, as big as the file. my $content; { local $/; $content = } -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mai

Re: global substitution with files

2007-08-23 Thread Gunnar Hjalmarsson
Jeff Pang wrote: 2007/8/24, Gunnar Hjalmarsson <[EMAIL PROTECTED]>: Yoyoyo Yoyoyoyo wrote: I have a file that I need to use the substitute operator on to get rid of spaces, and apostrophes and such. The only way I can think of doing it is this: 1. Open the file and go through it one line at

Re: global substitution with files

2007-08-23 Thread Jeff Pang
2007/8/24, Gunnar Hjalmarsson <[EMAIL PROTECTED]>: > Yoyoyo Yoyoyoyo wrote: > > I have a file that I need to use the substitute operator on to get > > rid of spaces, and apostrophes and such. The only way I can think of > > doing it is this: > > > > 1. Open the file and go through it one line at

Re: global substitution with files

2007-08-23 Thread Jeff Pang
Use one-liner Perl to do the replacement without calling 'open' and '<>' and 'close' directly. $ perl -pi.bak -e 's/abc/def/' file.txt 2007/8/24, Yoyoyo Yoyoyoyo <[EMAIL PROTECTED]>: > Hi all, > > I have a file that I need to use the substitute operator on to get rid of > spaces, and apostrophes

Re: global substitution with files

2007-08-23 Thread Gunnar Hjalmarsson
Yoyoyo Yoyoyoyo wrote: I have a file that I need to use the substitute operator on to get rid of spaces, and apostrophes and such. The only way I can think of doing it is this: 1. Open the file and go through it one line at a time with the diamond operator. 2. Make the substitutions on the

global substitution with files

2007-08-23 Thread Yoyoyo Yoyoyoyo
Hi all, I have a file that I need to use the substitute operator on to get rid of spaces, and apostrophes and such. The only way I can think of doing it is this: 1. Open the file and go through it one line at a time with the diamond operator. 2. Make the substitutions on the $_ variable and

Regular expression - Global substitution

2006-03-13 Thread Baskaran Sankaran
Hi Group, Am working with Unicode (UTF8 coded) stuff and facing problem with regular expression. s/(\p{HinNumerals})\s+($tokenize_string)+\s+(\p{HinNumerals})/$1$2$3/g; and, my HinNumerals is defined as, sub HinNumerals { return <

RE: global substitution

2002-01-07 Thread Scott
At 05:01 PM 1/7/2002 -0500, Jeff 'japhy' Pinyan wrote: >Anyway, you want s/[.:-]+//g, or something to that effect. Be warned, >though, that [.-:] is NOT what you want, since that means "characters from >'.' to '-'", which is the following list: > . / 0 1 2 3 4 5 6 7 8 9 : And that was my newbi

RE: global substitution

2002-01-07 Thread Jeff 'japhy' Pinyan
On Jan 7, Scott said: >At 04:12 PM 1/7/2002 -0500, Jeff 'japhy' Pinyan wrote: >> >>So s/[.-]+//g, or perhaps tr/.-//d; >> >I might have worded it wrong, I need to replace a period (.) and a dash >> >(-), they may not be together ie (.-), they could be in any of the >> >fields in the array. Some

RE: global substitution

2002-01-07 Thread Scott
At 04:12 PM 1/7/2002 -0500, Jeff 'japhy' Pinyan wrote: > >>So s/[.-]+//g, or perhaps tr/.-//d; > >I might have worded it wrong, I need to replace a period (.) and a dash > >(-), they may not be together ie (.-), they could be in any of the > >fields in the array. Some of the fields are numbers (5

RE: global substitution

2002-01-07 Thread Jeff 'japhy' Pinyan
On Jan 7, McCollum, Frank said: >so, if a character is inside of square brackets [], then perl recognizes >that it is part of a character class and never uses it as a quantifier or >special character?? Very few characters need escaping a char class. ] does (unless it's the first character of th

RE: global substitution

2002-01-07 Thread Jeff 'japhy' Pinyan
On Jan 7, Scott said: >At 04:04 PM 1/7/2002 -0500, Jeff 'japhy' Pinyan wrote: >>No, the [...] is needed. Otherwise, you're removing all occurrences of >>the string ".-" which is not what was intended. >> >>So s/[.-]+//g, or perhaps tr/.-//d; > >I might have worded it wrong, I need to replace a p

RE: global substitution

2002-01-07 Thread McCollum, Frank
4:04 PM To: McCollum, Frank Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: global substitution On Jan 7, McCollum, Frank said: >$record =~ s/[\.\-]//g; Neither of those two slashes are needed. >if it is a '.' or a '-' replace it with nothing. >Actually, I don't

RE: global substitution

2002-01-07 Thread Scott
At 04:04 PM 1/7/2002 -0500, Jeff 'japhy' Pinyan wrote: >No, the [...] is needed. Otherwise, you're removing all occurrences of >the string ".-" which is not what was intended. > >So s/[.-]+//g, or perhaps tr/.-//d; I might have worded it wrong, I need to replace a period (.) and a dash (-), the

Re: global substitution

2002-01-07 Thread Jose Vicente
I think: foreach $value(@fields) { $value = s/\.\-//g; } - Original Message - From: "Scott" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, January 07, 2002 4:02 PM Subject: global substitution > Hi all: > > I have two files that I am r

RE: global substitution

2002-01-07 Thread Jeff 'japhy' Pinyan
On Jan 7, McCollum, Frank said: >$record =~ s/[\.\-]//g; Neither of those two slashes are needed. >if it is a '.' or a '-' replace it with nothing. >Actually, I don't even think the [] is necessary, so it could just be: >$record =~ s/\.\-//g; No, the [...] is needed. Otherwise, you're removin

RE: global substitution

2002-01-07 Thread McCollum, Frank
2 PM To: [EMAIL PROTECTED] Subject: global substitution Hi all: I have two files that I am reading into an array, I want to substitute a period and a dash, actually I want to remove them completely. Here is my code: while (my $record = ){ my $policies = ; my @fields = split( /\t/, $record );

global substitution

2002-01-07 Thread Scott
Hi all: I have two files that I am reading into an array, I want to substitute a period and a dash, actually I want to remove them completely. Here is my code: while (my $record = ){ my $policies = ; my @fields = split( /\t/, $record ); my @policies = split( /\t/, $policies ); When I need a r