Re: Text munging problem

2007-04-07 Thread D. Bolliger
John W. Krahn am Samstag, 7. April 2007 01:05: > D. Bolliger wrote: > > Chas Owens am Freitag, 6. April 2007 13:27: [snip > $ perl -e' > use Benchmark q[cmpthese]; > my $wordlist = qx[cat /usr/share/dict/words]; > cmpthese -10, { > twomaps => q{ join " ", map ucfirst, map lc, split " ", $wordli

Re: Text munging problem

2007-04-07 Thread Glenn Booth
Hi, Chas Owens wrote: Why shift and unshift? Just use a for loop: I was trying to constrain any replacements to just the two text fields, and to actively ignore all others - I should have made that clearer in the original post. In other words, if the line of text was this: 0097138 | BOOK T

Re: Text munging problem

2007-04-07 Thread Glenn Booth
Hi, So it's true... there really is more than one way to do it. Thanks for all the answers - I'm learning something; mostly that I was making it way too complicated, and that my regular expressions suck. Thanks all. Regards, Glenn. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional

Re: Text munging problem

2007-04-06 Thread John W. Krahn
D. Bolliger wrote: > Chas Owens am Freitag, 6. April 2007 13:27: >>On 4/6/07, D. Bolliger <[EMAIL PROTECTED]> wrote: >> >>>$ perl -nle 'print join " ", map ucfirst, map lc, split' < in.txt > >>>out.txt >>There is no need to have multiple maps and the @ARGV/<> trick handles >>files as well as stdin,

Re: Text munging problem

2007-04-06 Thread D. Bolliger
Chas Owens am Freitag, 6. April 2007 13:27: > On 4/6/07, D. Bolliger <[EMAIL PROTECTED]> wrote: > > > $ perl -nle 'print join " ", map ucfirst, map lc, split' < in.txt > > > out.txt > > There is no need to have multiple maps and the @ARGV/<> trick handles > files as well as stdin, so there is no ne

Re: Text munging problem

2007-04-06 Thread Chas Owens
On 4/6/07, oryann9 <[EMAIL PROTECTED]> wrote: $field =~ s/\b(.)(.*?)\b/\u$1\L$2/g; $record .= "$field|"; ** Is this regex s/\b(.)(.*?)\b/ saying boundry between any character zero or more times in $1 up to everything else non-greedy end word boundry in $2 sort of confus

Re: Text munging problem

2007-04-06 Thread oryann9
$field =~ s/\b(.)(.*?)\b/\u$1\L$2/g; $record .= "$field|"; ** Is this regex s/\b(.)(.*?)\b/ saying boundry between any character zero or more times in $1 up to everything else non-greedy end word boundry in $2 sort of confused since your end goal is to CAPS first letter i

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Chas Owens
On 4/6/07, Jeff Pang <[EMAIL PROTECTED]> wrote: > >So, if I put a filehandle in the diamond, instead of empty diamond, >does that mean that the first would operate line by line and the >second would pull the whole file into memory? > When the diamond(<>) is appeared with while(),it means you re

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Chas Owens
On 4/6/07, Jeni Zundel <[EMAIL PROTECTED]> wrote: So, if I put a filehandle in the diamond, instead of empty diamond, does that mean that the first would operate line by line and the second would pull the whole file into memory? No, both while loops read line by line. The difference is where t

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeff Pang
> >So, if I put a filehandle in the diamond, instead of empty diamond, >does that mean that the first would operate line by line and the >second would pull the whole file into memory? > When the diamond(<>) is appeared with while(),it means you read the file line by line. ig,while(){ .. } an

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Chas Owens
On 4/6/07, Jeni Zundel <[EMAIL PROTECTED]> wrote: What is the difference between: a. while(defined(my $line = <>)) ... and b. while(<>) snip while (<>) {} is shorthand for while (defined ($_ = <>)) {} The biggest diff

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeni Zundel
So, if I put a filehandle in the diamond, instead of empty diamond, does that mean that the first would operate line by line and the second would pull the whole file into memory? Thanks much, Jen On Apr 6, 2007, at 9:31 AM, Jeff Pang wrote: : Re: Text munging problem: question on while

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeff Pang
: Re: Text munging problem: question on while loop differences > >What is the difference between: > >a. while(defined(my $line = <>)) ... > >and > >b. while(<>) Hello, When you say "

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeni Zundel
What is the difference between: a. while(defined(my $line = <>)) ... and b. while(<>) On Apr 6, 2007, at 7:52 AM, Rob Dixon wrote: Why shift and unshift? Just use a for loop: #!/usr

Re: Text munging problem

2007-04-06 Thread Rob Dixon
Chas Owens wrote: On 4/5/07, Glenn Booth <[EMAIL PROTECTED]> wrote: snip My failed approach so far: "While" loop to read file line by line "Split" each line using delimiter (pipe in this case) Put the text fields into an array "Shift" each element out of the array Run a regex to upper case the

Re: Text munging problem

2007-04-06 Thread Chas Owens
On 4/6/07, D. Bolliger <[EMAIL PROTECTED]> wrote: snip $ perl -nle 'print join " ", map ucfirst, map lc, split' < in.txt > out.txt snip There is no need to have multiple maps and the @ARGV/<> trick handles files as well as stdin, so there is no need to use < perl -lne 'print join " ", map { uc

Re: Text munging problem

2007-04-06 Thread D. Bolliger
Glenn Booth am Donnerstag, 5. April 2007 23:10: > Hi All, Hi Glenn > I'm a two-week perl newbie, trying to get my head around text > handling. I keep getting sent badly formatted text files, which > I have to 'repair' so that I can use them to feed an Oracle > database. They are typically a few t

Re: Text munging problem

2007-04-06 Thread Chas Owens
On 4/5/07, Glenn Booth <[EMAIL PROTECTED]> wrote: snip My failed approach so far: "While" loop to read file line by line "Split" each line using delimiter (pipe in this case) Put the text fields into an array "Shift" each element out of the array Run a regex to upper case the first character Shi

Re: Text munging problem

2007-04-06 Thread Seanie
Glenn Booth wrote: > I need to sort out the cases of the text fields (BOOK TITLE) > and ( a book about cats ) and render them to "Title Case" (first > character upper case for each word). > Anyone have an elegant way? ucfirst() does what you want: echo "hello world" | perl -ne 'print join " ", ma

Text munging problem

2007-04-05 Thread Glenn Booth
Hi All, I'm a two-week perl newbie, trying to get my head around text handling. I keep getting sent badly formatted text files, which I have to 'repair' so that I can use them to feed an Oracle database. They are typically a few thousand lines long. The files generally arrive in a format like th