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

RE: [PBML] Perl and regular expressions?

Expand Messages
  • Rajagopal, Jay
    Please send code of what you are doing. And varying samples of the file name. Given a file name with such a format, how you define which is (nnn) ? ... From:
    Message 1 of 12 , Mar 28, 2011
    • 0 Attachment
      Please send code of what you are doing. And varying samples of the file name.
      Given a file name with such a format, how you define which is (nnn) ?

      -----Original Message-----
      From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of keithdlee2000
      Sent: Monday, March 28, 2011 4:16 PM
      To: perl-beginner@yahoogroups.com
      Subject: [PBML] Perl and regular expressions?

      All:
      I am having problems attempting to change the name of a file from -- filename (nnn) date to filename date (nnn). I am attempting to change the files using Perl's regular expressions. Does anyone have any clues on this?


      Keith Lee



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

      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.
    • Tim Lewis
      Is it delimited by spaces? One option: my $fileName = myfile 123 032911 ; my @filePieces = split(/ /,$fileName); my $newFileName = $filePieces[0] . .
      Message 2 of 12 , Mar 29, 2011
      • 0 Attachment
        Is it delimited by spaces? One option:
        my $fileName = "myfile 123 032911";
        my @filePieces = split(/ /,$fileName);
        my $newFileName = $filePieces[0] . " " . $filePieces[2] . " " . $filePieces[1];
        print "newFileName is $newFileName\n";

        ---- keithdlee2000 <keithdlee@...> wrote:
        > All:
        > I am having problems attempting to change the name of a file from -- filename (nnn) date to filename date (nnn). I am attempting to change the files using Perl's regular expressions. Does anyone have any clues on this?
        >
        >
        > Keith Lee
        >
      • Rajagopal, Jay
        ... From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of Tim Lewis Sent: Tuesday, March 29, 2011 10:01 AM To:
        Message 3 of 12 , Mar 29, 2011
        • 0 Attachment
          ***Is it delimited by spaces?***
          :-)

          -----Original Message-----
          From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of Tim Lewis
          Sent: Tuesday, March 29, 2011 10:01 AM
          To: perl-beginner@yahoogroups.com
          Subject: Re: [PBML] Perl and regular expressions?

          Is it delimited by spaces? One option:
          my $fileName = "myfile 123 032911";
          my @filePieces = split(/ /,$fileName);
          my $newFileName = $filePieces[0] . " " . $filePieces[2] . " " . $filePieces[1]; print "newFileName is $newFileName\n";

          ---- keithdlee2000 <keithdlee@...> wrote:
          > All:
          > I am having problems attempting to change the name of a file from -- filename (nnn) date to filename date (nnn). I am attempting to change the files using Perl's regular expressions. Does anyone have any clues on this?
          >
          >
          > Keith Lee
          >



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

          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.
        • Tim Lewis
          I realize it was grabbing at straws, but if the file has a space between the sections, then it would be easy to parse and reassembly. Just trying to help a
          Message 4 of 12 , Mar 29, 2011
          • 0 Attachment
            I realize it was grabbing at straws, but if the file has a space between the sections, then it would be easy to parse and reassembly. Just trying to help a brother out :)

            ---- "Rajagopal wrote:
            > ***Is it delimited by spaces?***
            > :-)
            >
            > -----Original Message-----
            > From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of Tim Lewis
            > Sent: Tuesday, March 29, 2011 10:01 AM
            > To: perl-beginner@yahoogroups.com
            > Subject: Re: [PBML] Perl and regular expressions?
            >
            > Is it delimited by spaces? One option:
            > my $fileName = "myfile 123 032911";
            > my @filePieces = split(/ /,$fileName);
            > my $newFileName = $filePieces[0] . " " . $filePieces[2] . " " . $filePieces[1]; print "newFileName is $newFileName\n";
            >
            > ---- keithdlee2000 <keithdlee@...> wrote:
            > > All:
            > > I am having problems attempting to change the name of a file from -- filename (nnn) date to filename date (nnn). I am attempting to change the files using Perl's regular expressions. Does anyone have any clues on this?
            > >
            > >
            > > Keith Lee
            > >
            >
            >
            >
            > ------------------------------------
            >
            > 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.
            >
          • Edward Willekens
            under the assumption that filename is all characters (no numbers) $f= abcd123112299 ; $f=~s/([ a]*)([0-9][0-9][0-9])(.*)/$1$3$2/; print $f. n ; Regards,  
            Message 5 of 12 , Mar 30, 2011
            • 0 Attachment
              under the assumption that filename is all characters (no numbers)

              $f="abcd123112299";
              $f=~s/([\a]*)([0-9][0-9][0-9])(.*)/$1$3$2/;
              print $f."\n";

              Regards,
                Edward Willekens


              --- On Tue, 3/29/11, Tim Lewis <twlewis@...> wrote:

              From: Tim Lewis <twlewis@...>
              Subject: RE: [PBML] Perl and regular expressions?
              To: perl-beginner@yahoogroups.com
              Date: Tuesday, March 29, 2011, 8:51 AM







               









              I realize it was grabbing at straws, but if the file has a space between the sections, then it would be easy to parse and reassembly. Just trying to help a brother out :)



              ---- "Rajagopal wrote:

              > ***Is it delimited by spaces?***

              > :-)

              >

              > -----Original Message-----

              > From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] On Behalf Of Tim Lewis

              > Sent: Tuesday, March 29, 2011 10:01 AM

              > To: perl-beginner@yahoogroups.com

              > Subject: Re: [PBML] Perl and regular expressions?

              >

              > Is it delimited by spaces? One option:

              > my $fileName = "myfile 123 032911";

              > my @filePieces = split(/ /,$fileName);

              > my $newFileName = $filePieces[0] . " " . $filePieces[2] . " " . $filePieces[1]; print "newFileName is $newFileName\n";

              >

              > ---- keithdlee2000 <keithdlee@...> wrote:

              > > All:

              > > I am having problems attempting to change the name of a file from -- filename (nnn) date to filename date (nnn). I am attempting to change the files using Perl's regular expressions. Does anyone have any clues on this?

              > >

              > >

              > > Keith Lee

              > >

              >

              >

              >

              > ------------------------------------

              >

              > 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.

              >






















              [Non-text portions of this message have been removed]
            • merlyn@stonehenge.com
              ... Edward under the assumption that filename is all characters (no numbers) Edward $f= abcd123112299 ; Edward $f=~s/([ a]*)([0-9][0-9][0-9])(.*)/$1$3$2/;
              Message 6 of 12 , Mar 31, 2011
              • 0 Attachment
                >>>>> "Edward" == Edward Willekens <edwardwillekens@...> writes:

                Edward> under the assumption that filename is all characters (no numbers)
                Edward> $f="abcd123112299";
                Edward> $f=~s/([\a]*)([0-9][0-9][0-9])(.*)/$1$3$2/;
                Edward> print $f."\n";

                and /\d/ is the same as /[0-9]/, and a lot easier to type.

                --
                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
              • Shlomi Fish
                Hi Randal, Edward, and all. This message is in UTF-8. ... Well, just to be a bit pedantic: d matches any digit character in Unicode. As a result: [IRC_LOG]
                Message 7 of 12 , Apr 1 1:08 AM
                • 0 Attachment
                  Hi Randal, Edward, and all.

                  This message is in UTF-8.

                  On Thursday 31 Mar 2011 15:43:42 merlyn@... wrote:
                  > >>>>> "Edward" == Edward Willekens <edwardwillekens@...> writes:
                  > Edward> under the assumption that filename is all characters (no numbers)
                  > Edward> $f="abcd123112299";
                  > Edward> $f=~s/([\a]*)([0-9][0-9][0-9])(.*)/$1$3$2/;
                  > Edward> print $f."\n";
                  >
                  > and /\d/ is the same as /[0-9]/, and a lot easier to type.

                  Well, just to be a bit pedantic: \d matches any digit character in Unicode. As
                  a result:

                  [IRC_LOG]
                  Mar 25 19:42:18 <rindolf> perlbot: eval: ["٣" =~ /\d/ ? "Match" :
                  "Nomatch"]
                  Mar 25 19:42:21 <perlbot> rindolf: ["Match"]
                  Mar 25 19:42:24 <rindolf> Yay!
                  [/IRC_LOG]

                  "٣" is the digit "3" in
                  http://en.wikipedia.org/wiki/Hindu%E2%80%93Arabic_numeral_system which is used
                  in Written Arabic, among other contexts. Naturally, there are also probably
                  calculator digits in Unicode, and various other variations of digits which \d
                  will happily match.

                  So [0-9] is sometimes a safer choice, if you wish to avoid ASCIIification
                  and/or cultural imperialism.

                  Give me ASCII or give me deaþ!

                  Regards,

                  Shlomi Fish

                  --
                  -----------------------------------------------------------------
                  Shlomi Fish http://www.shlomifish.org/
                  Best Introductory Programming Language - http://shlom.in/intro-lang

                  Doing linear scans over an associative array is like trying to club someone to
                  death with a loaded Uzi. -- Larry Wall

                  Please reply to list if it's a mailing list post - http://shlom.in/reply .
                • Tim Lewis
                  This may be a simple question, but I have searched for this answer. Suppose I have a multi-di array. I can make it sort by any one element. But what I need
                  Message 8 of 12 , Apr 7 10:28 AM
                  • 0 Attachment
                    This may be a simple question, but I have searched for this answer.
                    Suppose I have a multi-di array. I can make it sort by any one element. But what I need to sort by two? In my simple example below, what if I wanted to sort by the animal name, and then by number of legs? I am grateful for any help or tips on this.

                    #!/usr/local/bin/perl
                    use strict;
                    use warnings;

                    my @critters; #multi-di with animal name and number of legs
                    $critters[0][0] = "dog";
                    $critters[0][1] = "4";
                    $critters[1][0] = "cat";
                    $critters[1][1] = "4";
                    $critters[2][0] = "monkey";
                    $critters[2][1] = "2";

                    #I know I can sort by any one field with
                    @critters = sort { $a->[0] cmp $b->[0] } @critters;
                    my $critterCount= @critters;
                    for (my $count=0;$count<$critterCount;$count++) {
                    print "The critter $critters[$count][0] has $critters[$count][1] legs\n";
                    }
                  • merlyn@stonehenge.com
                    ... Tim Suppose I have a multi-di array. I can make it sort by any one Tim element. But what I need to sort by two? In my simple example Tim below, what
                    Message 9 of 12 , Apr 7 10:58 AM
                    • 0 Attachment
                      >>>>> "Tim" == Tim Lewis <twlewis@...> writes:

                      Tim> Suppose I have a multi-di array. I can make it sort by any one
                      Tim> element. But what I need to sort by two? In my simple example
                      Tim> below, what if I wanted to sort by the animal name, and then by
                      Tim> number of legs? I am grateful for any help or tips on this.

                      Since that can be interpreted two ways, I'm going to pretend you
                      actually said "with the major sort by animal name, using the number of
                      legs to break ties as a secondary sort".

                      Tim> my @critters; #multi-di with animal name and number of legs
                      Tim> $critters[0][0] = "dog";
                      Tim> $critters[0][1] = "4";
                      Tim> $critters[1][0] = "cat";
                      Tim> $critters[1][1] = "4";
                      Tim> $critters[2][0] = "monkey";
                      Tim> $critters[2][1] = "2";

                      my @sorted = sort {
                      $a->[0] cmp $b->[0]
                      or $a->[1] <=> $b->[1];
                      } @critters;

                      This is covered in the Alpaca book.

                      And now, for the traditional "don't post here" comment:

                      **************************************************
                      *
                      * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
                      *
                      * The official one is at beginners@..., with instructions on how to
                      * join at http://lists.perl.org/list/beginners.html.
                      *
                      * You'll get far better response there, not to say you won't get *any* here.
                      *
                      **************************************************


                      --
                      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
                    • Tim Lewis
                      Thanks Randall. I was close. I was using cmp instead of for the number portion. Thanks again. I did not know about the other listserver, and found this
                      Message 10 of 12 , Apr 7 11:10 AM
                      • 0 Attachment
                        Thanks Randall. I was close. I was using "cmp" instead of <=> for the number portion.

                        Thanks again.
                        I did not know about the other listserver, and found this one on Yahoo. I will check out the other one.


                        Tim

                        ---- merlyn@... wrote:
                        > >>>>> "Tim" == Tim Lewis <twlewis@...> writes:
                        >
                        > Tim> Suppose I have a multi-di array. I can make it sort by any one
                        > Tim> element. But what I need to sort by two? In my simple example
                        > Tim> below, what if I wanted to sort by the animal name, and then by
                        > Tim> number of legs? I am grateful for any help or tips on this.
                        >
                        > Since that can be interpreted two ways, I'm going to pretend you
                        > actually said "with the major sort by animal name, using the number of
                        > legs to break ties as a secondary sort".
                        >
                        > Tim> my @critters; #multi-di with animal name and number of legs
                        > Tim> $critters[0][0] = "dog";
                        > Tim> $critters[0][1] = "4";
                        > Tim> $critters[1][0] = "cat";
                        > Tim> $critters[1][1] = "4";
                        > Tim> $critters[2][0] = "monkey";
                        > Tim> $critters[2][1] = "2";
                        >
                        > my @sorted = sort {
                        > $a->[0] cmp $b->[0]
                        > or $a->[1] <=> $b->[1];
                        > } @critters;
                        >
                        > This is covered in the Alpaca book.
                        >
                        > And now, for the traditional "don't post here" comment:
                        >
                        > **************************************************
                        > *
                        > * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
                        > *
                        > * The official one is at beginners@..., with instructions on how to
                        > * join at http://lists.perl.org/list/beginners.html.
                        > *
                        > * You'll get far better response there, not to say you won't get *any* here.
                        > *
                        > **************************************************
                        >
                        >
                        > --
                        > 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
                      Your message has been successfully submitted and would be delivered to recipients shortly.