Hi all,

I wrote this code in which I want to read some files in a folder. (Files are named in format YYYY_MM_DD,eg. 2010_01_24,). There are around "30 files" with naming from 2009_01_25.dat to 2010_01_24.dat. Now I wish to apply a filter on the date and read only those files which matches the range of dates. The code is given below.

use strict; use warnings; my $csvprint; my $csv; opendir DIR, "./dates/"; my @inputfiles = grep { $_ ne '.' && $_ ne '..' } readdir (DIR); my @sorting = sort {$a cmp $b} @inputfiles; #print @sorting,"\n\n\n"; foreach(@sorting) { my $start = "2009_12_30"; my $end = "2010_01_05"; if ($_=~ /^$start/../^$end/) { open FILE, "< ./dates/$_"; while (<FILE>) { chomp; my @content = split (/\,/,$_); my @datesplit = split(/\_/,$content[0]); $csvprint = "$datesplit[0],$datesplit[1],$content[1]\n"; if ($csvprint ne 0) { $csv .= $csvprint; } else { print "blank\n"; } } } else { print "nothing printed. \n"; #print $_,"\n"; } #print $csvprint,"\n\n"; } #print $csv; open CSV,"> 1.csv"; print CSV $csvprint;

My input files are of the format

File Name : 2009_12_24.dat

Content:
2009-12-24_Image,807
2009-12-24_image,119895419
2009-12-24_x-epoc,1138251
2009-12-24_multipart,185849
2009-12-24_application,45164332
2009-12-24_,5587
2009-12-24_audio,11638246
2009-12-24_video,97898353
2009-12-24_text,65788112


Now when I run this script I am getting this warning everytime.

Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 6. Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 15. Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 24. Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 33. Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 42. Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 51. Use of uninitialized value in concatenation (.) or string at files.pl +line 26, < FILE> line 60.
and also I am able to get the results. I am not able to understand why this warning is being generated. Please help.

In reply to reading files in a directory with range operator. by avanta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.