Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: path is broken

by ashok (Sexton)
on Dec 07, 2000 at 10:37 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-07-01 13:07 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (98 votes). Check out past polls.