G'day Bod,

"I'm curious why you used a sub given that it's a script, not a module, and it only gets called once."

My example code only called it once for demonstration purposes. A subroutine abstracts functionality and promotes reuseability; it has nothing to do with script vs. module. The OP's production code may want to use it multiple times.

Here's move_to_phone_4.pl which, after adding some files for my explanation to you, shows:

[Those last three points are mainly for the OP's benefit.]

#!/usr/bin/env perl use v5.36; use File::Copy 'move'; my ($source, $destination) = qw{Temp Phone}; mv_tmp_to_phone($source, $destination); mv_tmp_to_phone(qw{For_Bod Phone}); sub mv_tmp_to_phone ($src, $dest) { system ls => '-lR'; my @files = glob("$src/*"); say for @files; move($_, $dest) for @files; system ls => '-lR'; }

The output's getting lengthy but here's a sample run:

ken@titan ~/tmp/pm_11154302_move_files $ ./move_to_phone_4.pl .: total 4 drwxr-xr-x 1 ken None 0 Sep 9 08:42 For_Bod -rwxr-xr-x 1 ken None 337 Sep 8 18:05 move_to_phone.pl -rwxr-xr-x 1 ken None 335 Sep 9 07:07 move_to_phone_2.pl -rwxr-xr-x 1 ken None 319 Sep 9 08:14 move_to_phone_3.pl -rwxr-xr-x 1 ken None 356 Sep 9 09:02 move_to_phone_4.pl drwxr-xr-x 1 ken None 0 Sep 9 08:15 Phone drwxr-xr-x 1 ken None 0 Sep 9 08:15 Temp ./For_Bod: total 0 -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 3' -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 4' ./Phone: total 0 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file1 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file2 ./Temp: total 0 .: total 4 drwxr-xr-x 1 ken None 0 Sep 9 08:42 For_Bod -rwxr-xr-x 1 ken None 337 Sep 8 18:05 move_to_phone.pl -rwxr-xr-x 1 ken None 335 Sep 9 07:07 move_to_phone_2.pl -rwxr-xr-x 1 ken None 319 Sep 9 08:14 move_to_phone_3.pl -rwxr-xr-x 1 ken None 356 Sep 9 09:02 move_to_phone_4.pl drwxr-xr-x 1 ken None 0 Sep 9 08:15 Phone drwxr-xr-x 1 ken None 0 Sep 9 08:15 Temp ./For_Bod: total 0 -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 3' -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 4' ./Phone: total 0 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file1 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file2 ./Temp: total 0 .: total 4 drwxr-xr-x 1 ken None 0 Sep 9 08:42 For_Bod -rwxr-xr-x 1 ken None 337 Sep 8 18:05 move_to_phone.pl -rwxr-xr-x 1 ken None 335 Sep 9 07:07 move_to_phone_2.pl -rwxr-xr-x 1 ken None 319 Sep 9 08:14 move_to_phone_3.pl -rwxr-xr-x 1 ken None 356 Sep 9 09:02 move_to_phone_4.pl drwxr-xr-x 1 ken None 0 Sep 9 08:15 Phone drwxr-xr-x 1 ken None 0 Sep 9 08:15 Temp ./For_Bod: total 0 -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 3' -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 4' ./Phone: total 0 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file1 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file2 ./Temp: total 0 For_Bod/file 3 For_Bod/file 4 .: total 4 drwxr-xr-x 1 ken None 0 Sep 9 09:02 For_Bod -rwxr-xr-x 1 ken None 337 Sep 8 18:05 move_to_phone.pl -rwxr-xr-x 1 ken None 335 Sep 9 07:07 move_to_phone_2.pl -rwxr-xr-x 1 ken None 319 Sep 9 08:14 move_to_phone_3.pl -rwxr-xr-x 1 ken None 356 Sep 9 09:02 move_to_phone_4.pl drwxr-xr-x 1 ken None 0 Sep 9 09:02 Phone drwxr-xr-x 1 ken None 0 Sep 9 08:15 Temp ./For_Bod: total 0 ./Phone: total 0 -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 3' -rw-r--r-- 1 ken None 0 Sep 9 08:42 'file 4' -rw-r--r-- 1 ken None 0 Sep 8 17:50 file1 -rw-r--r-- 1 ken None 0 Sep 8 17:50 file2 ./Temp: total 0

— Ken


In reply to Re^5: how to move multiple files by kcott
in thread how to move multiple files by ObiPanda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.