Re: Perl equivalent to the unix 'cut' command

2004-10-14 Thread Chris Devers
On Thu, 14 Oct 2004, Dave Kettmann wrote:

> Subject speaks for itself..

Okay then.

perldoc -f split

Also speaks for itself :-)

 
 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl equivalent to the unix 'cut' command

2004-10-14 Thread Chris Devers
On Thu, 14 Oct 2004, Chris Devers wrote:

> On Thu, 14 Oct 2004, Dave Kettmann wrote:
> 
> > Subject speaks for itself..
> 
> Okay then.
> 
> perldoc -f split
> 
> Also speaks for itself :-)
 
To be less snarky, you probably need to open up your file, iterate over 
it line by line, using split to break each line up into chunks, then 
write out a new array with the fields you want and the order you want 
them. This second array can then be written out to disc; if you want you 
could even read & write within the same loop.

But the key point is that split is often the easiest way to break apart 
the fields in a file that is, for example, CSV formatted. 

Give that a try, write some code to attempt it, and let the list know if 
you have any problems in getting it to work.


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Perl equivalent to the unix 'cut' command

2004-10-14 Thread Dave Kettmann


> -Original Message-
> From: Chris Devers [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 14, 2004 4:16 PM
> To: Perl List (E-mail)
> Cc: Dave Kettmann
> Subject: Re: Perl equivalent to the unix 'cut' command
> 
> 
> On Thu, 14 Oct 2004, Chris Devers wrote:
> 
> > On Thu, 14 Oct 2004, Dave Kettmann wrote:
> > 
> > > Subject speaks for itself..
> > 
> > Okay then.
> > 
> > perldoc -f split
> > 
> > Also speaks for itself :-)
>  
> To be less snarky, you probably need to open up your file, 
> iterate over 
> it line by line, using split to break each line up into chunks, then 
> write out a new array with the fields you want and the order you want 
> them. This second array can then be written out to disc; if 
> you want you 
> could even read & write within the same loop.
> 
> But the key point is that split is often the easiest way to 
> break apart 
> the fields in a file that is, for example, CSV formatted. 
> 
> Give that a try, write some code to attempt it, and let the 
> list know if 
> you have any problems in getting it to work.
> 
> 
> -- 
> Chris Devers
> 

Chris,

The reply was deserved :) Just another question before I go too far with this... The 
files I am parsing (just needing 2 tabbed fields out of them) are approximately 20,000 
- 25,000 lines long a piece. Each of these files will be globbed into one file, but 
that is something completely different. I guess my question is, would I be better off 
calling exec(cut) with files of this size for ease of use?  Guess I should have 
mentioned this in my previous email.

Thanks again,

Dave

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Perl equivalent to the unix 'cut' command

2004-10-14 Thread Chris Devers
On Thu, 14 Oct 2004, Dave Kettmann wrote:

> The reply was deserved :) Just another question before I go too far 
> with this... The files I am parsing (just needing 2 tabbed fields out 
> of them) are approximately 20,000 - 25,000 lines long a piece. Each of 
> these files will be globbed into one file, but that is something 
> completely different. I guess my question is, would I be better off 
> calling exec(cut) with files of this size for ease of use?  Guess I 
> should have mentioned this in my previous email.

Not necessarily. 

I seem to remember that as long as you're iterating over a small window 
of the file at any given time, you don't necessarily end up slurping the 
whole thing into memory at once. 

How long is each line? How large are the files, bytewise? And how much 
memory (etc) do you have to work with?

This is going to be a situations where benchmarks are invaluable.


 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Perl equivalent to the unix 'cut' command

2004-10-14 Thread Dave Kettmann

> On Thu, 14 Oct 2004, Dave Kettmann wrote:
> 
> > The reply was deserved :) Just another question before I go too far 
> > with this... The files I am parsing (just needing 2 tabbed 
> fields out 
> > of them) are approximately 20,000 - 25,000 lines long a 
> piece. Each of 
> > these files will be globbed into one file, but that is something 
> > completely different. I guess my question is, would I be better off 
> > calling exec(cut) with files of this size for ease of use?  Guess I 
> > should have mentioned this in my previous email.
> 
> Not necessarily. 
> 
> I seem to remember that as long as you're iterating over a 
> small window 
> of the file at any given time, you don't necessarily end up 
> slurping the 
> whole thing into memory at once. 
> 
> How long is each line? How large are the files, bytewise? And 
> how much 
> memory (etc) do you have to work with?
> 
> This is going to be a situations where benchmarks are invaluable.
> 
> 
>  
> 
> -- 
> Chris Devers
> 

Each line is probably 80-100 characters in legnth, the files are about 300Kb each (6 
files total) working with 1GB of memory. Looking at these numbers, dont know that 
these are really that big of a file, but seem like it when you look at them in vi 
;)... I guess I will give slice a shot and see what I can do with it, I will keep you 
and the list updated :)

Dave Kettmann

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Perl equivalent to the unix 'cut' command

2004-10-14 Thread Chris Devers
On Thu, 14 Oct 2004, Dave Kettmann wrote:

> Each line is probably 80-100 characters in legnth, the files are about 
> 300Kb each (6 files total) working with 1GB of memory.

Oh, that's it? I'm sure you'll be find then


> Looking at these numbers, dont know that these are really that big of 
> a file, but seem like it when you look at them in vi ;)...

Well, among other things, Vim handles big files more smoothly :-)




-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl equivalent to the unix 'cut' command

2004-10-14 Thread John W. Krahn
Dave Kettmann wrote:
Howdy list,
Hello,
Subject speaks for itself.. Need to find a function or module to work
like the 'cut' command. I have a file with multiple fields and i need
to 'cut' out 2 of the fields. Looked thru CPAN for cut, but didnt find
anything,
Really?  I found it right away.
http://search.cpan.org/~cwest/ppt-0.14/src/cut/cut.hewgill
started looking thru CPAN searching on 'File' but I think
I'm just not thinking of the right keyword that perl uses.
Use 'cut'.
I'm still
new to perl and I'm sorry for my ignorance if it should be right under
my nose

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]