Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: remove line break from 1 line

by chargrill (Parson)
on Jan 20, 2007 at 06:11 UTC ( #595641=note: print w/replies, xml ) Need Help??


in reply to Re: remove line break from 1 line
in thread remove line break from 1 line

Actually... excerpted from perldoc -f chomp

If you chomp a list, each element is chomped, and the total number of characters removed is returned.

So , something like this will remove the locale equivalent of a newline from every element:

my @input = <STDIN>; chomp( @input );

Now everything entered on STDIN separated by a newline has been chomped.

Just be wary of precedence... Also from perldoc -f chomp:

Note that parentheses are necessary when you're chomping any- thing that is not a simple variable. This is because "chomp $cwd = `pwd`;" is interpreted as "(chomp $cwd) = `pwd`;", rather than as "chomp( $cwd = `pwd` )" which you might expect. Similarly, "chomp $a, $b" is interpreted as "chomp($a), $b" rather than as "chomp($a, $b)".


--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://595641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2019-09-23 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (279 votes). Check out past polls.

    Notices?