A
Andreas Pürzer
Greetings!
Recently I've stumbled over code where someone assigned to $^0. This
seemed rather nonsensical to me, so I tried:
D:\Temp>perl -MData:umper -we "use File::Spec; print Dumper(\%INC);"
$VAR1 = {
'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
'bytes.pm' => 'C:/Perl/lib/bytes.pm',
'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
'Carp.pm' => 'C:/Perl/lib/Carp.pm',
'C:/Perl/site/lib/sitecustomize.pl' =>
'C:/Perl/site/lib/sitecustomize.pl',
'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
'vars.pm' => 'C:/Perl/lib/vars.pm',
'strict.pm' => 'C:/Perl/lib/strict.pm',
'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
'warnings.pm' => 'C:/Perl/lib/warnings.pm',
'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
'overload.pm' => 'C:/Perl/lib/overload.pm',
'File/Spec/Win32.pm' => 'C:/Perl/lib/File/Spec/Win32.pm',
'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
};
So far, so good, everything as expected. File::Spec::Win32 shows up
because, as you may have guessed from my use of Doublequotes, I'm on
MSWin32.
But then I tried:
D:\Temp>perl -MData:umper -we "BEGIN { $^O = 'epoc'}; use File::Spec;
print Dumper(\%INC)"
$VAR1 = {
'File/Spec/Epoc.pm' => 'C:/Perl/lib/File/Spec/Epoc.pm',
'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
'bytes.pm' => 'C:/Perl/lib/bytes.pm',
'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
'Carp.pm' => 'C:/Perl/lib/Carp.pm',
'C:/Perl/site/lib/sitecustomize.pl' =>
'C:/Perl/site/lib/sitecustomize.pl',
'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
'vars.pm' => 'C:/Perl/lib/vars.pm',
'strict.pm' => 'C:/Perl/lib/strict.pm',
'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
'warnings.pm' => 'C:/Perl/lib/warnings.pm',
'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
'overload.pm' => 'C:/Perl/lib/overload.pm',
'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
};
No more File::Spec::Win32, but File::Spec::Epoc!
According to `perldoc perlvar`:
$OSNAME
$^O The name of the operating system under which this copy of Perl
was built, as determined during the configuration process.
So, I'm a little lost why it's even possible to (ab-)use $^O this way,
and I fail to see the possible benefits of doing so. OTOH, I'd have
expected to see something along the lines of:
Modification of a read-only value attempted
So, is this a bug or a feature? ;->
Could someone please shed some light on this?
Thank you,
Andreas Puerzer
Recently I've stumbled over code where someone assigned to $^0. This
seemed rather nonsensical to me, so I tried:
D:\Temp>perl -MData:umper -we "use File::Spec; print Dumper(\%INC);"
$VAR1 = {
'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
'bytes.pm' => 'C:/Perl/lib/bytes.pm',
'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
'Carp.pm' => 'C:/Perl/lib/Carp.pm',
'C:/Perl/site/lib/sitecustomize.pl' =>
'C:/Perl/site/lib/sitecustomize.pl',
'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
'vars.pm' => 'C:/Perl/lib/vars.pm',
'strict.pm' => 'C:/Perl/lib/strict.pm',
'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
'warnings.pm' => 'C:/Perl/lib/warnings.pm',
'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
'overload.pm' => 'C:/Perl/lib/overload.pm',
'File/Spec/Win32.pm' => 'C:/Perl/lib/File/Spec/Win32.pm',
'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
};
So far, so good, everything as expected. File::Spec::Win32 shows up
because, as you may have guessed from my use of Doublequotes, I'm on
MSWin32.
But then I tried:
D:\Temp>perl -MData:umper -we "BEGIN { $^O = 'epoc'}; use File::Spec;
print Dumper(\%INC)"
$VAR1 = {
'File/Spec/Epoc.pm' => 'C:/Perl/lib/File/Spec/Epoc.pm',
'warnings/register.pm' => 'C:/Perl/lib/warnings/register.pm',
'bytes.pm' => 'C:/Perl/lib/bytes.pm',
'XSLoader.pm' => 'C:/Perl/lib/XSLoader.pm',
'Carp.pm' => 'C:/Perl/lib/Carp.pm',
'C:/Perl/site/lib/sitecustomize.pl' =>
'C:/Perl/site/lib/sitecustomize.pl',
'File/Spec/Unix.pm' => 'C:/Perl/lib/File/Spec/Unix.pm',
'vars.pm' => 'C:/Perl/lib/vars.pm',
'strict.pm' => 'C:/Perl/lib/strict.pm',
'Exporter.pm' => 'C:/Perl/lib/Exporter.pm',
'warnings.pm' => 'C:/Perl/lib/warnings.pm',
'File/Spec.pm' => 'C:/Perl/lib/File/Spec.pm',
'overload.pm' => 'C:/Perl/lib/overload.pm',
'Data/Dumper.pm' => 'C:/Perl/lib/Data/Dumper.pm'
};
No more File::Spec::Win32, but File::Spec::Epoc!
According to `perldoc perlvar`:
$OSNAME
$^O The name of the operating system under which this copy of Perl
was built, as determined during the configuration process.
So, I'm a little lost why it's even possible to (ab-)use $^O this way,
and I fail to see the possible benefits of doing so. OTOH, I'd have
expected to see something along the lines of:
Modification of a read-only value attempted
So, is this a bug or a feature? ;->
Could someone please shed some light on this?
Thank you,
Andreas Puerzer