Oh Wise Ones,

I have a dir filled with files. Each file contains tab-delimited data that will ultimately be loaded into a database. The files each have a number as their suffix (ex. FILE.001, FILE.002, etc.) The data inside the files contain no reference as to which file the data came from. I wrote this little program that takes the filename and places it at the end of each line of data contained in the file. This works fine and solves the problem. The improvement I would like to make is instead of taking the entire filename I would like to take the suffix only (i.e. 001, 002, etc.). Looking at the code provided what would I have to add to just get the text after the period (.) in $file variable.

Thanks in advance for your help,

Eli
#!/usr/bin/perl # ingramid.pl use warnings; use strict; my @tempfile; my $file; my $ingramdir = "d:/ingram/ingramprc"; opendir(DIR, $ingramdir) or die "can't open $ingramdir: $!"; while (defined($file = readdir(DIR))) { print "$file\n"; open ingramoldfile, "d:/ingram/ingramprc/$file"; while (<ingramoldfile>){ chomp $_; push @tempfile, "$_\t$file\n"; } close ingramoldfile; } open ingramnew, ">d:/ingram/ingramprc/ingramall.txt"; print ingramnew @tempfile; close ingramnew; closedir(DIR);

In reply to parse filenames by esolm

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.