Question about split

H

Hugh Kang

I am trying to get the memory size of the system using prtconf (UnixWare 7)
The output of prtconf is:

SYSTEM CONFIGURATION:

Memory Size: 2048 Megabytes
System Peripherals:

Floppy Drive 1 - 1.44 MB 3.5
SCSI CD-Rom Drive 1 - TOSHIBA - DVD-ROM SD-M1502
Tape Drive 1 - QUANTUM - DLT8000
Disk Drive 1 - MYLEX - eXtremeRAID 2000 - 17406 MB
Disk Drive 2 - MYLEX - eXtremeRAID 2000 - 52234 MB
80387 Math Processor

In the perl script, I am doing the followings:

open(MEMSIZE,"/usr/sbin/prtconf") || die "Cannot run prtconf";
while (<MEMSIZE>) {
($dummy, $word1, $word2, $memsize, $rest) = split;
if ( $word1 eq "Memory" ) {
print "dummy = $dummy \n";
print "word1 = $word1 \n";
print "word2 = $word2 \n";
print "memsize = $memsize \n";
print "rest = $rest \n";

$memory = $memsize;
print "memeory size = $memory \n";
}
}

I am expecting '2048' for the memory size but I've got "%d" for $memsize.
dummy =
word1 = Memory
word2 = Size:
memsize = %d
rest = Megabytes
memeory size = %d

Can anyone help me out with this? Any other good way to get the size?

Regards
Hugh
 
A

Andreas Kahari

Hugh Kang wrote: said:
open(MEMSIZE,"/usr/sbin/prtconf") || die "Cannot run prtconf";

You're opening the executable file, you're not running it. Add
a pipe ('|') after the file name.

[cut]
I am expecting '2048' for the memory size but I've got "%d" for $memsize.

Yes, you stumbled over the C format string in the compiled
program. The '%d' is a placeholder for an integer value, just
like in Perl's own printf function.
 
G

Gunnar Hjalmarsson

Hugh said:
($dummy, $word1, $word2, $memsize, $rest) = split;
if ( $word1 eq "Memory" ) {

Since you are splitting without a pattern, it surprises me that
$word1, and not $dummy, is assigned the first word on respective line.
 
A

Anno Siegel

Gunnar Hjalmarsson said:
Since you are splitting without a pattern, it surprises me that
$word1, and not $dummy, is assigned the first word on respective line.

Well, he's reading the binary executablei. :) From the original code:

open(MEMSIZE,"/usr/sbin/prtconf")

By some coincidence, this puts "Memory" from the sprintf format into
$word1.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top