Re: Need help with script
On Thu, Sep 30, 2004 at 04:44:36PM -0700, John W. Krahn wrote: Paul Johnson wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: perl -l -00pe's/\n/\t/;s/\//g;' FILENAME $ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g' BEGIN { $/ = \n; $\ = \000; } In your example you have removed the -0 switch so it is doing something completely different. Oops. Quite right. Must remember not to stop checking my posts until they are correct. Thanks, John. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME perl -l -00pe's/\n/\t/' FILENAME That's pretty slick you guys, he's sure to get an A+ ;) If your teacher requires the quotes to be removed: What if the teacher requires an explanation? O:-) It is my opinion that code should be explained, at least in this list. You're trying to teach people how to fish (and maybe swim). Giving them fish is good, of course, but tell them how you got it :-) That said, nice code :-) perl -l -00pe's/\n/\t/;s/\//g;' FILENAME :) -- José Alves de Castro [EMAIL PROTECTED] http://natura.di.uminho.pt/~jac -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Hi Perlers, On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME perl -l -00pe's/\n/\t/' FILENAME That's pretty slick you guys, he's sure to get an A+ ;) If your teacher requires the quotes to be removed: What if the teacher requires an explanation? O:-) It is my opinion that code should be explained, at least in this list. You're trying to teach people how to fish (and maybe swim). Giving them fish is good, of course, but tell them how you got it :-) That said, nice code :-) perl -l -00pe's/\n/\t/;s/\//g;' FILENAME :) -- José Alves de Castro [EMAIL PROTECTED] http://natura.di.uminho.pt/~jac I'll give it a try. First, it's good to know that the two Perl special variables '$/' and '$\' are the input separator and output separator. By Default, they will be $/ = \n (newline character) and $\ = undef (nothing. No output separator). Now, on the command line, the '-0' option will set the input separator ($/). In the above example, it's setting $/ = 0. Also, in the example, the '-l' will do two things. First, it will automatically chomp() whatever's in '$/', and then it will set the output separator to be whatever the input separator will be. So, specific to our example, first '-l' sets '$\' (output separator) to whatever '$/' is (at this point, it's \n, or a newline). Then, the '-0' switch is setting the $/ = 0 ( or null, or nothing!). OK, next we have '-p' and '-e'. The '-e' tells Perl to read one line (the one after the '-e') and use that as the code to process. The '-p' causes Perl to assume the following code around your code: LINE: while( ) { # your code goes here } continue { print or die -p destination: $!\n; } So, this is going to process whatever files it finds on your command line and then print '$_'! Now, the code that's going into that block is, in our example: s/\n/\t/; s/\//g; So, we get this as the code Perl is running: LINE: while( ) { s/\n/\t/; # Change newlines into tabs s/\//g; # Remove all double-quotes } continue { print or die -p destination: $!\n; } but with the special $/ = 0 as the input separator and $\ = \n as the output separator! There! Am I right? This is fun ... we should do this more often! This taught me a lot. BTW, I found most of these explanations in the 'perldoc perlrun' and 'perldoc perlvar' pages. You can check out continue blocks with 'perldoc -f continue'. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
On Thu, Sep 30, 2004 at 08:00:41AM -0500, Errin Larsen wrote: Hi Perlers, On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: perl -l -00pe's/\n/\t/;s/\//g;' FILENAME It is my opinion that code should be explained, at least in this list. And it normally is. But if someone posts a message saying please do this for me without (apparently) making any effort to do it themselves, then a functioning cryptic one-liner response is a succinct way of saying that as soon as you put a little more effort into this then so will we. So, we get this as the code Perl is running: LINE: while( ) { s/\n/\t/; # Change newlines into tabs s/\//g; # Remove all double-quotes } continue { print or die -p destination: $!\n; } but with the special $/ = 0 as the input separator and $\ = \n as the output separator! There! Am I right? This is fun ... we should do this more often! Pretty close: $ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g' BEGIN { $/ = \n; $\ = \000; } LINE: while (defined($_ = ARGV)) { chomp $_; s/\n/\t/; s///g; } continue { print $_; } -e syntax OK which shows a little confusion over $/ and $\, and an unnecessary \ in the initial program. This taught me a lot. Good :-) -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Need help with script
From: Errin Larsen mailto:[EMAIL PROTECTED] wrote: [snip] : There! Am I right? This is fun ... we should do this : more often! This taught me a lot. That's one advantage of answering questions on a list like this. You learn while researching the answer. Most of my experience with perl comes from researching answers to beginner questions on these lists. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Hi Paul, Thx for the response On Thu, 30 Sep 2004 15:30:06 +0200, Paul Johnson [EMAIL PROTECTED] wrote: SNIP Pretty close: $ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g' BEGIN { $/ = \n; $\ = \000; } LINE: while (defined($_ = ARGV)) { chomp $_; s/\n/\t/; s///g; } continue { print $_; } -e syntax OK which shows a little confusion over $/ and $\, and an unnecessary \ in the initial program. This taught me a lot. Good :-) -- Paul Johnson - [EMAIL PROTECTED] When I run your command line up there, I get the following: # perl -MO=Deparse -l00pe's/\n/\t/;s/\//g' LINE: while (defined($_ = ARGV)) { chomp $_; s/\n/\t/; s///g; } continue { print $_; } -e syntax OK What OS are you running? My '-MO=Deparse' didn't create that BEGIN Block. I'm on Solaris, using Perl 5.6.1. I'm just curious what the difference is. --Errin BTW, I didn't know about the Deparse Pre-Compiler thing! Thanks for pointing it out. It's very handy. Why do you think Perl uses: while( defined( $_ = ARGV ) ) instead of: while( ) Is this example pointing out that the diamond ( ) operator is really a short-cut for 'defined( $_ = ARGV )' ? I'll have to go read about this. What is Perl protecting against by putting that assignment in a defined()? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Paul Johnson wrote: On Thu, Sep 30, 2004 at 08:00:41AM -0500, Errin Larsen wrote: Hi Perlers, On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: perl -l -00pe's/n/t/;s///g;' FILENAME It is my opinion that code should be explained, at least in this list. And it normally is. But if someone posts a message saying please do this for me without (apparently) making any effort to do it themselves, then a functioning cryptic one-liner response is a succinct way of saying that as soon as you put a little more effort into this then so will we. So, we get this as the code Perl is running: LINE: while( ) { s/n/t/; # Change newlines into tabs s///g; # Remove all double-quotes } continue { print or die -p destination: $!n; } but with the special $/ = 0 as the input separator and $ = n as the output separator! There! Am I right? This is fun ... we should do this more often! Pretty close: $ perl -MO=Deparse -l00pe's/n/t/;s///g' BEGIN { $/ = n; $ = 00; } LINE: while (defined($_ = ARGV)) { chomp $_; s/n/t/; s///g; } continue { print $_; } -e syntax OK which shows a little confusion over $/ and $, and an unnecessary in the initial program. This taught me a lot. Good :-) Thanks for your help guys... But the code is performing the logic only for the first set of lines... After the running the above script, the output looks like Object1...tab...Description1 Object2 Description2 Object3 Description3 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
On Thu, Sep 30, 2004 at 11:26:27AM -0500, Errin Larsen wrote: When I run your command line up there, I get the following: # perl -MO=Deparse -l00pe's/\n/\t/;s/\//g' LINE: while (defined($_ = ARGV)) { chomp $_; s/\n/\t/; s///g; } continue { print $_; } -e syntax OK What OS are you running? My '-MO=Deparse' didn't create that BEGIN Block. I'm on Solaris, using Perl 5.6.1. I'm just curious what the difference is. That was on linux, but the important thing here is the perl version. 5.6.1 is old, and if you are looking at the B modules (which Deparse is) it's very old. There have been many improvements (bug fixes) since then. --Errin BTW, I didn't know about the Deparse Pre-Compiler thing! Thanks for pointing it out. It's very handy. Why do you think Perl uses: while( defined( $_ = ARGV ) ) instead of: while( ) Is this example pointing out that the diamond ( ) operator is really a short-cut for 'defined( $_ = ARGV )' ? Yes, exactly that. I'll have to go read about this. What is Perl protecting against by putting that assignment in a defined()? It's protecting against input which evaluates to false, such as the last line of a file which contains only 0 and no newline, for example. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Thanks for your help guys... But the code is performing the logic only for the first set of lines... After the running the above script, the output looks like Object1...tab...Description1 Object2 Description2 Object3 Description3 Can you post EXACTLY what's in the input file for us? I test with the following input file, I called it object.txt: # cat object.txt Object1 Description1 Object2 Description2 Object3 Description3 I run this command line: # perl -l -00pe's/\n/\t/;s/\//g' object.txt Object1 Description1 Object2 Description2 Object3 Description3 It's hard to see the tabs, so I tried one with 2 tabs in it for clarity: # perl -l -00pe's/\n/\t\t/;s/\//g' object.txt Object1 Description1 Object2 Description2 Object3 Description3 So, on my (Solaris 9, Perl 5.6.1) box, it's working. What OS and Perl version are you using and what's your input file look like? --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
I am using Cygwin on Win2K and the version of perl on it is v5.8.0 I am using the same input file, but when I run the command you ran, the output looks like Object1 Description1 Object2 Description2 Object3 Description3 Thanks Errin Larsen wrote: Thanks for your help guys... But the code is performing the logic only for the first set of lines... After the running the above script, the output looks like Object1...tab...Description1 Object2 Description2 Object3 Description3 Can you post EXACTLY what's in the input file for us? I test with the following input file, I called it object.txt: # cat object.txt Object1 Description1 Object2 Description2 Object3 Description3 I run this command line: # perl -l -00pe's/n/t/;s///g' object.txt Object1 Description1 Object2 Description2 Object3 Description3 It's hard to see the tabs, so I tried one with 2 tabs in it for clarity: # perl -l -00pe's/n/tt/;s///g' object.txt Object1 Description1 Object2 Description2 Object3 Description3 So, on my (Solaris 9, Perl 5.6.1) box, it's working. What OS and Perl version are you using and what's your input file look like? --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
On 30 Sep 2004 19:52:31 -, PerlDiscuss - Perl Newsgroups and mailing lists [EMAIL PROTECTED] wrote: I am using Cygwin on Win2K and the version of perl on it is v5.8.0 I am using the same input file, but when I run the command you ran, the output looks like Object1 Description1 Object2 Description2 Object3 Description3 Thanks Hi again, Just to let you know, most on this list will become upset with you if you don't bottom-post. For future reference ... Ok, I've got ActiveState on WinXP, 5.8.4 ... I tried and found that I had the same problems as you. After much playing around, I found it's a quoting problem on the command line (at least, in my case it was). I just don't have a good grasp of quoting rules and precedence in DOS I guess. Here's what I did to make it work on my DOS command line: C:\ perl -l -00pe s/\n/\t/;s/\//g object.txt I basically just removed the single-quotes from around the code in the '-e' option. That gave me the output I was looking for. Try it and let us know. --Errin BTW, anyone have a good reference for DOS quoting rules/precedence? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Hi again, Ok, I've got ActiveState on WinXP, 5.8.4 ... I tried and found that I had the same problems as you. After much playing around, I found it's a quoting problem on the command line (at least, in my case it was). I just don't have a good grasp of quoting rules and precedence in DOS I guess. Here's what I did to make it work on my DOS command line: C: perl -l -00pe s/n/t/;s///g object.txt I basically just removed the single-quotes from around the code in the '-e' option. That gave me the output I was looking for. Try it and let us know. --Errin BTW, anyone have a good reference for DOS quoting rules/precedence? If I remove single quotes, my command kind of hangs..it does not give any output. thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Errin Larsen wrote: Hi Perlers, On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME perl -l -00pe's/\n/\t/' FILENAME That's pretty slick you guys, he's sure to get an A+ ;) If your teacher requires the quotes to be removed: What if the teacher requires an explanation? O:-) It is my opinion that code should be explained, at least in this list. You're trying to teach people how to fish (and maybe swim). Giving them fish is good, of course, but tell them how you got it :-) That said, nice code :-) perl -l -00pe's/\n/\t/;s/\//g;' FILENAME I'll give it a try. First, it's good to know that the two Perl special variables '$/' and '$\' are the input separator and output separator. By Default, they will be $/ = \n (newline character) and $\ = undef (nothing. No output separator). So far so good. :-) Now, on the command line, the '-0' option will set the input separator ($/). In the above example, it's setting $/ = 0. Wrong. Also, in the example, the '-l' will do two things. First, it will automatically chomp() whatever's in '$/', and then it will set the output separator to be whatever the input separator will be. So, specific to our example, first '-l' sets '$\' (output separator) to whatever '$/' is (at this point, it's \n, or a newline). Then, the '-0' switch is setting the $/ = 0 ( or null, or nothing!). perldoc perlrun [snip] -0[octal/hexadecimal] specifies the input record separator ($/) as an octal or hexadecimal number. If there are no digits, the null character is the separator. ^^^ Other switches may precede or follow the digits. For example, if you have a version of find which can print filenames terminated by the null character, you can say this: find . -name '*.orig' -print0 | perl -n0e unlink The special value 00 will cause Perl to slurp files in paragraph mode. ^ The value 0777 will cause Perl to slurp files whole because there is no legal byte with that value. So using the switch -00 is the same as setting the input record separator to paragraph mode or $/ = ''; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Paul Johnson wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: perl -l -00pe's/\n/\t/;s/\//g;' FILENAME $ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g' BEGIN { $/ = \n; $\ = \000; } In your example you have removed the -0 switch so it is doing something completely different. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Please use a more descriptive subject line I have a file with the following format Object1 Description1 Object2 Description Object3 Description I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 Thanks What have you tried, what have you researched, where did you fail? This is not a free script writing service, and your question looks like homework. http://www.catb.org/~esr/faqs/smart-questions.html http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
On Wed, 2004-09-29 at 18:55, PerlDiscuss - Perl Newsgroups and mailing lists wrote: I have a file with the following format Object1 Description1 Object2 Description Object3 Description I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 Thanks perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME HTH Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
Ramprasad A Padmanabhan wrote: On Wed, 2004-09-29 at 18:55, PerlDiscuss - Perl Newsgroups and mailing lists wrote: I have a file with the following format Object1 Description1 Object2 Description Object3 Description I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME perl -l -00pe's/\n/\t/' FILENAME John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Need help with script
I would like the output in the following format object1...tabDescription1 object2...tabDescription2 object3...tabDescription3 perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME perl -l -00pe's/\n/\t/' FILENAME That's pretty slick you guys, he's sure to get an A+ ;) If your teacher requires the quotes to be removed: perl -l -00pe's/\n/\t/;s/\//g;' FILENAME :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response