Re: Help! Perl Substitution
From: Jeff Westman (westfour_at_yahoo.com)
Date: 02/20/04
- Next message: Wc -Sx- Jones: "Re: Help! Perl Substitution"
- Previous message: David: "Re: Help! Perl Substitution"
- In reply to: Paul Johnson: "Re: Help! Perl Substitution"
- Next in thread: Wc -Sx- Jones: "Re: Help! Perl Substitution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 19 Feb 2004 16:39:31 -0800 (PST) To: perl_help <beginners@perl.org>
Paul Johnson <paul@pjcj.net> wrote:
> On Thu, Feb 19, 2004 at 04:36:55PM -0800, david wrote:
> > Jeff Westman wrote:
> >
> > > I'm trying to help out another developer with a mini-Perl
> script.
> > > He has a file that contains one very long line, about 28M in
> size.
> > > He needs to do a replacement of all occurances of
> > >
> > > |^NEWLINE^|^
> > >
> > > to a literal newline (HPUX, 0x0a or "\n").
> > >
> > > When I ran this
> > >
> > > $ perl -ne 's/|^NEWLINE^|^/\n/g;print' loadFile
> > >
> > > it choked and gave me
> > >
> > > Out of memory during "large" request for 1073745920 bytes,
> total
> > > sbrk() is 604078796 bytes at -e line 1, <> line 1.
> > >
> >
> > if your system do not have memory to read in large chunk, you
> can easily
> > break the chunks up by reading smaller chunks to process. for
> example, the
> > follwoing reads 4k a time and process them:
> >
> > [panda]# perl -ne 'BEGIN{$/=\10} s/\|\^NEWLINE\^\|\^/\n/g;
> print' loadFile
>
> The trouble with this approach is that you will miss any
> separators
> which are split. Your example actually reads 10 bytes at a time,
> but
> using $/ is the right idea:
>
> perl -ple 'BEGIN { $/="|^NEWLINE^|^" }' loadFile
>
> This reads "lines" separated by "|^NEWLINE^|^", chomps away the
> separator and prints the "lines" followed by a newline.
>
> perldoc perlrun
> perldoc perlvar
Paul -- a million thanks -- your solution worked absolutely
perfectly!!
-Jeff
__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools
- Next message: Wc -Sx- Jones: "Re: Help! Perl Substitution"
- Previous message: David: "Re: Help! Perl Substitution"
- In reply to: Paul Johnson: "Re: Help! Perl Substitution"
- Next in thread: Wc -Sx- Jones: "Re: Help! Perl Substitution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|