in reply to elseif syntax error

Your regex /\.*$/ will always match: it's looking for zero or more '.' characters at the end of the string. If you're attempting to eliminate the '.' and '..' directories you want:

if (!/^\.+$/) {

(String from start to end contains one or more '.' characters only)

Replies are listed 'Best First'.
Re^2: elseif syntax error
by gmargo (Hermit) on Oct 27, 2009 at 14:44 UTC

    I think perhaps you meant

    if (!/^\.{1,2}$/) {
    or
    if (!/^\.\.?$/) {
    unless you're trying to avoid all entries that consist only of dots. ("...." is a valid name)

      Confused.

      Inspiration:

      $ echo 'wtf' > ... $ ls -l ... -rw-r--r-- 1 me me 4 Oct 27 10:50 ... $ cat ... wtf $

      Enlightened.

        ls # Scared due to the lack of mention of "..." in ls output (at least I +hope # you are, as otherwise "enlightment fizzled and finally failed").
Re^2: elseif syntax error
by Anonymous Monk on Oct 27, 2009 at 15:20 UTC
    Can't cd to (./test/) test test test test: No such file or directory at e:\path\myfiles\perl\filename_spaces2.pl line 7

    The code is fine it is not completely "recursive" someone of you got some hint how to go down in every subdirectory? If i start it a second time it is working ... On first attempt the directory tree is (i got several space containing files below E:\temp:

    #Perl should find spaces and replace them with "-" # use warnings; use File::Copy; use File::Find; find(\&rename_txts, "."); #Pfade ... find(\&rename_txts, "./txt2/"); sub rename_txts { if (!/^\.+$/) { my $new_name = $_; $new_name =~ y/ /-/; print "$File::Find::name to $new_name\n"; print "$_ \n"; move $_, $new_name; } }
    The result is:
    "E:\temp\test\test test test test"\Files with spaces ...
    2nd attempt:
    "E:\temp\test\test-test-test-test"Files-with-spaces...
    so the 2nd (or depending on the number of subdirectories run is ok)
    Thx for all your help so far
    btw: The purpose is to rename all the files on a network drive to proper names without spaces ...

      You don't need recursion, because the "find" function is traversing the directory structure for you.

      The errors you see are due to renaming of a directory before it is finished being used. Try "finddepth" instead of "find". The "finddepth" routine will process a directory's contents before the directory itself.