Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Parsing file and joining content into string

by flexvault (Prior)
on Jan 15, 2013 at 18:51 UTC ( #1013442=note: print w/ replies, xml ) Need Help??


in reply to Parsing file and joining content into string

Welcome Mark.Allan,

If you loop on the file as:

my $string = ""; while ( <$IN> ) ## $IN needs to be open { chomp; if ( $_ eq "END" ) { $string = join ( " ", split " ", $string ); # $string =~ s/$other//g; ## In case you need to remove o +ther characters print $OUT "$string\n"; ## $OUT is open output file $string = ""; next; } $string .= $_; }

I know you didn't want code, but it was easier to type code then describe :-)

That special use of 'join' is in the Camel book (3rd edition) on page 154. It removes whitespace before and after the string, plus reduces multiple spaces to 1. I typed this in, so there may be some typos, but it should get you going, and remember to use 'use strict; use warning;' in your code.

Hope it helps.

"Well done is better than well said." - Benjamin Franklin


Comment on Re: Parsing file and joining content into string
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2015-07-31 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls