Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Question about split

Reply
Thread Tools

Question about split

 
 
Hugh Kang
Guest
Posts: n/a
 
      11-07-2003
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
 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      11-07-2003
In article <(E-Mail Removed) >, Hugh Kang wrote:
[cut]
> 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.

--
Andreas Kähäri
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-07-2003
Hugh Kang wrote:
>
> ($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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-10-2003
Gunnar Hjalmarsson <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Hugh Kang wrote:
> >
> > ($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.


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a split is not a split Dumbell Computer Support 3 03-09-2009 10:45 PM
String#split(/\s+/) vs. String#split(/(\s+)/) Sam Kong Ruby 5 08-12-2006 07:59 PM
How can I split database results with ExecuteReader and Split? needin4mation@gmail.com ASP .Net 2 05-05-2006 10:36 PM
split on '' (and another for split -1) trans. (T. Onoma) Ruby 10 12-28-2004 06:36 AM
Small inconsistency between string.split and "".split Carlos Ribeiro Python 11 09-17-2004 05:57 PM



Advertisments