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<...tab....>Description1
object2<...tab....>Description2
object3<...tab....>Description3

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>




              • ... Errin Larsen
              • ... Paul Johnson
              • ... PerlDiscuss - Perl Newsgroups and mailing lists
              • ... Errin Larsen
              • ... PerlDiscuss - Perl Newsgroups and mailing lists
              • ... Errin Larsen
              • ... PerlDiscuss - Perl Newsgroups and mailing lists
              • ... John W. Krahn
              • ... Paul Johnson
            • RE: ... Charles K. Clarkson
            • Re: ... John W. Krahn
  • Re: Need help with script Wiggins d Anconia

Reply via email to