Re: AW: Working with files of different character encodings

2010-04-07 Thread Uri Guttman
> "R" == Ruud writes: R> Thomas Bätzler wrote: >> my $data = do { >> local $/ = undef; >> <$fh>; >> }; R> Especially for big files, that is better written as: define big. most files are still text or similar and not big by today's ram sizes. slurping in a megabyte is nothing to

Re: AW: Working with files of different character encodings

2010-04-07 Thread Dr.Ruud
Thomas Bätzler wrote: my $data = do { local $/ = undef; <$fh>; }; Especially for big files, that is better written as: my $data; { local $/; $data = <$fh>; } -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http

AW: Working with files of different character encodings

2010-04-06 Thread Thomas Bätzler
Doug Cacialli asked: > Does anyone have any ideas how I can make the second block of code > work? Or otherwise accomplish the task without opening the .txt file > twice? How large are your data files? If your available memory is much larger than your maximum file size, you might get away with s

Re: Working with files of different character encodings

2010-04-05 Thread Jim Gibson
On 4/5/10 Mon Apr 5, 2010 2:56 PM, "Doug Cacialli" scribbled: > I sincerely appreciate the tips on improving my code; I implement (or > at least take strong note) of all the suggestions I receive. In the > code I posted, however, I'm primarily interested in learning if > there's a way to avoid

Re: Working with files of different character encodings

2010-04-05 Thread Doug Cacialli
I sincerely appreciate the tips on improving my code; I implement (or at least take strong note) of all the suggestions I receive. In the code I posted, however, I'm primarily interested in learning if there's a way to avoid opening the file to determine the character encoding, and then opening it

Re: Working with files of different character encodings

2010-04-05 Thread Dr.Ruud
Doug Cacialli wrote: $datapath =~ s/^\s+//; $datapath =~ s/\s+$//; Alternative notation: s/\s+$//, s/^\s+// for $datapath; I have a "sub trim()" in my Toolbox, so I just call "trim($datapath);". open (my $filehndl , "<", "$datapath") || die ("Can't open .txt file $datapath. Ex

Working with files of different character encodings

2010-04-03 Thread Doug Cacialli
Thanks to much help from the list, and hours of reading up on Unicode, the Encode module, and many posts to perlmonks, I've come up with a hideous solution for processing text files with different character encodings. Can someone please explain why this first block of code works when decoding .txt