Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] trying to cp a file

Expand Messages
  • Chankey Pathak
    Use System command. ... -- Regards, Chankey Pathak [Non-text portions of this message have been removed]
    Message 1 of 14 , Oct 29, 2011
    • 0 Attachment
      Use System command.

      On Sat, Oct 29, 2011 at 4:59 PM, Paul.G <medura43@...> wrote:

      > **
      >
      >
      > system "cp /sds/ibr/waibr/submit/000000.1 junk.txt";
      >
      > give that a try.
      >
      > ________________________________
      > From: David Precious <davidp@...>
      > To: perl-beginner@yahoogroups.com
      > Sent: Saturday, 29 October 2011 5:04 AM
      > Subject: Re: [PBML] trying to cp a file
      >
      >
      > On Friday 28 October 2011 19:13:46 rmillergraysharbor wrote:
      > > Hi,
      > > I'm trying to use perl on solaris to copy a file which may have spaces in
      > > it. I can't even get it to work without spaces.
      > >
      > > On the command line, this works:
      > > cp "/sds/ibr/waibr/submit/000000.1" junk.txt
      > >
      > > In perl, I've been trying combinations of system and ` and ", and I'm
      > > getting: cp cannot access /sds/ibr/waibr/submit/000000.1
      > >
      > > If it works on the command line, why in the world won't it work in perl?
      > >
      > > My latest attempt is:
      > > `cp "$filename" junk.txt`;
      > >
      > > Can anyone tell me what I'm doing wrong?
      >
      > Save yourself hassle, and make your script more secure and portable, by
      > using
      > File::Copy:
      >
      > use File::Copy;
      > File::Copy::copy($filename, 'junk.txt)
      > or die "Failed to copy file - $!";
      >
      > That may make it work; if not, the error message will be more helpful to
      > help
      > you see why.
      >
      > --
      > David Precious ("bigpresh")
      > http://www.preshweb.co.uk/
      >
      > "Programming is like sex. One mistake and you have to support
      > it for the rest of your life". (Michael Sinz)
      >
      > [Non-text portions of this message have been removed]
      >
      >
      >



      --
      Regards,
      Chankey Pathak <http://javaenthusiastic.blogspot.com>


      [Non-text portions of this message have been removed]
    • Yatin Jadhav
      You can also try parsing varialbles as $a = /sds/ibr/waibr/submit/000000.1 junk.txt system( cp $a ); or if no variables are included:
      Message 2 of 14 , Oct 29, 2011
      • 0 Attachment
        You can also try parsing varialbles as
        $a = "/sds/ibr/waibr/submit/000000.1 junk.txt"
        system("cp $a");

        or if no variables are included:

        system('cp /sds/ibr/waibr/submit/000000.1 junk.txt');


        It also works with windows based systems just give any dos command :

        system ("copy D:/sds/ibr/waibr/submit/000000.1 junk.txt");

        Regards,
        yatin


        ________________________________
        From: Paul.G <medura43@...>
        To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
        Sent: Saturday, October 29, 2011 4:59 PM
        Subject: Re: [PBML] trying to cp a file


         
        system "cp /sds/ibr/waibr/submit/000000.1 junk.txt";

        give that a try.

        ________________________________
        From: David Precious <davidp@...>
        To: perl-beginner@yahoogroups.com
        Sent: Saturday, 29 October 2011 5:04 AM
        Subject: Re: [PBML] trying to cp a file

         
        On Friday 28 October 2011 19:13:46 rmillergraysharbor wrote:
        > Hi,
        > I'm trying to use perl on solaris to copy a file which may have spaces in
        > it. I can't even get it to work without spaces.
        >
        > On the command line, this works:
        > cp "/sds/ibr/waibr/submit/000000.1" junk.txt
        >
        > In perl, I've been trying combinations of system and ` and ", and I'm
        > getting: cp cannot access /sds/ibr/waibr/submit/000000.1
        >
        > If it works on the command line, why in the world won't it work in perl?
        >
        > My latest attempt is:
        > `cp "$filename" junk.txt`;
        >
        > Can anyone tell me what I'm doing wrong?

        Save yourself hassle, and make your script more secure and portable, by using
        File::Copy:

        use File::Copy;
        File::Copy::copy($filename, 'junk.txt)
        or die "Failed to copy file - $!";

        That may make it work; if not, the error message will be more helpful to help
        you see why.

        --
        David Precious ("bigpresh")
        http://www.preshweb.co.uk/

        "Programming is like sex. One mistake and you have to support
        it for the rest of your life". (Michael Sinz)

        [Non-text portions of this message have been removed]




        [Non-text portions of this message have been removed]
      • Paul.G
        Can t speak for windows, but I think for linux the brackets are not required. ________________________________ From: Yatin Jadhav To:
        Message 3 of 14 , Oct 29, 2011
        • 0 Attachment
          Can't speak for windows, but I think for linux the brackets are not required.



          ________________________________
          From: Yatin Jadhav <yatinjdhv@...>
          To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
          Sent: Saturday, 29 October 2011 9:54 PM
          Subject: Re: [PBML] trying to cp a file


           
          You can also try parsing varialbles as
          $a = "/sds/ibr/waibr/submit/000000.1 junk.txt"
          system("cp $a");

          or if no variables are included:

          system('cp /sds/ibr/waibr/submit/000000.1 junk.txt');

          It also works with windows based systems just give any dos command :

          system ("copy D:/sds/ibr/waibr/submit/000000.1 junk.txt");

          Regards,
          yatin

          ________________________________
          From: Paul.G <medura43@...>
          To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
          Sent: Saturday, October 29, 2011 4:59 PM
          Subject: Re: [PBML] trying to cp a file

           
          system "cp /sds/ibr/waibr/submit/000000.1 junk.txt";

          give that a try.

          ________________________________
          From: David Precious <davidp@...>
          To: perl-beginner@yahoogroups.com
          Sent: Saturday, 29 October 2011 5:04 AM
          Subject: Re: [PBML] trying to cp a file

           
          On Friday 28 October 2011 19:13:46 rmillergraysharbor wrote:
          > Hi,
          > I'm trying to use perl on solaris to copy a file which may have spaces in
          > it. I can't even get it to work without spaces.
          >
          > On the command line, this works:
          > cp "/sds/ibr/waibr/submit/000000.1" junk.txt
          >
          > In perl, I've been trying combinations of system and ` and ", and I'm
          > getting: cp cannot access /sds/ibr/waibr/submit/000000.1
          >
          > If it works on the command line, why in the world won't it work in perl?
          >
          > My latest attempt is:
          > `cp "$filename" junk.txt`;
          >
          > Can anyone tell me what I'm doing wrong?

          Save yourself hassle, and make your script more secure and portable, by using
          File::Copy:

          use File::Copy;
          File::Copy::copy($filename, 'junk.txt)
          or die "Failed to copy file - $!";

          That may make it work; if not, the error message will be more helpful to help
          you see why.

          --
          David Precious ("bigpresh")
          http://www.preshweb.co.uk/

          "Programming is like sex. One mistake and you have to support
          it for the rest of your life". (Michael Sinz)

          [Non-text portions of this message have been removed]

          [Non-text portions of this message have been removed]




          [Non-text portions of this message have been removed]
        • rmillergraysharbor
          After a nice long weekend, I am back trying to cp a file in perl. I am on a Sun Solaris box. Thanks for all of your responses, but still no luck. I ve tried 3
          Message 4 of 14 , Oct 31, 2011
          • 0 Attachment
            After a nice long weekend, I am back trying to cp a file in perl.
            I am on a Sun Solaris box.

            Thanks for all of your responses, but still no luck.

            I've tried 3 things.
            ________________________________________________
            use File::Copy;
            my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`;
            print $filename;
            File::Copy::copy("$filename",'junk.txt')
            or die "Failed to copy file - $!";

            Getting:
            /sds/ibr/waibrs/submit/SPD/000000.3
            Unsuccessful open on filename containing newline at /usr/local/lib/perl5/5.8.0/F ile/Copy.pm line 119.
            Failed to copy file - No such file or directory at ./test.sh line 11.

            I also tried with " instead of ' around junk.txt.
            Please note that it can print $filename, so it can find $filename, just not within the context of my copy command. ??
            ________________________________________________________________


            my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`;
            print $filename;
            system "cp /sds/ibr/waibr/submit/000000.1 junk.txt"

            Getting:
            /sds/ibr/waibrs/submit/SPD/000000.3
            cp: Insufficient arguments (1)
            Usage: cp [-f] [-i] [-p] [-@] f1 f2
            cp [-f] [-i] [-p] [-@] f1 ... fn d1
            cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
            sh: junk.txt: not found

            Again, it prints $filename, so it can find $filename, but not within the context of my command.

            Also, I don't think this would work when there are spaces in the filename, will it?

            ___________________________________________________
            Per parsing variables, I tried:

            my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`;
            print $filename;
            $a = "/sds/ibr/waibr/submit/000000.1 junk.txt"
            system("cp $a");

            I get
            /sds/ibr/waibrs/submit/SPD/000000.3
            Can't call method "cp" without a package or object reference at ./test.sh line 15.


            Thanks again for any help.
            Regina




            --- In perl-beginner@yahoogroups.com, "Paul.G" <medura43@...> wrote:
            >
            > Can't speak for windows, but I think for linux the brackets are not required.
            >
            >
            >
            > ________________________________
            > From: Yatin Jadhav <yatinjdhv@...>
            > To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
            > Sent: Saturday, 29 October 2011 9:54 PM
            > Subject: Re: [PBML] trying to cp a file
            >
            >
            >  
            > You can also try parsing varialbles as
            > $a = "/sds/ibr/waibr/submit/000000.1 junk.txt"
            > system("cp $a");
            >
            > or if no variables are included:
            >
            > system('cp /sds/ibr/waibr/submit/000000.1 junk.txt');
            >
            > It also works with windows based systems just give any dos command :
            >
            > system ("copy D:/sds/ibr/waibr/submit/000000.1 junk.txt");
            >
            > Regards,
            > yatin
            >
            > ________________________________
            > From: Paul.G <medura43@...>
            > To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
            > Sent: Saturday, October 29, 2011 4:59 PM
            > Subject: Re: [PBML] trying to cp a file
            >
            >  
            > system "cp /sds/ibr/waibr/submit/000000.1 junk.txt";
            >
            > give that a try.
            >
            > ________________________________
            > From: David Precious <davidp@...>
            > To: perl-beginner@yahoogroups.com
            > Sent: Saturday, 29 October 2011 5:04 AM
            > Subject: Re: [PBML] trying to cp a file
            >
            >  
            > On Friday 28 October 2011 19:13:46 rmillergraysharbor wrote:
            > > Hi,
            > > I'm trying to use perl on solaris to copy a file which may have spaces in
            > > it. I can't even get it to work without spaces.
            > >
            > > On the command line, this works:
            > > cp "/sds/ibr/waibr/submit/000000.1" junk.txt
            > >
            > > In perl, I've been trying combinations of system and ` and ", and I'm
            > > getting: cp cannot access /sds/ibr/waibr/submit/000000.1
            > >
            > > If it works on the command line, why in the world won't it work in perl?
            > >
            > > My latest attempt is:
            > > `cp "$filename" junk.txt`;
            > >
            > > Can anyone tell me what I'm doing wrong?
            >
            > Save yourself hassle, and make your script more secure and portable, by using
            > File::Copy:
            >
            > use File::Copy;
            > File::Copy::copy($filename, 'junk.txt)
            > or die "Failed to copy file - $!";
            >
            > That may make it work; if not, the error message will be more helpful to help
            > you see why.
            >
            > --
            > David Precious ("bigpresh")
            > http://www.preshweb.co.uk/
            >
            > "Programming is like sex. One mistake and you have to support
            > it for the rest of your life". (Michael Sinz)
            >
            > [Non-text portions of this message have been removed]
            >
            > [Non-text portions of this message have been removed]
            >
            >
            >
            >
            > [Non-text portions of this message have been removed]
            >
          • Rajagopal, Jay
            Did you chomp? ... From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of rmillergraysharbor Sent: Monday, October 31, 2011
            Message 5 of 14 , Oct 31, 2011
            • 0 Attachment
              Did you chomp?

              -----Original Message-----
              From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of rmillergraysharbor
              Sent: Monday, October 31, 2011 1:57 PM
              To: perl-beginner@yahoogroups.com
              Subject: Re: [PBML] trying to cp a file

              After a nice long weekend, I am back trying to cp a file in perl.
              I am on a Sun Solaris box.

              Thanks for all of your responses, but still no luck.

              I've tried 3 things.
              ________________________________________________
              use File::Copy;
              my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`; print $filename;
              File::Copy::copy("$filename",'junk.txt')
              or die "Failed to copy file - $!";

              Getting:
              /sds/ibr/waibrs/submit/SPD/000000.3
              Unsuccessful open on filename containing newline at /usr/local/lib/perl5/5.8.0/F ile/Copy.pm line 119.
              Failed to copy file - No such file or directory at ./test.sh line 11.

              I also tried with " instead of ' around junk.txt.
              Please note that it can print $filename, so it can find $filename, just not within the context of my copy command. ??
              ________________________________________________________________


              my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`; print $filename; system "cp /sds/ibr/waibr/submit/000000.1 junk.txt"

              Getting:
              /sds/ibr/waibrs/submit/SPD/000000.3
              cp: Insufficient arguments (1)
              Usage: cp [-f] [-i] [-p] [-@] f1 f2
              cp [-f] [-i] [-p] [-@] f1 ... fn d1
              cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
              sh: junk.txt: not found

              Again, it prints $filename, so it can find $filename, but not within the context of my command.

              Also, I don't think this would work when there are spaces in the filename, will it?

              ___________________________________________________
              Per parsing variables, I tried:

              my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`; print $filename; $a = "/sds/ibr/waibr/submit/000000.1 junk.txt"
              system("cp $a");

              I get
              /sds/ibr/waibrs/submit/SPD/000000.3
              Can't call method "cp" without a package or object reference at ./test.sh line 15.


              Thanks again for any help.
              Regina




              --- In perl-beginner@yahoogroups.com, "Paul.G" <medura43@...> wrote:
              >
              > Can't speak for windows, but I think for linux the brackets are not required.
              >
              >
              >
              > ________________________________
              > From: Yatin Jadhav <yatinjdhv@...>
              > To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
              > Sent: Saturday, 29 October 2011 9:54 PM
              > Subject: Re: [PBML] trying to cp a file
              >
              >
              > Â
              > You can also try parsing varialbles as $a =
              > "/sds/ibr/waibr/submit/000000.1 junk.txt"
              > system("cp $a");
              >
              > or if no variables are included:
              >
              > system('cp /sds/ibr/waibr/submit/000000.1 junk.txt');
              >
              > It also works with windows based systems just give any dos command :
              >
              > system ("copy D:/sds/ibr/waibr/submit/000000.1 junk.txt");
              >
              > Regards,
              > yatin
              >
              > ________________________________
              > From: Paul.G <medura43@...>
              > To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
              > Sent: Saturday, October 29, 2011 4:59 PM
              > Subject: Re: [PBML] trying to cp a file
              >
              > Â
              > system "cp /sds/ibr/waibr/submit/000000.1 junk.txt";
              >
              > give that a try.
              >
              > ________________________________
              > From: David Precious <davidp@...>
              > To: perl-beginner@yahoogroups.com
              > Sent: Saturday, 29 October 2011 5:04 AM
              > Subject: Re: [PBML] trying to cp a file
              >
              > Â
              > On Friday 28 October 2011 19:13:46 rmillergraysharbor wrote:
              > > Hi,
              > > I'm trying to use perl on solaris to copy a file which may have
              > > spaces in it. I can't even get it to work without spaces.
              > >
              > > On the command line, this works:
              > > cp "/sds/ibr/waibr/submit/000000.1" junk.txt
              > >
              > > In perl, I've been trying combinations of system and ` and ", and
              > > I'm
              > > getting: cp cannot access /sds/ibr/waibr/submit/000000.1
              > >
              > > If it works on the command line, why in the world won't it work in perl?
              > >
              > > My latest attempt is:
              > > `cp "$filename" junk.txt`;
              > >
              > > Can anyone tell me what I'm doing wrong?
              >
              > Save yourself hassle, and make your script more secure and portable,
              > by using
              > File::Copy:
              >
              > use File::Copy;
              > File::Copy::copy($filename, 'junk.txt) or die "Failed to copy file -
              > $!";
              >
              > That may make it work; if not, the error message will be more helpful
              > to help you see why.
              >
              > --
              > David Precious ("bigpresh")
              > http://www.preshweb.co.uk/
              >
              > "Programming is like sex. One mistake and you have to support it for
              > the rest of your life". (Michael Sinz)
              >
              > [Non-text portions of this message have been removed]
              >
              > [Non-text portions of this message have been removed]
              >
              >
              >
              >
              > [Non-text portions of this message have been removed]
              >




              ------------------------------------

              Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links




              T. Rowe Price (including T. Rowe Price Group, Inc. and its affiliates) and its associates do not provide legal or tax advice. Any tax-related discussion contained in this e-mail, including any attachments, is not intended or written to be used, and cannot be used, for the purpose of (i) avoiding any tax penalties or (ii) promoting, marketing, or recommending to any other party any transaction or matter addressed herein. Please consult your independent legal counsel and/or professional tax advisor regarding any legal or tax issues raised in this e-mail.

              The contents of this e-mail and any attachments are intended solely for the use of the named addressee(s) and may contain confidential and/or privileged information. Any unauthorized use, copying, disclosure, or distribution of the contents of this e-mail is strictly prohibited by the sender and may be unlawful. If you are not the intended recipient, please notify the sender immediately and delete this e-mail.
            • merlyn@stonehenge.com
              ... rmillergraysharbor my($filename) = `ls -at1 rmillergraysharbor /sds/ibr/waibrs/submit/SPD/00*`; Why are you using ls when Perl is perfectly good at
              Message 6 of 14 , Oct 31, 2011
              • 0 Attachment
                >>>>> "rmillergraysharbor" == rmillergraysharbor <rmiller@...-harbor.wa.us> writes:

                rmillergraysharbor> my($filename) = `ls -at1
                rmillergraysharbor> /sds/ibr/waibrs/submit/SPD/00*`;

                Why are you using "ls" when Perl is perfectly good at globbing?

                my @names = glob "/sds/ibr/waibrs/submit/SPD/00*";

                And then figure out which name you want.

                --
                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                See http://methodsandmessages.posterous.com/ for Smalltalk discussion
              • Regina Miller
                Because I want the latest one, so I need them in order, not by name, but by datetime. ... From: Randal L. Schwartz [mailto:merlyn@stonehenge.com] Sent: Monday,
                Message 7 of 14 , Oct 31, 2011
                • 0 Attachment
                  Because I want the latest one, so I need them in order, not by name, but
                  by datetime.


                  -----Original Message-----
                  From: Randal L. Schwartz [mailto:merlyn@...]
                  Sent: Monday, October 31, 2011 11:01 AM
                  To: Regina Miller
                  Cc: perl-beginner@yahoogroups.com
                  Subject: Re: [PBML] trying to cp a file

                  >>>>> "rmillergraysharbor" == rmillergraysharbor
                  <rmiller@...-harbor.wa.us> writes:

                  rmillergraysharbor> my($filename) = `ls -at1
                  rmillergraysharbor> /sds/ibr/waibrs/submit/SPD/00*`;

                  Why are you using "ls" when Perl is perfectly good at globbing?

                  my @names = glob "/sds/ibr/waibrs/submit/SPD/00*";

                  And then figure out which name you want.

                  --
                  Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
                  0095 <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                  Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                  See http://methodsandmessages.posterous.com/ for Smalltalk discussion
                • rmillergraysharbor
                  That was it! I didn t chomp! Oh, thank you. And thanks to everyone for their help. Regina
                  Message 8 of 14 , Oct 31, 2011
                  • 0 Attachment
                    That was it!
                    I didn't chomp!

                    Oh, thank you.

                    And thanks to everyone for their help.

                    Regina

                    --- In perl-beginner@yahoogroups.com, "Rajagopal, Jay" <jay_rajagopal@...> wrote:
                    >
                    > Did you chomp?
                    >
                    > -----Original Message-----
                    > From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of rmillergraysharbor
                    > Sent: Monday, October 31, 2011 1:57 PM
                    > To: perl-beginner@yahoogroups.com
                    > Subject: Re: [PBML] trying to cp a file
                    >
                    > After a nice long weekend, I am back trying to cp a file in perl.
                    > I am on a Sun Solaris box.
                    >
                    > Thanks for all of your responses, but still no luck.
                    >
                    > I've tried 3 things.
                    > ________________________________________________
                    > use File::Copy;
                    > my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`; print $filename;
                    > File::Copy::copy("$filename",'junk.txt')
                    > or die "Failed to copy file - $!";
                    >
                    > Getting:
                    > /sds/ibr/waibrs/submit/SPD/000000.3
                    > Unsuccessful open on filename containing newline at /usr/local/lib/perl5/5.8.0/F ile/Copy.pm line 119.
                    > Failed to copy file - No such file or directory at ./test.sh line 11.
                    >
                    > I also tried with " instead of ' around junk.txt.
                    > Please note that it can print $filename, so it can find $filename, just not within the context of my copy command. ??
                    > ________________________________________________________________
                    >
                    >
                    > my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`; print $filename; system "cp /sds/ibr/waibr/submit/000000.1 junk.txt"
                    >
                    > Getting:
                    > /sds/ibr/waibrs/submit/SPD/000000.3
                    > cp: Insufficient arguments (1)
                    > Usage: cp [-f] [-i] [-p] [-@] f1 f2
                    > cp [-f] [-i] [-p] [-@] f1 ... fn d1
                    > cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
                    > sh: junk.txt: not found
                    >
                    > Again, it prints $filename, so it can find $filename, but not within the context of my command.
                    >
                    > Also, I don't think this would work when there are spaces in the filename, will it?
                    >
                    > ___________________________________________________
                    > Per parsing variables, I tried:
                    >
                    > my($filename) = `ls -at1 /sds/ibr/waibrs/submit/SPD/00*`; print $filename; $a = "/sds/ibr/waibr/submit/000000.1 junk.txt"
                    > system("cp $a");
                    >
                    > I get
                    > /sds/ibr/waibrs/submit/SPD/000000.3
                    > Can't call method "cp" without a package or object reference at ./test.sh line 15.
                    >
                    >
                    > Thanks again for any help.
                    > Regina
                    >
                    >
                    >
                    >
                    > --- In perl-beginner@yahoogroups.com, "Paul.G" <medura43@> wrote:
                    > >
                    > > Can't speak for windows, but I think for linux the brackets are not required.
                    > >
                    > >
                    > >
                    > > ________________________________
                    > > From: Yatin Jadhav <yatinjdhv@>
                    > > To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
                    > > Sent: Saturday, 29 October 2011 9:54 PM
                    > > Subject: Re: [PBML] trying to cp a file
                    > >
                    > >
                    > > Â
                    > > You can also try parsing varialbles as $a =
                    > > "/sds/ibr/waibr/submit/000000.1 junk.txt"
                    > > system("cp $a");
                    > >
                    > > or if no variables are included:
                    > >
                    > > system('cp /sds/ibr/waibr/submit/000000.1 junk.txt');
                    > >
                    > > It also works with windows based systems just give any dos command :
                    > >
                    > > system ("copy D:/sds/ibr/waibr/submit/000000.1 junk.txt");
                    > >
                    > > Regards,
                    > > yatin
                    > >
                    > > ________________________________
                    > > From: Paul.G <medura43@>
                    > > To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
                    > > Sent: Saturday, October 29, 2011 4:59 PM
                    > > Subject: Re: [PBML] trying to cp a file
                    > >
                    > > Â
                    > > system "cp /sds/ibr/waibr/submit/000000.1 junk.txt";
                    > >
                    > > give that a try.
                    > >
                    > > ________________________________
                    > > From: David Precious <davidp@>
                    > > To: perl-beginner@yahoogroups.com
                    > > Sent: Saturday, 29 October 2011 5:04 AM
                    > > Subject: Re: [PBML] trying to cp a file
                    > >
                    > > Â
                    > > On Friday 28 October 2011 19:13:46 rmillergraysharbor wrote:
                    > > > Hi,
                    > > > I'm trying to use perl on solaris to copy a file which may have
                    > > > spaces in it. I can't even get it to work without spaces.
                    > > >
                    > > > On the command line, this works:
                    > > > cp "/sds/ibr/waibr/submit/000000.1" junk.txt
                    > > >
                    > > > In perl, I've been trying combinations of system and ` and ", and
                    > > > I'm
                    > > > getting: cp cannot access /sds/ibr/waibr/submit/000000.1
                    > > >
                    > > > If it works on the command line, why in the world won't it work in perl?
                    > > >
                    > > > My latest attempt is:
                    > > > `cp "$filename" junk.txt`;
                    > > >
                    > > > Can anyone tell me what I'm doing wrong?
                    > >
                    > > Save yourself hassle, and make your script more secure and portable,
                    > > by using
                    > > File::Copy:
                    > >
                    > > use File::Copy;
                    > > File::Copy::copy($filename, 'junk.txt) or die "Failed to copy file -
                    > > $!";
                    > >
                    > > That may make it work; if not, the error message will be more helpful
                    > > to help you see why.
                    > >
                    > > --
                    > > David Precious ("bigpresh")
                    > > http://www.preshweb.co.uk/
                    > >
                    > > "Programming is like sex. One mistake and you have to support it for
                    > > the rest of your life". (Michael Sinz)
                    > >
                    > > [Non-text portions of this message have been removed]
                    > >
                    > > [Non-text portions of this message have been removed]
                    > >
                    > >
                    > >
                    > >
                    > > [Non-text portions of this message have been removed]
                    > >
                    >
                    >
                    >
                    >
                    > ------------------------------------
                    >
                    > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo! Groups Links
                    >
                    >
                    >
                    >
                    > T. Rowe Price (including T. Rowe Price Group, Inc. and its affiliates) and its associates do not provide legal or tax advice. Any tax-related discussion contained in this e-mail, including any attachments, is not intended or written to be used, and cannot be used, for the purpose of (i) avoiding any tax penalties or (ii) promoting, marketing, or recommending to any other party any transaction or matter addressed herein. Please consult your independent legal counsel and/or professional tax advisor regarding any legal or tax issues raised in this e-mail.
                    >
                    > The contents of this e-mail and any attachments are intended solely for the use of the named addressee(s) and may contain confidential and/or privileged information. Any unauthorized use, copying, disclosure, or distribution of the contents of this e-mail is strictly prohibited by the sender and may be unlawful. If you are not the intended recipient, please notify the sender immediately and delete this e-mail.
                    >
                  • David Precious
                    ... Then do so in Perl, in a robust and portable way: my @files_sorted = sort { -M $a -M $b } glob /sds/ibr/waibrs/submit/SPD/00* ; That will give you the
                    Message 9 of 14 , Oct 31, 2011
                    • 0 Attachment
                      On Monday 31 October 2011 18:16:19 Regina Miller wrote:
                      > From: Randal L. Schwartz [mailto:merlyn@...]
                      > > Why are you using "ls" when Perl is perfectly good at globbing?
                      > >
                      > > my @names = glob "/sds/ibr/waibrs/submit/SPD/00*";
                      > >
                      > > And then figure out which name you want.

                      > Because I want the latest one, so I need them in order, not by name, but
                      > by datetime.

                      Then do so in Perl, in a robust and portable way:

                      my @files_sorted = sort { -M $a <=> -M $b }
                      glob "/sds/ibr/waibrs/submit/SPD/00*";

                      That will give you the matching files, sorted by modification time, oldest
                      first.

                      If you only want the first one, either then say $files_sorted[0] to get it, or
                      capture only the first one with:

                      my ($oldest_file) = sort { -M $a <=> -M $b }
                      glob "/sds/ibr/waibrs/submit/SPD/00*";
                    • David Precious
                      ... Yup, the newline from the `ls -at1` output was the reason behind the (fairly clear) error message you received when using File::Copy. Whilst you now have a
                      Message 10 of 14 , Oct 31, 2011
                      • 0 Attachment
                        On Monday 31 October 2011 18:23:03 rmillergraysharbor wrote:
                        > That was it!
                        > I didn't chomp!

                        Yup, the newline from the `ls -at1` output was the reason behind the (fairly
                        clear) error message you received when using File::Copy.

                        Whilst you now have a script doing what you want, for the sake of your future
                        code and those who come after you, I would urge you to consider executing
                        things like 'cp', 'ls' etc a Bad Thing, often leading to non-portable code
                        with potential security vulnerabilities - if you can avoid executing shell
                        commands and just do it in Perl, it'll usually be more secure and more
                        portable.

                        Otherwise, you may as well be writing a shell script :)
                      • rmillergraysharbor
                        Thank you for the advice. And thanks to David Precious for the sample code that is more Perl-specific. I appreciate it. Regina
                        Message 11 of 14 , Oct 31, 2011
                        • 0 Attachment
                          Thank you for the advice.
                          And thanks to David Precious for the sample code that is more Perl-specific.

                          I appreciate it.

                          Regina
                          --- In perl-beginner@yahoogroups.com, David Precious <davidp@...> wrote:
                          >
                          > On Monday 31 October 2011 18:23:03 rmillergraysharbor wrote:
                          > > That was it!
                          > > I didn't chomp!
                          >
                          > Yup, the newline from the `ls -at1` output was the reason behind the (fairly
                          > clear) error message you received when using File::Copy.
                          >
                          > Whilst you now have a script doing what you want, for the sake of your future
                          > code and those who come after you, I would urge you to consider executing
                          > things like 'cp', 'ls' etc a Bad Thing, often leading to non-portable code
                          > with potential security vulnerabilities - if you can avoid executing shell
                          > commands and just do it in Perl, it'll usually be more secure and more
                          > portable.
                          >
                          > Otherwise, you may as well be writing a shell script :)
                          >
                        Your message has been successfully submitted and would be delivered to recipients shortly.