Warning: no fun :(

next doesn't skip the continue block where the print is done. Instead you
could:
perl -pe
$_="" if $. < 2;

You have materially changed the substitution
before: "|" -> ""
yours:  "|" -> " "

the effect of 4) is to mean that "\t\t" -> "| " and "\tA" -> "\tA. No idea
why this is being done.

Greg

-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 01, 2004 5:12 AM
To: Fun with Perl
Subject: Re: Shortening a script, but aiming for efficiency


Jose Alves de Castro wrote:
> To make it short: I have a small filter that I'd like to keep as compact
>  as possible, while not losing efficiency.
> 
> How it works:
> 
> 1) ignore the first line (it's a header line)
> 2) if a line ends in a tab, remove that character
> 3) replace all tabs with pipes
> 4) if the line now ends in a pipe, add a space at the end
> 
> This all looks pretty easy, right?

Change that to three steps:

1) ignore the first line (it's a header line)
2) replace all tabs with pipes
3) if a line ends in a pipe, change it to a space.

Even easier.


> So, here's an attempt:
> 
> #!/usr/bin/perl -lwn
> use strict;
> 
> $. - 1 || next;
> s/\t$//;
> y/\t/|/;
> s/\|$/ /;
> print;

#!/usr/bin/perl -lwp
use strict;

$. - 1 || next;
y/\t/|/;
s/\|$/ /;



John
-- 
use Perl;
program
fulfillment


------------------------------------------------------------------------------
This message is intended only for the personal and confidential use of the designated 
recipient(s) named above.  If you are not the intended recipient of this message you 
are hereby notified that any review, dissemination, distribution or copying of this 
message is strictly prohibited.  This communication is for information purposes only 
and should not be regarded as an offer to sell or as a solicitation of an offer to buy 
any financial product, an official confirmation of any transaction, or as an official 
statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or 
error-free.  Therefore, we do not represent that this information is complete or 
accurate and it should not be relied upon as such.  All information is subject to 
change without notice.

Reply via email to