Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: RFC: A Primer on Writing Portable Perl Programs

by mirod (Canon)
on Nov 01, 2006 at 11:37 UTC ( #581655=note: print w/ replies, xml ) Need Help??


in reply to RFC: A Primer on Writing Portable Perl Programs

Just one comment: I found that using the alternate quote syntax makes it much easier to write one-liners, portable or not:

perl -wl -e 'print qq{The arguments are: @ARGV};'

Then if you want to use this on Windows, change the outer ' to ", et voilà! No extra-escaping, no having to figure out whether there are interpolated variables in the string or not... It Just Works (tm)


Comment on Re: RFC: A Primer on Writing Portable Perl Programs
Download Code
Re^2: RFC: A Primer on Writing Portable Perl Programs
by yumpy (Sexton) on Nov 01, 2006 at 18:00 UTC
    That's a good point, but at the expense of doubling the number of 'quoting' characters that needs to be typed ("x" vs. qq{x}), I don't think it would catch on as a routine practice. However, as a "best practice" for depicting one-liners meant for portability, I like it!
    *=========================================================================* | Dr. Tim Maher, CEO, Consultix | Email: tim@consultix-inc.com *=========================================================================*
      doubling the number of 'quoting' characters…("x" vs. qq{x})

      In the realm of your discussion it's (\"x\" vs. qq{x}) which makes the score even.

      I don't think it would catch on as a routine practice.

      It is routine practise, but that may be only me. For one I don't like "external" characters inside my perl code (the backslash belonging to the cmd.exe, and is not seen by perl), and secondly it's actually easier to parse when read (for my brain at least).

      Update: The original proposition from mirod came from the -ix side. My remarks are coming from the Win command line ;-)

        pKai wrote on 1 Nov 2006:
           (yumpy wrote on 1 Nov 2006:)
        doubling the number of 'quoting' characters…("x" vs. qq{x})

        · In the realm of your discussion it's (\"x\" vs. qq{x}) which makes the score even.

        I don't think it would catch on as a routine practice.

        · It is routine practise, but that may be only me. For one I don't like "external" characters inside my perl code (the backslash belonging to the cmd.exe, and is not seen by perl), and secondly it's actually easier to parse when read (for my brain at least).

        It is not only you, pKai. I also routinely make a practice of using some alternate Perl quoting delimiters, when writing a one-liner for Windows/CMD or one that I think might ever run on Windows/CMD.

        In my experience it only takes a little practice to "see" the quoted string standing out clearly when using a q<some-char> construct, just as or nearly as easily as one without practice does with ordinary "s. But then I write a lot of Perl.

        Since it is tangential to this reply I won't go deeply into it, but one pet peeve of mine concerns assumptions about what shell a Win32 Perler is using. There are UNIX sh -like shells being used on MS Windows. There's a special environmental variable, PERL5SHELL, addressing that. Yet most all of the core Perl utility code (i.e. for things like ExtUtils) assumes that a command interpreter on Windows has to be the CMD.exe or command.com type. I feel a bit mistreated ;-). The 3 people still using MINT systems get support, but I as part of who knows how many hundreds or thousands using a 3rd-party UNIX-like shell on MS Windows cannot? By what logic exactly? Because there's so few of us? Only in relation to the total user base for MS Windows. So 3 MINT users or 48 FooIX-1.0 users get support, but trying to use MS Windows better gets us punishment? ;-)

        You'll find some more MS Windows / Perl portability notes (especially relating to the creation of DOSKEY macros to fill the role that BASH functions do, in the CMD shell), on my home node, yumpy. Down past the "meta" stuff relating to my experience in 6 years here at Perlmonks. Ignore the growling and squeals of moral distress if that's not what you're into. ;-)

            Soren A / somian / perlspinr / Intrepid

        -- 
        Words can be slippery, so consider who speaks as well as what is said; know as much as you can about the total context of the speaker's participation in a forum over time, before deciding that you fully comprehend the intention behind those words. If in doubt, ask for clarification before you 'flame'.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-10-30 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls