Robert Citek wrote:
> 
> Hello Zeus,
> 
> At 11:55 AM 1/29/2003 -0500, Zeus Odin wrote:
> >An even shorter version of yours is:
> >-------------------------
> >my @a;
> >while(<DATA>){
> >   next unless /=/ && chomp;
> >   push @a, split /=/, $_, 2;
> >}
> >print "$_\n" for @a;
> >-------------------------
> 
> This is even shorter, eliminates all uses of variables, and slurps in the
> data all at once:
> 
> #!/usr/bin/perl -w0
> print join("\n", map({split(/=/,$_,2)} grep(/=/, split(/\n/, <DATA>))));
> 
> The only thing it does not do is use the regex.  Is the regex a requirement?

It is not _quite_ the same.  Your version uses "\0" as the input record
separator (-0 in perlrun) and doesn't print a newline after the last
record (join "\n").  If you want to slurp the whole file use the -0777
switch or undefine $/.  But why slurp the file and then split it on
newlines?

This will do it correctly:

perl -ne's/=/\n/&&print' yourfile.txt

Or in a program:

while ( <DATA> ) {
    s/=/\n/ && print;
    }




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to