how to substiture a letter in a string using perl?

Discussion in 'Perl Misc' started by Paul, Feb 1, 2006.

  1. Paul

    Paul Guest

    hi, there,

    I have a date format string, like $mydate='Wed Feb 1 17:33:20 2006';

    I dont want to have the space and : in my string, so I use

    $mydate =~ tr/[ ,:]/a/; to get a new string as
    $mydate='WedaFebaa1a17a33a28a2006';

    The question is how can I get rid all the "a" in this string? or how to
    get $mydate='WedFeb11733202006' from $mydate='Wed Feb 1 17:33:20
    2006'?


    thanks.
    Paul, Feb 1, 2006
    #1
    1. Advertising

  2. Paul

    Xicheng Guest

    Paul wrote:
    > hi, there,
    >
    > I have a date format string, like $mydate='Wed Feb 1 17:33:20 2006';
    >
    > I dont want to have the space and : in my string, so I use
    >
    > $mydate =~ tr/[ ,:]/a/; to get a new string as


    > $mydate='WedaFebaa1a17a33a28a2006';
    >
    > The question is how can I get rid all the "a" in this string? or how to
    > get $mydate='WedFeb11733202006' from $mydate='Wed Feb 1 17:33:20
    > 2006'?


    $mydate =~ tr/ ://d;

    >
    >
    > thanks.
    Xicheng, Feb 1, 2006
    #2
    1. Advertising

  3. "Paul" <> wrote in
    news::

    > I have a date format string, like $mydate='Wed Feb 1 17:33:20 2006';
    >
    > I dont want to have the space and : in my string, so I use
    >
    > $mydate =~ tr/[ ,:]/a/; to get a new string as
    > $mydate='WedaFebaa1a17a33a28a2006';
    >
    > The question is how can I get rid all the "a" in this string? or how
    > to get $mydate='WedFeb11733202006' from $mydate='Wed Feb 1 17:33:20
    > 2006'?


    Please feel free to read the documentation.

    D:\Home\asu1\UseNet\clpmisc> perldoc -f tr
    tr/// The transliteration operator. Same as "y///". See perlop.

    Then find tr in perldoc perlop:

    #!/usr/bin/perl

    use strict;
    use warnings;

    my $mydate = 'Wed Feb 1 17:33:20 2006';

    $mydate =~ tr/ ://d;

    print "$mydate\n";

    __END__
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 1, 2006
    #3
  4. Paul

    DJ Stunks Guest

    Paul wrote:
    > hi, there,
    >
    > I have a date format string, like $mydate='Wed Feb 1 17:33:20 2006';
    >
    > I dont want to have the space and : in my string, so I use
    >
    > $mydate =~ tr/[ ,:]/a/; to get a new string as
    > $mydate='WedaFebaa1a17a33a28a2006';
    >
    > The question is how can I get rid all the "a" in this string? or how to
    > get $mydate='WedFeb11733202006' from $mydate='Wed Feb 1 17:33:20
    > 2006'?
    >
    >
    > thanks.


    oh, that's easy:

    $mydate='Wed Feb 1 17:33:20 2006';
    $mydate =~ tr/[ ,:]/a/;
    $mydate =~ tr/a/b/; # no more a's

    no charge, glad to help :)

    -jp
    DJ Stunks, Feb 1, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jay
    Replies:
    1
    Views:
    19,039
    Marc Dzaebel
    Feb 25, 2004
  2. vertigo

    big letter -> small letter

    vertigo, Jul 6, 2004, in forum: Python
    Replies:
    4
    Views:
    753
    Reinhold Birkenfeld
    Jul 6, 2004
  3. Tony Meyer

    RE: big letter -> small letter

    Tony Meyer, Jul 6, 2004, in forum: Python
    Replies:
    0
    Views:
    504
    Tony Meyer
    Jul 6, 2004
  4. Andrew McNamara

    Re: big letter -> small letter

    Andrew McNamara, Jul 6, 2004, in forum: Python
    Replies:
    2
    Views:
    749
    Scott David Daniels
    Jul 6, 2004
  5. Daneel Yaitskov
    Replies:
    1
    Views:
    2,644
    J├╝rgen Exner
    Dec 7, 2008
Loading...

Share This Page