moving file using perl

Chris G cl at isbd.net
Thu May 1 09:02:30 UTC 2008


On Thu, May 01, 2008 at 11:27:58AM +0300, OOzy Pal wrote:
> On Thu, May 1, 2008 at 10:54 AM, Chris G <cl at isbd.net> wrote:
> > On Thu, May 01, 2008 at 10:41:21AM +0300, OOzy Pal wrote:
> >  > Hello,
> >  >
> >  > How can I move a file to a directory name DONE using perl. I tried
> >  > this but it did not work?
> >  >
> >  > $file='Myfile';
> >  > rename $file, 'Done/'$file;
> >  >
> >  ... and what error message did you get?  Does the directory exist (and
> >  remember 'DONE' and 'Done' are different in Linux/Unix)?
> >
> 
> Here is the error
> Scalar found where operator expected at /home/hab/bin/exiftool.pl line
> 45, near "'DONE/'$file"
>         (Missing operator before $file?)
> syntax error at /home/hab/bin/exiftool.pl line 45, near "'DONE/'$file"
> Execution of /home/hab/bin/exiftool.pl aborted due to compilation errors.
> 
My perl is a bit rusty (I've settled on Python as my language of
choice, much 'cleaner' IMHO) but the error is simple - you can't just
put 'Done/'$file and expect perl to concatenate the two.  You have to
use the string concatenation operator, e.g.:-

    rename $file, 'Done/' . $file;

-- 
Chris Green




More information about the ubuntu-users mailing list