"be consistent" PerlMonks

### Re^3: Parsing Data logger files ...

by mbethke (Hermit)
 on Oct 07, 2012 at 00:51 UTC ( #997650=note: print w/replies, xml ) Need Help??

in reply to Re^2: Parsing Data logger files ...
in thread Parsing Data logger files ...

The simplest solution would be to call choroba's script as "munge.pl /some/where/*" and let the shell do the directory stuff. "<>" will automatically try to read everything in @ARGV so you don't have to deal with it yourself.

Otherwise you're on the right track with readdir but you forgot to actually open each individual file.

Replies are listed 'Best First'.
Re^4: Parsing Data logger files ...
by RedTussock (Acolyte) on Oct 07, 2012 at 01:11 UTC
Perfect ... and a lesson in spotting the tree in the forest. Thank you both ... I guess now all I have to do is print it too a file.
Re^4: Parsing Data logger files ...
by RedTussock (Acolyte) on Oct 07, 2012 at 01:21 UTC
Something like
#!/usr/bin/perl
use warnings;
use strict;

$/ = "\n1="; while (<>) { my @fields = split /\n/; s/^[1-6]=// for @fields; open (MYFILE, '>/a/b/c/perl/dl_parser/logData.txt'); print MYFILE "+(join ',', @fields[0 .. 5]), "\n""; close (MYFILE); } [download] Consider the following: #!usr/bin/perl use strict; use warnings;$/ = "\n1=";

open my $fh, '>', '/a/b/c/perl/dl_parser/logData.txt' or die$!;

while (<>) {
my @fields = split /\n/;
s/^[1-6]=// and s/\s+$// for @fields; print$fh ( join ',', map qq/"$_"/, @fields[ 0 .. 5 ] ) . "\n"; } close$fh;
[download]

For each csv line, your script will open, write to, and then close the logData.txt file. When done, that file will have only one line, viz., the last one written to it. The above will write all csv lines to your file, since the open and close statements are outside the while loop. Additionally, note that open is using a lexically-scoped file handle (my $fh) and that it is a three-argument open. Have added two items to the script. The first is an additional substitution, since there was a space at the end of the last three fields. The second, a map statement, encloses each field within quotations, since the first data field contains a comma (remove the map qq/"$_"/, if you want the date and time to be treated as separate csv fields).

Hope this helps!

Yep OK, Sorry for the delay I had to pick family up of the plane ... The code offered creates afile indeed it does ... but It chokes on multiple files I think ... I get this result
Smitty@smittytech:~/scripts/perl/dl_parser> perl lineJumper.pl /home/S
+mitty/scripts/perl/dl_parser/down/*
Use of uninitialized value in join or string at lineJumper.pl line 12,
+ <> chunk 478.
Use of uninitialized value in join or string at lineJumper.pl line 12,
+ <> chunk 478.
Use of uninitialized value in join or string at lineJumper.pl line 12,
+ <> chunk 478.
Use of uninitialized value in join or string at lineJumper.pl line 12,
+ <> chunk 478.
[download]
which I think is the script not liking multiple files to parse ?? ..

Create A New User
Node Status?
node history
Node Type: note [id://997650]
help
Chatterbox?
 [Corion]: thezip: start "some title" path\to\that\ application, but that will open another console window [Corion]: thezip: If you want to confuse your users, use system(1, "that\\command" );, which will make Perl launch it in the background [Corion]: That will keep the console window open even though the user can't type into it anymore [thezip]: So I have a script that generates a log file. After script completion, I want tohave VIM open this logfile. [thezip]: i don't get the command line "back" until I close VIM. No what I want to happen... [thezip]: I currently don't have access to CYGWIN, else I'd just do a tail -f on the logfile. [Corion]: thezip: If you want to open vim and can live with opening a second console window, use start "The results" vim.exe c:\path\to\logfile .log

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-03-27 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (321 votes). Check out past polls.