in reply to Re^12: search and replace strings in different files in a directory
in thread search and replace strings in different files in a directory

Dear Anonymous Monk

Thank you very much for your explanation and your encouraging words. You are right, creating code for a particular task is different than reading the book(s) and going through the exercises.

I think I still lack this eye for detail and sometimes I am aware of the problem but cannot figure out how to put the solution into code syntax.

Such was the case with File::Bom. I just did not know how to add to that particular part of the subroutine (not enough practice with modules and objects).

Thank you also for introducing Carp, I will have a go at it.

Thanks a mil again for your support, makes the whole a bit easier and it surely is more fun. (This goes for all contributors btw)

Kind regards

C.
  • Comment on Re^13: search and replace strings in different files in a directory

Replies are listed 'Best First'.
Re^14: search and replace strings in different files in a directory
by PitifulProgrammer (Acolyte) on Sep 02, 2014 at 12:12 UTC

    Dear Monks

    Sorry for pestering you once again with my noob questions. I changed the script according to your recommendations. So far no more BOM errors and everything seems to be working as planned.

    However, I got the following error message the meaning of which I am not quite sure of. Maybe one of you could shed some light on this (I used Carp::Always, as one of you suggested). I had to anonymise the code for I guess you know why....

    Error opendir on 'Z:/123/xyz/xyz/xyz_xyz_xyz_/01_abc': No such file or directory at C:/strawberry/perl/site/lib/Path/Tiny.pm +line 1490. Path::Tiny::Error::throw("Path::Tiny::Error", "opendir", "Z:/2014/xyz/ +xyz/xyz_xyz_xyz_/01_abc"") called at C:/strawberry/perl/site/lib/Path/Tiny.pm line 126 Path::Tiny::_throw(Path::Tiny=ARRAY(0x2774f74), "opendir") called at C +:/strawberry/perl/site/lib/Path/Tiny.pm line 532 Path::Tiny::children(Path::Tiny=ARRAY(0x2774f74), qr(\.xml$)u) called +at script.pl line 59 main::RetrieveAndBackupXML("Z:/123/xyz/xyz/xyz_xyz_xyz_/01_abc\\0"...) + called at script.pl line 31 main::Main() called at script.pl line 20

    In my opinion, the error is telling me that neither the folder nor the files exist (well, you cannot access the files if you cannot access the folder.

    Question is why is the programm throwing this error message, the folders do exist as indicated by the path names I am reading out.

    Is it problem if I access a network-drive? Would that be another building block that would bloat the script and provide with me with yet another topic to read about?

    A penny for your thoughts.

    Kind regards

    C

      Hmm, you say it exists as a directory, does the path contain any unicode codepoints ? What do you get with this program

      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use Win32; use Win32::Unicode qw/ statW /; my $path = 'Z:/123/xyz/xyz/xyz_xyz_xyz_/01_abc'; dd( $path ); dd({ -ansi, Win32::GetANSIPathName( $path ) }); dd({ -full, scalar Win32::GetFullPathName( $path ) }); dd({ -short, Win32::GetShortPathName( $path ) }); dd( statW( $path ) ); __END__

        Dear Anonymous Monk

        There might be some umlauts in some of the path names. Would that trigger the alarm?

        The initial purpose of the file (before it becam a rather huge project for a novice like me) was to do the following:

        read the path in the text-file provided by user

        go to each directory specified by the path name

        Look for any xml-files and open each one individually

        in each xml-file replace certain strings

        create a backup of the xml(s)

        close the file(s)

        close the directory

        Hope that helps (it did for me to get an initial idea what I was going to do step by step)

        Looking forward to your reply. Thanks for your help

        Kind regards

        C.