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

comment on

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

Which programming style do you like? Which one should I use?
Athanasius has already provided a much nicer alternative.

I'll briefly nitpick your style of using the || operator (as in index($Y,'WIN')<0||return'\\';). For flow of control, prefer the low precedence or operator. A common example of preferring or to || is:

open(my $fh, '<', $file) or die "error opening '$file': $!";
That is probably the principal use case as to why the low precedence operators were added to the language in the first place. Reserve && and || for logical expressions, not flow of control, for example:
if ($x > 5 && $y < 10) ...

This is discussed in detail in Perl Best Practices, Chapter 4, "Values and Expressions" in the "Don't mix high- and low-precedence booleans" item.

Re OS path portability, the core Perl module that deals with this is File::Spec and that is perhaps what you should be using (hard to know without understanding your bigger picture). Note that if you only need to target *nix and Windows (update: and modern Macs running BSD-derived MacOS), you can avoid File::Spec simply by using / as the path separator; this works because the Windows API treats forward slashes and back slashes equivalently in file path arguments to all Windows API functions. A minor annoyance is that Windows commands typically use forward slash for command line argument options. So, while using forward slashes in file paths is fine when calling all Perl internal functions on Windows, using them in command line arguments when running Windows commands is problematic - in the rare cases where you need to pass a file path to an external Windows command, you can translate it like so: $filepath =~ tr{/}{\\}

More useful than nitpicking low level details of programming style is to look at the bigger picture; some references on that follow:

In reply to Re: What's your programming style? by eyepopslikeamosquito
in thread What's your programming style? by harangzsolt33

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2020-07-11 14:36 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found