> Programming Languages > Perl
Various Topics Home

Perl



Perl Programming Languages the antichomp


Default the antichomp

Is there a better way to it than this?

$_ .= "\n" for @ARGV;

wana
Default Re: the antichomp

(wana) wrote in news:bf0b47ca.0411170715.2aa1d853
@posting.google.com:

> Is there a better way to it than this?
>
> $_ .= "\n" for @ARGV;


Of course. Read perldoc -f chomp.

Sinan
Default Re: the antichomp

>>>>> "w" == wana <> writes:

w> Is there a better way to it than this?
w> $_ .= "\n" for @ARGV;

s/for/x/ ;

uri

--
Uri Guttman ------
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ----------------------------
Default Re: the antichomp

>>>>> "ASU" == A Sinan Unur <> writes:

ASU> (wana) wrote in news:bf0b47ca.0411170715.2aa1d853
ASU> @posting.google.com:

>> Is there a better way to it than this?
>>
>> $_ .= "\n" for @ARGV;


ASU> Of course. Read perldoc -f chomp.

and how would chomp append newlines?

uri

--
Uri Guttman ------
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ----------------------------
Default Re: the antichomp

Uri Guttman <> wrote in
news::

>>>>>> "ASU" == A Sinan Unur <> writes:

>
> ASU> (wana) wrote in
> news:bf0b47ca.0411170715.2aa1d853 ASU> @posting.google.com:
>
> >> Is there a better way to it than this?
> >>
> >> $_ .= "\n" for @ARGV;

>
> ASU> Of course. Read perldoc -f chomp.
>
> and how would chomp append newlines?


It would not. But it would explain what one needs to do to write an
'antichomp'.

chomp VARIABLE
chomp( LIST )
chomp

This safer version of "chop" removes any trailing string
that corresponds to the current value of $/ (also known
as $INPUT_RECORD_SEPARATOR in the "English" module). It
returns the total number of characters removed from all
its arguments.

So, "the antichomp" would have to do the opposite of what chomp does,
wouldn't it?

Sinan.
Default Re: the antichomp

Uri Guttman <> wrote in
news::

>>>>>> "w" == wana <> writes:

>
> w> Is there a better way to it than this?
> w> $_ .= "\n" for @ARGV;
>
> s/for/x/ ;
>
> uri


I am confused.

use strict;
use warnings;

$_ .= "\n" x @ARGV;

print @ARGV;
__END__

D:\Home> perl t.pl 1 2 3 4 5
12345

OTOH:

use strict;
use warnings;

$_ .= "\n" for @ARGV;

print @ARGV;
__END__

D:\Home> perl t.pl 1 2 3 4 5
1
2
3
4
5

What am I missing?

Sinan.
Default Re: the antichomp

A. Sinan Unur wrote:

> What am I missing?


A definition of what exactly the OP wants to accomplish.

Default Re: the antichomp

>>>>> "ASU" == A Sinan Unur <> writes:

ASU> Uri Guttman <> wrote in
ASU> news::

>>>>>>> "ASU" == A Sinan Unur <> writes:

>>
>> >> $_ .= "\n" for @ARGV;

ASU> Of course. Read perldoc -f chomp.
>>
>> and how would chomp append newlines?


ASU> It would not. But it would explain what one needs to do to write an
ASU> 'antichomp'.

ASU> So, "the antichomp" would have to do the opposite of what chomp does,
ASU> wouldn't it?

but that isn't an antichomp. it is appending a newline it over and over
to a single string. and writing an antichomp for such a simple op makes
little sense. see my other post for a better solution.

uri
Default Re: the antichomp

>>>>> "ASU" == A Sinan Unur <> writes:

ASU> Uri Guttman <> wrote in
ASU> news::

>>>>>>> "w" == wana <> writes:

>>

w> Is there a better way to it than this?
w> $_ .= "\n" for @ARGV;
>>
>> s/for/x/ ;
>>
>> uri


ASU> I am confused.

untested as always. must have been too late at night. i didn't see the
$_ being aliased to the elements of @ARGV.

uri
Default Re: the antichomp

On Wed, 17 Nov 2004 07:15:55 -0800, wana wrote:

> Is there a better way to it than this?
>
> $_ .= "\n" for @ARGV;


Well a bit shorter and perhaps more in a sense of antichomp might be
$_ .= $/ for @ARGV;

However, that fails to do something sensful if $/ contains e.g. a
reference to a number, but whenever $/ contains a simple line ending
string, that antichomp variation would add what chomp would have removed
perhaps before.


Greetings,
Janek

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0