Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Problems? Is your data what you think it is?
 
PerlMonks  

Re: (tye)Re: How to look for patterns in a file and create a CR

by juo (Curate)
on Mar 21, 2001 at 09:44 UTC ( [id://65999]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to (tye)Re: How to look for patterns in a file and create a CR
in thread How to look for patterns in a file and create a CR

This didn't make it work completely. I have found the way to do it. First I remove all the returns and make one file of it. After that I build in again returns looking for a certain pattern. If somebody can make it <CR> shorter and knows how I can skip to make intermediate file and create straigt away the target file it is welcome. Pieter Here is the code :

#!perl -w use strict; use FileHandle; my $file = "c:/perl/training/test/common.grb"; #source file my $file1 = "c:/perl/training/test/test5.txt"; #intermediate file, jus +t contain one long line my @users = readFile($file); for(@users) { chomp; s/\s+/ /g; } writeFile("c:/perl/training/test/test5.txt", @users); my @newUsers = readFile($file1); for (@newUsers) { s/(.)G57/$1\nG57/g; } writeFile("c:/perl/training/test/test6.txt", @newUsers);> #target fil +e, each line start with G57 sub readFile { my ($fileName) = @_; sysopen(F, $fileName, O_RDONLY) or die "\nCannot open #<CR> $file: $!\ +n"; my @fileContents = <F>; close(F); return @fileContents; } sub writeFile { my ($file, @contents) = @_; if(-e $file) { unlink $file or die "\nunable to remove $file: $!\n"; } sysopen(F, $file, O_RDWR | O_EXCL | O_CREAT, 0666) or die "\nCannot cr +eate $file: $!\n"; print F @contents or die "\nCannot write to $file: $!\n"; close(F) or die "\nCannot close filehandle - $file: $!\n"; }

Edit 2001-03-21 by mirod: added code tags

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://65999]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.