in reply to How to use file copy with wild card characters

What if the wildcarded filename matches more than one file? What is the expected behavior?

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

  • Comment on Re: How to use file copy with wild card characters

Replies are listed 'Best First'.
Re^2: How to use file copy with wild card characters
by redhotpenguin (Deacon) on Dec 31, 2004 at 22:04 UTC
    File::Copy won't function without a $to and $from argument, so some naming convention for the new files is needed. I would approach it in this manner:

    map { copy($_, $_ . '.new') } glob("*.ext");
      While I agree that that is probably a good idea, it doesn't answer the question that I asked. It could be that the OP only wants to save one archived log. So, in that case, you could move every file in the glob to a static file name i.e.
      foreach my $file (glob('*.log')) { rename $file, "oldlog" or die "Oops: $!"; }
      I don't know about you, but I'm not psychic.

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

      Danger, Will Robinson! map in void context! I would write that like this instead:

      copy($_, "$_.new") for glob "*.ext";

      I think it's much easier to look at.

        what´s wrong with map in void context?