home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!reed!romulus!merlyn
- From: merlyn@romulus.reed.edu (Randal L. Schwartz)
- Newsgroups: comp.lang.perl
- Subject: Re: Multi files reading/Chopping lines.
- Message-ID: <MERLYN.92Aug22085210@romulus.reed.edu>
- Date: 22 Aug 92 15:52:13 GMT
- Article-I.D.: romulus.MERLYN.92Aug22085210
- References: <1992Aug21.221915.3131@pool.info.sunyit.edu>
- Sender: news@reed.edu (USENET News System)
- Organization: Reed College
- Lines: 28
- In-Reply-To: buck@pool.info.sunyit.edu's message of 21 Aug 92 22:19:15 GMT
-
- In article <1992Aug21.221915.3131@pool.info.sunyit.edu> buck@pool.info.sunyit.edu (Jesse Buckley) writes:
- 1) I want to read in several files as one (cat files*|). What is the
- best way?
-
- 2) Is there a fast/easy way to chop a line to X width (like colrm or
- cut)?
-
- Well, this little program ought to demonstrate both. It trims the
- lines of the files specified on the command line down to the number of
- characters given in the first argument.
-
- #!/usr/bin/perl
- $width = shift(@ARGV); # get width
- while (<>) {
- chop; # toss the newline
- print substr($_,0,$width), "\n";
- }
-
- See? Pretty easy. Although, if I was using this, I'd probably do it
- in one line, as given on the manpage:
-
- perl -lpe 'substr($_, 80) = ""'
-
- print ((unpack("a5" x 5,"er PeanothJust cker,rl ha"))[2,1,0,4,3])
- --
- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
- merlyn@reed.edu (guest account) merlyn@ora.com (better for permanent record)
- cute quote: "Welcome to Portland, Oregon -- home of the California Raisins!"
-