Hello White Raven and welcome to the monastery and to the wonderful world of perl!

You already got a good clue: $^O is the perl special variable containing the OS, from the perl point of view. But with perl you have many many options to finely leverage the platform/architecture checking.

1) $^O being your first option: you can use it in if construct: if ($^O eq 'MSWin32 ) { ...' or in a dispatch thable:

my %clear_command = ( MSWin32 => 'cls', Linux => 'clear' ... ); system (1, $clear_command{ $^O } );

As said in perlvar concerning $^O on windows it always returns MSWin32 but using Win32 module you have something better:

print Win32::GetOSName(),Win32::GetOSVersion(); # output: Win10Business (64-bit)100179362002561

2) Config is a core module that holds ~900 values concerning the current perl installation: for example the architecture:

print $Config{archname}; # MSWin32-x64-multi-thread or if current perl is configured to use threads: $Config{usethreads} The module populates for you a readonly hash named %Config

3) the if module (not the normal if ) is useful to import the rigth module depending on situation: if you need to work with the OS name (given the above) you may need Win32 module to get the right name:  use if $^O eq 'MSWin32', 'MSWin32'; # note that it wants module in a string!

4) in perlvar look also at $] and $^V useful to inspect the current perl version (versions are a bit.. confusing in perl: recent history shows.. ;)

5) last but not least consider that many modules do their best in being agnostinc in respect of the operating system: come to mind Term::ReadLine that works fine on different platforms. Under the hood the module will load the appropriate module dependin on platforms: Term::ReadLine::Linux for example if run on Linux.

The very same does the best module for portable program: the core module File::Spec that abstracts many important file and path related operations being very OS agnostic

6) a look at perlport is recomended

good luck!

L*

PS (the title was: Perl Newbie question) next times try to choose more meaning titles for your questions: it wil be useful for future searcher!

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Easing cross-platform scripting -- portable scripts - OS agnostic tools by Discipulus
in thread Easing cross-platform scripting by White Raven

Title:
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, details, 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, summary, 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.