Perl Scripting problem - please help!

From: Mark (budman_at_generation.net)
Date: 03/17/05

  • Next message: Felix Geerinckx: "Re: Perl Scripting problem - please help!"
    Date: 17 Mar 2005 06:47:53 -0800
    
    

    Hello,

    I am new to PERL and I want to do a simple function (in LINUX):

    find all files that have the extension pseudo.pdf and put the file
    names in a file;
    parse the file and change all file names current filename plus date:

    pseudo+date+.pdf

    Move the new file to pseudo directory :

    I have written the code which seems to work without any errors and has
    been accepted by PERL:

    #!/usr/bin/perl -w
    open (pdfs, "/var/www/html/reports/shops/pdflist.txt")
    ||Error('open','file');
    @fnames=<pdfs>;
    close (pdfs);
    ($second,$minute,$hour,$day,$month,$year,$weekday,$dayofyear,$isdst)=localtime(time);
    $cmonth=$month+1;
    $cyear=($year % 100);
    $fdate=$cmonth.'-'.$day.'-'.$cyear;
    $ext='.pdf';
    foreach $pdffile (@fnames2) {
       $pdffile=$pdffile.$fdate.$ext;
    }
    $n=1;
    foreach $fnames (@fnames) {
       $cnt=index($fnames,".pdf");
       $newfile=substr($fnames,0,$cnt);
       $newpdf=$newfile.$fdate.$ext;
       print "fnames: $fnames \n";
       print "new file: $newfile \n";
       print "newpdf: $newpdf \n";
       print "old= /var/www/html/reports/shops/$fnames \n";
       print "new= /var/www/html/reports/shops/$newfile/$newpdf \n";
       rename("/var/www/html/reports/shops/$fnames","/var/www/html/reports/shops/
               $newfile/$newpdf");
    print "\n";

    }

    I cannot get the rename function to work even if I use the same
    directory. I don't get any errors and the file permissions are set
    correctly on the files.

    Anyone know why this does not work?

    Thanks,

    Mark
    budman@nospam.generation.net


  • Next message: Felix Geerinckx: "Re: Perl Scripting problem - please help!"

    Relevant Pages

    • Perl Scripting problem - please help
      ... I am new to PERL and I want to do a simple function: ... Move the new file to pseudo directory: ... foreach $pdffile { ... foreach $fnames { ...
      (comp.lang.perl.misc)
    • parse hash by array element seems to run slow
      ... I've been through the faq's and every web site that focuses on perl ... I iterate the array and search the hash keys to find a match and then ... foreach $verifyArr ...
      (comp.lang.perl.misc)
    • Perl crash related to Tie::File and hashes
      ... crash in perl when I try to use the data later on. ... sub TIEARRAY { ... foreach my $p { ... The assignment in the last loop causes perl to crash. ...
      (comp.lang.perl.moderated)
    • [DGBI] oops, obviously Ive missed something (was: regexp or array?)
      ... foreach { ... Better use an array of precompiled regexpes: ... perl -wle ' ... use Benchmark qw|cmpthese timethese|; ...
      (comp.lang.perl.misc)
    • Re: Search and replace problem
      ... the foreach part doesn't work. ... You are not using the natural representation of things. ... string, it's a precompiled regex. ... Why not just write Perl? ...
      (comp.lang.perl.misc)