in reply to Pattern Match/Trim Variables.

I'm not sure what those first three substitutions are. You appear to be replacing characters with themselves, specifying the match as a meta-character and the replacement as a hex value.

The s command you want to get rid of the trailing piece in the date is:

my $date = '02/17/2003 14:09:34.087'; $date =~ s#^(\d\d/\d\d/\d\d\d\d \d\d:\d\d:\d\d)\.\d\d\d$#$1#;

Replies are listed 'Best First'.
Re: Re: Pattern Match/Trim Variables.
by LostS (Friar) on Feb 17, 2003 at 19:21 UTC
    Don't worry about those other replace strings. I am creating a CSV and need those for formating... But how do I do an:
    if ($line =~ /\d\d\/\d\d\/\d\d\d\d \d\d:\d\d:\d\d.\d\d\d/) { $line =~ s#^(\d\d/\d\d/\d\d\d\d \d\d:\d\d:\d\d\.\d\d\d$#$1#; }
    Is that correct??

    -----------------------
    Billy S.
    Slinar Hardtail - Hand of Dane
    Datal Ephialtes - Guildless
    RallosZek.Net Admin/WebMaster

    perl -le '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat +!\n"; } else { print "Thats a dog\n"; }'

      You *could* do that, but the if() statement is completely unnecessary. If the match is not found in the string, then it won't do anything, thus the if() is redundant. As for that regex, I'd recommend you look further into the discussion and pick out one of the other (shorter!) ones.


      If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.

      Those first three substitutions are doing nothing unless there's some magic I'm missing. A tab has hex value 09, a newline hex value 0a, and a carriage return hex value 0d. The metacharacter representation and the hex representation in your substitutions evaluate to the same thing. So you're replacing each one with itself.