Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Matching dot using regexp

by AnomalousMonk (Archbishop)
on Oct 10, 2017 at 08:43 UTC ( [id://1201081]=note: print w/replies, xml ) Need Help??


in reply to Re: Matching dot using regexp
in thread Matching dot using regexp

<pedantic>
The regular expression that follows in the OP is  /./ in the split expression. And FWIW, it could, indeed, be a string literal:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $tim = '01:00:01.004'; ;; $tim =~ s/:/./g; print qq{new time is '$tim'}; my @outputlist = split '\.', $tim; dd \@outputlist; " new time is '01.00.01.004' ["01", "00", "01", "004"]
</pedantic>


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

Replies are listed 'Best First'.
Re^3: Matching dot using regexp
by LanX (Saint) on Oct 10, 2017 at 09:30 UTC
    If it was a string literal why do you need to escape the dot?

    I read thru split couldn't find a a mention of strings as separators.

    From my knowledge using a delimiter in single quotes is still a regex, albeit without variable interpolation like in double quotes.

    UPDATE

    After reading the dialog it seems that what you meant, a literal string without interpolation used as regex.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Somewhere in the middle of that doc it says that PATTERN can be
      a string composed of a single space character (such as ' ' or "\x20" , but not e.g. / / ).
      However, the only PATTERN strings that I find there are whitespace (PATTERN defaults to " " if omitted) and the empty string.

        split is happy with any string (or anything that can be converted to a string) as a /PATTERN/, e.g.,

        c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $tim = '10:00:10.004'; ;; my @outputlist = split '[:.]', $tim; dd \@outputlist; ;; my $p = 10; @outputlist = split $p, $tim; dd \@outputlist; " [10, "00", 10, "004"] ["", ":00:", ".004"]
        However, I would incline to use  // qr// m// for any but the most simple and straightforward patterns; I vaguely recall pitfalls involving backslashes.


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

      Well... I don't quite understand the point you're making, but...

      If it was a string literal why do you need to escape the dot? ... strings as separators.
      In my understanding, a string (or anything that's not a  Regexp object) supplied as a  /PATTERN/ to split will be compiled to a regex, so a single- or double-quoted dot has meta-nature and must be meta-escaped to match only a period.


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

Re^3: Matching dot using regexp
by Anonymous Monk on Oct 10, 2017 at 11:10 UTC
    Heh slow days and i draws the ijits. Regular expressions are not english or chinese they're regex. No matter qr// or qr'' or qr"" whats inside is a different language it aint a plain string

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201081]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found