Loading ...
Sorry, an error occurred while loading the content.

27480What does this mean?

Expand Messages
  • Peter Holsberg
    Oct 26, 2013
    • 0 Attachment
      I'm trying to understand a script someone else wrote so I can modify it
      for my own purposes.

      I'm trying to read (and modify) a file in the current directory. The
      filename has 6 digits (eg., 131026) and is of type .htm. Other files
      that may be used are similarly named, for example,

      131026.htm
      131026.aca
      131026.pbn
      131026.bws
      131026.txt
      131026ARECAP.txt

      The script begins:

      #!/usr/bin/perl

      use strict;
      use warnings;

      use Tie::File;
      use File::Copy 'copy';
      use File::Spec;

      use Cwd;
      my $dir = cwd;

      opendir my ($dh), $dir;

      # Find all files in the directory that match \d{6}\.htm
      # Die if none or multiple files found
      #

      my @files = grep /\A\d{6}\.htm\z/i, readdir $dh;
      die 'No matching files found' unless @files;
      die 'Multiple matching files found' if @files > 1;
      my $file = File::Spec->catfile($dir, $files[0]);

      print "\n\n------------ FOUND THIS: $file \n\n";

      The output of the above command is:
      E:\_WEBPAGES\.Cinna\ACBLmerge\131021.htm

      I think that everything that follows would be much simpler if $file had
      the value 131021.htm

      So, a couple of questions:

      1. How do I operate on $file so get what I want?

      2. Can someone please parse

      my @files = grep /\A\d{6}\.htm\z/i, readdir $dh;

      and

      my $file = File::Spec->catfile($dir, $files[0]);

      Thanks.
    • Show all 4 messages in this topic