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

Re: Handling errors when working with files

2007-12-31 Thread oscar gil
Thanks Tom, it helped. :-) I learned some more few things. ;-) Regards, Tom Phoenix <[EMAIL PROTECTED]> wrote: On Dec 30, 2007 10:17 AM, oscar gil wrote: > What I still don't understand is why $! and $^E are set as there was an > error though there was not :-?. Those variables may

Re: Handling errors when working with files

2007-12-30 Thread Tom Phoenix
On Dec 30, 2007 10:17 AM, oscar gil <[EMAIL PROTECTED]> wrote: > What I still don't understand is why $! and $^E are set as there was an > error though there was not :-?. Those variables may be set when your perl binary internally needs to use a system call or something similar. During or shortly

Re: Handling errors when working with files

2007-12-29 Thread Tom Phoenix
On Dec 29, 2007 9:18 AM, oscar gil <[EMAIL PROTECTED]> wrote: > Using 'open' I cannot say if the 'del' command was done correctly > or not, although there is a message probably to STDERR that I do > not know how to manage. :-( I believe you're talking about a piped open() to an external command

Re: Handling errors when working with files

2007-12-29 Thread oscar gil
g the file handler. Answering your question to 'Do you want to handle errors or do you want to report errors?' I would like to handle the errors and I thought using these variable would be a good method, wouldn't be? Thanks again. "John W. Krahn" <[EMAIL PROTECT

Re: Handling errors when working with files

2007-12-29 Thread John W. Krahn
oscar gil wrote: Hello everybody, Hello, I wanted to learn a bit more about how to handle errors when I am working with files, Do you want to handle errors or do you want to report errors? so I wrote this simple script to start with it where you can see that first I show the normal perl

Handling errors when working with files

2007-12-29 Thread oscar gil
Hello everybody, I wanted to learn a bit more about how to handle errors when I am working with files, so I wrote this simple script to start with it where you can see that first I show the normal perl errors variables, then I try to delete a file and finally I show the errors variables again

Re: Working with files

2007-02-23 Thread Dr.Ruud
Jeff Pang schreef: > [processing .h files] > next if $file eq '.' or $file eq '..'; > next if $file !~ /\.h$/; Those two lines can be replaced by file =~ /\.h$/ or next; > return $. if /$string/; If the string can contain regex-special characters, then always use quote

Re: Working with files

2007-02-23 Thread Ken Foskey
On Thu, 2007-02-22 at 23:20 +0530, Dharshana Eswaran wrote: > I forgot to mention, First step is to Search for the file in which the > string occurs A list of files use either function glob or opendir (perldoc -f ???) I wonder how you are going to check for a string without opening it. You may

Re: Working with files

2007-02-22 Thread Jeff Pang
>> I need to search a particular string in a set of files in a directory. The >> string appears only in one of the files in the directory. >> I need to retrieve the file name and then access the line of that >> particular file in which the string occurs. >> >> NOTE: The perl script also resides i

Re: Working with files

2007-02-22 Thread Tom Phoenix
On 2/22/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote: I need to search a particular string in a set of files in a directory. The string appears only in one of the files in the directory. I need to retrieve the file name and then access the line of that particular file in which the string occ

Re: Working with files

2007-02-22 Thread Dharshana Eswaran
On 2/22/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote: Hello All, I need to search a particular string in a set of files in a directory. The string appears only in one of the files in the directory. I need to retrieve the file name and then access the line of that particular file in which th

Working with files

2007-02-22 Thread Dharshana Eswaran
Hello All, I need to search a particular string in a set of files in a directory. The string appears only in one of the files in the directory. I need to retrieve the file name and then access the line of that particular file in which the string occurs. NOTE: The perl script also resides in the