---------- Forwarded message ----------
From: Robert Citek <[EMAIL PROTECTED]>
Date: Jan 8, 2008 9:24 AM
Subject: Re: avoid using a temporary variable
To: "Chas. Owens" <[EMAIL PROTECTED]>

On Jan 8, 2008 8:59 AM, Chas. Owens <[EMAIL PROTECTED]> wrote:
> On Jan 7, 2008 6:59 PM, Robert Citek <[EMAIL PROTECTED]> wrote:
> > How can I get rid of the @foo?
> >
> > This does what I want, but uses the "temporary" variable @foo:
> >
> > $ ls | perl -e '@foo=<>; chomp @foo ; print join(" ", @foo)'
> >
> > This eliminates the temporary variable but doesn't work:
> >
> > $ ls | perl -e 'print join(" ", chomp(<>))'
> >
> > Thanks in advance.
> >
> > Regards,
> > - Robert
>
> It looks like you are trying to turn this
>
> foo
> bar
> baz
>
> into this
>
> foo bar baz
>
> A much better way is this
>
> perl -pe 's/\n/ /';

That would be a better perl way if I was just trying to concatenate a
list of items.  If I was, an even better way would be to substitue
xargs for perl:

$ ls | xargs

What I really want to know is if there's a way to eliminate the
temporary variable.  If not, that's fine.  I was just wondering if
there's something I'm overlooking.  Come to think of it, maybe I could
use map.

Regards,
- Robert

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to