Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

NB: The  \1 \2 \3 notation is for regex back-references and is not kosher in a  s/// replacement string. warnings would have told you this had you enabled them. This (ab)use of back-references is a special dispensation of Perl, but should be avoided in favor of capture variables; see Variables related to regular expressions in perlvar.

c:\@Work\Perl\monks>perl -wMstrict -le "use strict; use warnings; ;; my $line = 'OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/ +30/2019,2015-06-20 00:00:00'; ;; $line =~ s/(\d{4})-(\d{2})-(\d{2})\s\d{2}:\d{2}:\d{2}/\2\/\3\/\1/g; print qq{>$line<}; " \2 better written as $2 at -e line 1. \3 better written as $3 at -e line 1. \1 better written as $1 at -e line 1. >OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,06/2 +0/2015<
Also note that you can avoid inflicting LTS upon yourself (and your eyes) by choosing a better regex delimiter:
c:\@Work\Perl\monks>perl -wMstrict -le "use strict; use warnings; ;; my $line = 'OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/ +30/2019,2015-06-20 00:00:00'; ;; $line =~ s{(\d{4})-(\d{2})-(\d{2})\s\d{2}:\d{2}:\d{2}}{$2/$3/$1}g; print qq{>$line<}; " >OD44202,07/01/2015,08/19/2019,08/27/2019,1,07/01/2015,06/30/2019,06/2 +0/2015<
Please see perlre, perlretut and perlrequick.

Update: Your eyes will also thank you for some whitespace courtesy of the  /x modifier:
    $line =~ s{ (\d{4}) - (\d{2}) - (\d{2}) \s \d{2} : \d{2} : \d{2} }{$2/$3/$1}xg;
And is the  /g modifier really necessary?


Give a man a fish:  <%-{-{-{-<


In reply to Re: New File Not Working by AnomalousMonk
in thread New File Not Working by jalopez453

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2022-01-22 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?