Ok, first off, I warned him not to use this code, but he's just learned how, erm, "terse" Perl can be, and can't resist the pull to the Dark Side...

Secondly, though this isn't super-obfu, it has a rather dense, inscrutable line in it that we're actually using, soooo without further ado, here you go.

Update: I commented the inscrutable line, just in case anyone cares.
my $test = '`dir $path /-c`'; my $free = &bleah( 'u:' ); print $free, "\n"; my $free = &bleah( 'c:' ); print $free, "\n"; sub bleah { my $path = shift; # # 1. evaluate the perl code in $test # when eval'ed, $path gets set internally # 2. get the last line of the result list # 3. match it against the given pattern # 4. the captured item gets returned in its own list # 5. return the captured item only (a scalar) # 6. voila - bytes free from DOS. # return ((eval $test)[-1] =~ m/(\d+) bytes free/)[0]; # yow! }

Replies are listed 'Best First'.
Re: Real live code
by cored (Scribe) on Jul 14, 2003 at 14:11 UTC
    I think you can figure out how to make the script portable into unix/win32 with the $^O var.
Re: Real live code
by Anonymous Monk on Jul 11, 2003 at 19:59 UTC
    What happens if the eval fails?
Re: Real live code
by runrig (Abbot) on Jun 14, 2006 at 21:39 UTC
    There's nothing wrong with non-portable code, if you have no intention of ever porting it. But Win32::AdminMisc::GetDriveSpace() would be a better choice here. (Note: this is a reply to an old node, and is just for the benefit of anyone who runs across this thread and needs to do a similar thing).
Re: Real live code
by Anonymous Monk on Jul 12, 2003 at 14:36 UTC

    Ever heard of people using different operating systems than Windows?

      Yes, it is true. We at Microsoft have labored long and hard to de-educate people, and these rogue OS's are not helping our cause at all. People need Windows ... they are just simply too stupid and desperately need our guidance and knowledge. Just imagine if these OS users actually thought for themselves ... where would the world be now?

      "Friends don't let friends use anything but Windows" is our new campaign slogan. We have invested close to a billion dollars into this campaign, so look out Linux! Imagine being reported by your neighbor or even your children for using anything but Windows. So give up your silly little antiquated command line interface ... join the mouse!

      Of course, some would accuse Microsoft of dealing in less than ethical business practices, such as using vapor-ware to elimate possible competition. Let us remind you about our Butterfly. Would a butterfly do something mean like that? Of course not! It's a pretty butterfly. Fly pretty butterfly! Fly! Microsoft is your butterfly. You like Microsoft. Buy our products. Don't question authority. Don't look into source code to see what evil pipeline we have created. Did I say 'evil'? I meant Butterfly! Look at the butterfly!
      This is the Windows-specific code. Are you worried that the Unix-side code isn't as terse looking?