file output 
Author Message
 file output

Hello Group;

    I have a small perl app that I wrote. It take a text file that is
captured from the serial port, named capture.txt. My app takes this
captured.txt file and prases all of the info I want in the file and produces
an output file that if formatted the way I want. My question is how can I
have this output file named to what ever the current system date is, like
(date +%x). Instead of the hard coded filename I have given it. Below is the
last few line of my app, where the file is being writen out.

open (OUTPUT_FILE, ">/home/Administrator/phonelogs/phonelog.txt");

while (<INPUT_FILE>) {
        if (m/09/) {s/^\s+//;
         print OUTPUT_FILE "$_";}

        }

print "\n\n\nPress <Enter> to continue...";

<STDIN>;

So how do I make the output file the current date in, date +%x, format?
Instead of my phonelog.txt.name.

Any help is greatly apperciated.

-Jayson Garrell
Fresno Linux User Group
http://www.*-*-*.com/



Mon, 01 Mar 2004 20:39:10 GMT  
 file output

Quote:

> Hello Group;

>     I have a small perl app that I wrote. It take a text file that is
> captured from the serial port, named capture.txt. My app takes this
> captured.txt file and prases all of the info I want in the file and produces
> an output file that if formatted the way I want. My question is how can I
> have this output file named to what ever the current system date is, like

perldoc -f localtime

--
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa



Mon, 01 Mar 2004 11:58:32 GMT  
 file output

Quote:

>         My question is how can I
>have this output file named to what ever the current system date is, like
>(date +%x).

(snip)

Quote:

>So how do I make the output file the current date in, date +%x, format?

first: you should learn to choose an appropriate Subject line. this has
nothing to with 'file output'.

now, what have you tried?

perldoc -f localtime()
perldoc -f gmtime()

also, the POSIX module gives access to a whole lot of library functions,
among them strftime()

then there are a whole lot of modules that can deal with time and date
in different ways, including the all-singing all-dancing Date::Manip
these can be found on cpan.org

gnari



Tue, 02 Mar 2004 07:11:06 GMT  
 file output

Quote:

>So how do I make the output file the current date in, date +%x, format?
>Instead of my phonelog.txt.name.

Create a suitable filename on the fly when you open the file:

# date today
my ( $day, $month, $year ) = ( localtime time ) [ 3..5 ];
$month++;
$year += 1900;

my $file = sprintf "/whatever/%02d%02d%4d.ext", $day, $month, $year;

open( OUT, ">$file" ) or die "Cn't open '$file' for writing: $!\n";

HTH,
--

split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while



Tue, 02 Mar 2004 09:30:06 GMT  
 file output
Thanks for all the help guys. I have it producing the file name I now want,
thanks. As for the incorrect subject line, sorry this is my first time
posting to this group. This is also like my second perl script so I'm still
learning.

-Jayson Garrell


Quote:
> Hello Group;

>     I have a small perl app that I wrote. It take a text file that is
> captured from the serial port, named capture.txt. My app takes this
> captured.txt file and prases all of the info I want in the file and
produces
> an output file that if formatted the way I want. My question is how can I
> have this output file named to what ever the current system date is, like
> (date +%x). Instead of the hard coded filename I have given it. Below is
the
> last few line of my app, where the file is being writen out.

> open (OUTPUT_FILE, ">/home/Administrator/phonelogs/phonelog.txt");

> while (<INPUT_FILE>) {
>         if (m/09/) {s/^\s+//;
>          print OUTPUT_FILE "$_";}

>         }

> print "\n\n\nPress <Enter> to continue...";

> <STDIN>;

> So how do I make the output file the current date in, date +%x, format?
> Instead of my phonelog.txt.name.

> Any help is greatly apperciated.

> -Jayson Garrell
> Fresno Linux User Group
> http://linux.microbsys.com




Tue, 02 Mar 2004 16:49:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. binary file output (textual hex to binary stream - wmf image file)

2. error opening a pdf file output from perl script

3. file output

4. Need help with file output/editing - newbie

5. Help - file output problem

6. backspace in file output question

7. writing file output....newbie

8. file output and modules

9. Directory Processing and File output

10. Capturing file output

11. grep-like search with multiple file output?

12. Html file output :-I

 

 
Powered by phpBB® Forum Software