Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Regexp for oneliner conversion

by cztmonk (Monk)
on Aug 05, 2012 at 12:26 UTC ( #985519=perlquestion: print w/ replies, xml ) Need Help??
cztmonk has asked for the wisdom of the Perl Monks concerning the following question:

How do I convert a Unix oneliner like this :

perl -wl -e 'print "This is text";'

to a Windows oneliner like this :

perl -wl -e "print 'This is text';"

I am looking for a regexp solution...

Comment on Regexp for oneliner conversion
Select or Download Code
Re: Regexp for oneliner conversion
by BrowserUk (Pope) on Aug 05, 2012 at 12:34 UTC
    How do I convert a Unix oneliner like this

    Depends how "like" that it is:

    $o = q[perl -wl -e 'print "This is text";'];; $o =~ tr['"]["'];; print $o;; perl -wl -e "print 'This is text';"

    I can see many ways to make that fail, but it might be good enough.

    Otherwise, you soon move into the realms of Only perl can parse Perl.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Perfect! One question about the code.Why did you use

      ;;

      Typo?

        One question about the code.Why did you use ;; Typo?

        No. See Re^6: RFC: IPerl - Interactive Perl ( read-eval-print loop ) (x) and the full thread it is a part of if you really need to know; otherwise, just ignore it.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re: Regexp for oneliner conversion
by johngg (Abbot) on Aug 05, 2012 at 18:46 UTC

    You might also be interested in Quote and Quote like Operators. Using those would allow you to have the same quoting constructs inside the code both on Unix and Windows, only the quotes around the code changing depending on o/s. I have got into the habit of using these instead of normal quotes, my answer to chromatic's query gives the background.

    Cheers,

    JohnGG

Re: Regexp for oneliner conversion
by ww (Bishop) on Aug 05, 2012 at 19:05 UTC
    Illustrating BrowserUK's warning that your success will depend on just how just "how like" the next code to be converted is to the example your open-ended question:

    A regex simply can't translate a *nix-ish perl -E '`stat \usr\bin\foo;`' to something a stock M$ Windows system will understand and act on properly unless it's custom-built to deal with that particular approach... and the custom regex will fail on many (most) variants.

Re: Regexp for oneliner conversion
by Marshall (Prior) on Aug 05, 2012 at 19:05 UTC
    Why do you even care about "one liner'ers?"

    Why not write a short program that will work on both OS'es?

    Why not?

    Once you invoke Perl, I don't that it makes a difference if you have 1 line or 5 lines.

Reaped: Re: Regexp for oneliner conversion
by NodeReaper (Curate) on Aug 05, 2012 at 19:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985519]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-09-18 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (121 votes), past polls