Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Getting correct filename

by Anonymous Monk
on Aug 10, 2000 at 19:20 UTC ( #27300=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a program that sorts through some weblogs and depending on what is found on each line, it writes the line to a file. The program works wonderfully, but I am having touble figuring out how to derive the new filename from the old filename. I know I can use $ARGV to obtain the full filename of the file I am reading, but I really only need half the original filename to make the new filename. I hope this makes sense, because I can't seem to explain myself that clearly today. Let me try to clarify: Name of file to be processed: Weblog.23Jul What I want the name of new file to be: weblog-otherinfo where weblog is obtained from the old filename and otherinfo is obtained through the processsing of the file. Any help would be greatly appreciated. Let me know if more clarification is needed. Than

Replies are listed 'Best First'.
Re: Getting correct filename
by young perlhopper (Scribe) on Aug 10, 2000 at 19:34 UTC
    I'm not totally clear on what you are trying to do but maybe something like this will get you started:

    # $infile is assumed to be the file you are reading... # I'm assuming you know what you want to put in the out # file name and how to get it... my $otherinfo = &getotherinfo; # the \d{2} is the day, make it \d{1,2} if you want to # allow weblog.2Jul as well as weblog.23Jul # # the \w{3} catches the month abbreviation (my $outfile = $infile) =~ s/\.\d{2}\w{3}/-$otherinfo/; # do this if you want to use an absolute pathname... $outfile = $pathname . $outfile; open(OUTFILE, "> $outfile");

    If i totally missed what you were trying to do, let me know.

    Good luck,
    Mark

Re: Getting correct filename
by msb (Initiate) on Aug 11, 2000 at 04:26 UTC
    Also, it sounds like you don't know "otherinfo" until you've proccessed the file. So, you should put all output in an array and write it to a file at the end, when you know the name, or write to a temporary file and rename it at the end. Mark.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2022-10-05 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (23 votes). Check out past polls.

    Notices?