> Programming Languages > Perl
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on Perl



Perl - "the antichomp" in Programming Languages


Old 11-17-2004   #1
....
 
Default the antichomp

Is there a better way to it than this?

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

wana
 
Old 11-17-2004   #2
.. ..n.. ....
 
Default Re: the antichomp

ioneabu@yahoo.com (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
 
Old 11-17-2004   #3
..i ..ttm..
 
Default Re: the antichomp

>>>>> "w" == wana <ioneabu@yahoo.com> writes:

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

s/for/x/ ;

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Old 11-17-2004   #4
..i ..ttm..
 
Default Re: the antichomp

>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:

ASU> ioneabu@yahoo.com (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 ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Old 11-17-2004   #5
.. ..n.. ....
 
Default Re: the antichomp

Uri Guttman <uri@stemsystems.com> wrote in
news:x765445uy1.fsf@mail.sysarch.com:

>>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:

>
> ASU> ioneabu@yahoo.com (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.
 
Old 11-17-2004   #6
.. ..n.. ....
 
Default Re: the antichomp

Uri Guttman <uri@stemsystems.com> wrote in
news:x7is845vlh.fsf@mail.sysarch.com:

>>>>>> "w" == wana <ioneabu@yahoo.com> 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.
 
Old 11-17-2004   #7
..o.. ..y..
 
Default Re: the antichomp

A. Sinan Unur wrote:

> What am I missing?


A definition of what exactly the OP wants to accomplish.

 
Old 11-17-2004   #8
..i ..ttm..
 
Default Re: the antichomp

>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:

ASU> Uri Guttman <uri@stemsystems.com> wrote in
ASU> news:x765445uy1.fsf@mail.sysarch.com:

>>>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> 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
 
Old 11-17-2004   #9
..i ..ttm..
 
Default Re: the antichomp

>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:

ASU> Uri Guttman <uri@stemsystems.com> wrote in
ASU> news:x7is845vlh.fsf@mail.sysarch.com:

>>>>>>> "w" == wana <ioneabu@yahoo.com> 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
 
Old 11-17-2004   #10
..n.. ..hleich..
 
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 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0