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

Re: Re: path is broken

by ashok (Sexton)
on Dec 07, 2000 at 10:37 UTC ( [id://45449]=note: print w/replies, xml ) Need Help??


in reply to Re: path is broken
in thread path is broken

Hi, I appreciate your help. But still I have one more problem. As I did explain, I am reading file names from a file. This file contains some history of each file in the entire source code. Like:
Module: /org/trans/program files/dir1 /dir2/file1.cpp some flags some history
So I pickup file name using reglar expression. My problem is when it breaks into two lines, like
Module: /org/trans/program files/dir1/subdir1/subdir2/file1.cpp some flags some history
In this case how to write my regular expression? I do not know in which line filename in a file breaks into two lines. The file I read is a big file and I can not keep into memory. Thanks again to you all. I am learning a lot. Ashok

Replies are listed 'Best First'.
Re: (lemming) Re: path is broken
by lemming (Priest) on Dec 07, 2000 at 10:50 UTC
    So if you're going through your file looking for ^Module and getting the what may be the filename;
    You may want to do a test if the file exists: (-e $filename) and then if it does not, grab the next line and tack it on.
    Though make sure you tack through the next Module line.
    Does it break on line length or on spaces? Consider that as well.
Re: Re: Re: path is broken
by kilinrax (Deacon) on Dec 07, 2000 at 16:53 UTC
    I assume that what you're looking for here is the string '/org/trans/program files/dir1/subdir1/subdir2/file1.cpp'.
    Crafting a regex to extract the file name without having a format you can rely on is going to be tricky.
    However, if you are always going to be looking for a '.cpp' file, then the following will work:
    #!/usr/bin/perl -w use strict; my $data = join '', <DATA>; my ($filename) = ($data =~ m|^Module: (.*\.cpp)$|ms); $filename =~ s|\n||; print $filename; __DATA__ Module: /org/trans/program files/dir1/subdir1/subdir2/file1.cpp some flags some history

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-03-28 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found