This was really helpful and is teaching me a lot about coding ettiquette.

Thank you.

I actually have solved my problems, it had to deal with missing a
chomp in beginning where i asked for the name.  I couldnt figure out
why when I printed the concantenated variable it had the right info
but it wouldnt rename the files.  This happened because it couldnt use
the newline character in the rename.

Thanks again for everyones help.

I have now completed half the script.  The next half deals with
regular expressions but I want to work more on my own and go through
trial & error before I ask for help.


On Sat, 19 Feb 2005 23:14:54 -0800, $Bill Luebkert <[EMAIL PROTECTED]> wrote:
> fad3r wrote:
> > Hi,
> >
> > I have been playing around with two pieces of test code:
> >
> > $first = "Jim";
> > $last = "Smith";
> > $fullname = $first . " " . $last;
> > print $fullname;
> >
> > $str1 = "Jim";
> > $str2 = "Smith";
> > $long_str = "$str1 $str2";
> > print $long_str;
> >
> > Both of these succesfully work.  However when I try implementing them
> > in my code I get errors.  Can anyone let me know what I am doing
> > wrong?
> >
> > print "\nWhere are the files?  ";
> > $dir = <stdin>;
> > chomp ($dir);
> >
> > opendir (DIRECTORY, $dir) || die "cannot open directory\n";
> >
> > @files = readdir (DIRECTORY);
> > foreach $file (@files) {
> >     $lc_file = lc($file);
> >     rename("$dir/$file", "$dir/$lc_file");
> > }
> > #the above works flawlessly
> >
> > opendir (DIRECTORY, $dir) || die "cannot open directory\n";
> > @files2 = readdir (DIRECTORY);
> >
> > foreach $file2 (@files2) {
> >       $can_file = $name $file2;
> >       rename("$dir/$file", "$dir/$can_file");
> >
> > That returns:
> > D:\Scriptz>lc3.pl
> > Scalar found where operator expected at D:\Scriptz\lc3.pl line 22,
> > file2"
> >         (Missing operator before $file2?)
> > syntax error at D:\Scriptz\lc3.pl line 22, near "$name $file2"
> > Execution of D:\Scriptz\lc3.pl aborted due to compilation errors.
> >
> > Doing it the other way returns:
> >
> > Use of uninitialized value in concatenation (.) or string at 
> > D:\Scriptz\lc3.pl l
> > ine 23, <stdin> line 2.
> > Use of uninitialized value in concatenation (.) or string at 
> > D:\Scriptz\lc3.pl l
> > ine 23, <stdin> line 2.
> > Use of uninitialized value in concatenation (.) or string at 
> > D:\Scriptz\lc3.pl l
> > ine 23, <stdin> line 2.
> > Use of uninitialized value in concatenation (.) or string at 
> > D:\Scriptz\lc3.pl l
> > ine 23, <stdin> line 2.
> > Use of uninitialized value in concatenation (.) or string at 
> > D:\Scriptz\lc3.pl l
> > ine 23, <stdin> line 2.
> >
> > Thanks again,
> >
> > I appreciate people helping me learn.
> 
> If you want to learn, then make sure you have the first two lines below on
> all your scripts.
> 
> use strict;
> use warnings;
> 
> my $first = "Jim";
> my $last = "Smith";
> my $fullname = $first . " " . $last;
> print $fullname, "\n";
> 
> my $str1 = "Jim";
> my $str2 = "Smith";
> my $long_str = "$str1 $str2";
> print $long_str, "\n";
> 
> my $name = 'foo';       # you need to define $name
> 
> # get the directory we are fixing
> 
> print "\nWhere are the files?  ";
> my $dir = <stdin>;
> chomp $dir;
> 
> # lowercase all the filenames in dir
> 
> opendir DIR, $dir or die "opendir $dir: $!\n";
> while (my $file = readdir DIR) {
>        my $lc_file = lc $file;
>        if ($file ne $lc_file) {
>                rename "$dir/$file", "$dir/$lc_file" or
>                  warn "rename '$dir/$file', '$dir/$lc_file': $!";
>        }
> }
> closedir DIR;
> 
> # prepend $name to all the filenames in dir
> # this step could actually be done in the above loop and save
> # a step.
> 
> opendir DIR, $dir or die "opendir $dir: $!\n";
> while (my $file = readdir DIR) {
>        my $can_file = $name . $file;
>        if (! -e "$dir/$can_file") {
>                rename "$dir/$file", "$dir/$can_file" or
>                  warn "'$dir/$file', '$dir/$can_file': $!";
>        }
> }
> closedir DIR;
> 
> __END__
> 
> --
>  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
> (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
>  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
> -/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to