note
Discipulus
Hello [White Raven] and welcome to the monastery and to the wonderful world of perl!<P>
You already got a good clue: <C>$^O</C> 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.<P>
<b>1)</b> <C>$^O</C> being your first option: you can use it in if construct: <C>if ($^O eq 'MSWin32</C> ) { ...' or in a dispatch thable:
<c>
my %clear_command = ( MSWin32 => 'cls', Linux => 'clear' ... );
system (1, $clear_command{ $^O } );
</c><P>
As said in [DOC://perlvar|<tt>perlvar</tt>] concerning <C>$^O</C> on windows it always returns <C>MSWin32</C> but using [metamod://Win32] module you have something better:<P>
<c>
print Win32::GetOSName(),Win32::GetOSVersion();
# output:
Win10Business (64-bit)100179362002561
</c><P>
<b>2)</b> [metamod://Config] is a core module that holds ~900 values concerning the current perl installation: for example the architecture:<P>
<C>print $Config{archname}; # MSWin32-x64-multi-thread</C> or if current perl is configured to use threads: <C>$Config{usethreads}</C> The module populates for you a readonly hash named <C>%Config</C><P>
<b>3)</b> the [metamod://if] module (not the normal [DOC://if|<tt>if</tt>] ) 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 <C>Win32</C> module to get the right name:
<c> use if $^O eq 'MSWin32', 'MSWin32'; # note that it wants module in a string!</c><P>
<b>4)</b> in [DOC://perlvar|<tt>perlvar</tt>] look also at <C>$]</C> and <C>$^V</C> useful to inspect the current perl version (versions are a bit.. <i>confusing</i> in perl: recent history shows.. ;)<P>
<b>5)</b> last but not least consider that many modules do their best in being agnostinc in respect of the operating system: come to mind [metamod://Term::ReadLine] that works fine on different platforms. Under the hood the module will load the appropriate module dependin on platforms: <C>Term::ReadLine::Linux</C> for example if run on Linux. <P>
The very same does the best module for portable program: the core module [metamod://File::Spec] that abstracts many important file and path related operations being very OS agnostic<P>
<b>6)</b> a look at [DOC://perlport|<tt>perlport</tt>] is recomended<P>
good luck!<P>
L*<P>
<B>PS</B> (the title was: <i>Perl Newbie question</i>) next times try to choose more meaning titles for your questions: it wil be useful for future searcher!<P>
<div class="pmsig"><div class="pmsig-174111">
There are no rules, there are no thumbs..<BR>
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
</div></div><!-- Wiki2Monks {"version":1.142} -->
1226402
1226402