[23555] in Perl-Users-Digest
Perl-Users Digest, Issue: 5763 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 7 11:05:47 2003
Date: Fri, 7 Nov 2003 08:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 7 Nov 2003 Volume: 10 Number: 5763
Today's topics:
Re: Accessing PHP variables with Perl <nospam@goawayspam.com>
Re: Breaking out of loop if nothing pending <neil.shadrach@corryn.com>
Re: Breaking out of loop if nothing pending (Anno Siegel)
Re: Bug in 5.8.0? . op is very slow <daniel.rawson.take!this!out!@asml.nl>
Re: Code to generate random file names <REMOVEsdnCAPS@comcast.net>
Re: count of 1s in a binary number (Tad McClellan)
Re: how to access a (global) variable across files (Anno Siegel)
Re: how to access a (global) variable across files <tassilo.parseval@rwth-aachen.de>
Re: I think what I need is a backreference but it doesn (Sara)
Re: Intermittent Character Encoding Issues <s0239182@gwendolyn.inf.ed.ac.uk>
Re: math operations <bik.mido@tiscalinet.it>
Re: Perl features (Tad McClellan)
Re: Perl features <twhu@lucent.com>
Re: Perl module for analyzing log files? <massi@NOSPAMmassimilianosini.it>
Question about split (Hugh Kang)
Re: Question about split <ak+usenet@freeshell.org>
Re: Question about split <noreply@gunnar.cc>
Re: Tool to embed images (or other binaries) in your P <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 7 Nov 2003 09:02:34 -0600
From: "Kubaton Lover" <nospam@goawayspam.com>
Subject: Re: Accessing PHP variables with Perl
Message-Id: <vqnd0dobb5bj99@corp.supernews.com>
"James Willmore" <jwillmore@remove.adelphia.net> wrote in message
news:20031107000809.420779f1.jwillmore@remove.adelphia.net...
> On Fri, 07 Nov 2003 03:12:06 GMT
> "Kubaton Lover" <spamsucks@noemail.com> wrote:
>
> > I have a site which is primarily PHP and I'm setting a bunch of PHP
> > environment variables with statements like:
> > $HTTP_SESSION_VARS['valid_user'] = $userid;
> >
> > Is there a way for my Perl scripts to access those session
> > variables? I've never done that before with Perl.
>
>
> Try using the PHP::Session module
> http://search.cpan.org/~miyagawa/PHP-Session-0.22/lib/PHP/Session.pm
>
> HTH
>
> --
> Jim
Thanks, I'll try that.
------------------------------
Date: Fri, 7 Nov 2003 11:24:28 +0000 (UTC)
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Re: Breaking out of loop if nothing pending
Message-Id: <bofvdb$j2$4@visp.bt.co.uk>
Anno Siegel:
> Neil Shadrach <neil.shadrach@corryn.com> wrote in comp.lang.perl.misc:
>
>># perl -we 'die q(KO) unless open(my $h,q(tail -f logfile1.txt|));while
>>(<$h>) { print "L:$_"; }'
>>
>>Can I easily break out of the 'while' loop if nothing is there to be read
>>or do I need to use a lower level read function to be able to do this?
>
>
> I don't know what you mean by "nothing to read". The job of "tail -f"
> is to wait until there *is* something to read, so most of the time there
> will be nothing to read.
Clarification
The 'tail -f' is only in my illustrative example.
The actual application in the 'command|' generates output intermittently - so it might
produce 10 lines in quick succession then nothing for half an hour.
So I'd like to read what is there if there is something there
( maybe not everything if time is scarce ) but not waste time
waiting on it if there is nothing. I've done similar in C with low
level calls but my memory is a poor one and I was optimistically
hoping for ( eg ) a filehandle test that would tell me whether there is
something to be read or not. I'd hate to resort to reading lengths of bytes
and losing the readline behavious if it's not necessary.
------------------------------
Date: 7 Nov 2003 12:44:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Breaking out of loop if nothing pending
Message-Id: <bog433$ku2$1@mamenchi.zrz.TU-Berlin.DE>
Neil Shadrach <neil.shadrach@corryn.com> wrote in comp.lang.perl.misc:
> Anno Siegel:
>
> > Neil Shadrach <neil.shadrach@corryn.com> wrote in comp.lang.perl.misc:
> >
> >># perl -we 'die q(KO) unless open(my $h,q(tail -f logfile1.txt|));while
> >>(<$h>) { print "L:$_"; }'
> >>
> >>Can I easily break out of the 'while' loop if nothing is there to be read
> >>or do I need to use a lower level read function to be able to do this?
> >
> >
> > I don't know what you mean by "nothing to read". The job of "tail -f"
> > is to wait until there *is* something to read, so most of the time there
> > will be nothing to read.
>
> Clarification
> The 'tail -f' is only in my illustrative example.
> The actual application in the 'command|' generates output intermittently
> - so it might
> produce 10 lines in quick succession then nothing for half an hour.
> So I'd like to read what is there if there is something there
> ( maybe not everything if time is scarce ) but not waste time
> waiting on it if there is nothing. I've done similar in C with low
> level calls but my memory is a poor one and I was optimistically
> hoping for ( eg ) a filehandle test that would tell me whether there is
> something to be read or not. I'd hate to resort to reading lengths of bytes
> and losing the readline behavious if it's not necessary.
I'm still not clear what you want, but you may want select (the 4-arg
form, or the module). See "perldoc -f slect".
Anno
------------------------------
Date: Fri, 07 Nov 2003 07:34:09 -0500
From: Dan Rawson <daniel.rawson.take!this!out!@asml.nl>
Subject: Re: Bug in 5.8.0? . op is very slow
Message-Id: <bog3g1$1duits$1@ID-122008.news.uni-berlin.de>
Sisyphus wrote:
> Matthias Weckman wrote:
>
>> Christian Winter wrote:
>>
>>> "Simon Andrews" <simon.andrews@bbsrc.ac.uk> wrote:
>>>
>>>> I can confirm this on my Win32 boxes.
>>>>
>>>> 5.8.0 (AS Build 806) 23 wallclock secs
>>>> 5.6.1 (AS Build 635) 1 wallclock sec
>>>>
>>> I can reproduce this only on our W2K Servers,
>>> ServicePack 3. No Problem on W2K Prof SP4.
>>> So maybe it depends on ServicePack or Prof/Server
>>> versions? Don't have any SP3 Workstations or
>>> SP4 Servers here to test at the moment, so I
>>> can't investigate this any further.
>>
>> Well, I've tried it on some other machines as well, and didn't see the
>> effect on W2K Server SP3 or SP4, nor on W2003 Server.
>>
[Snip]
>
>
As an FYI, I get the same effect on NT SP6a, so it's not limited to Win2k (less than 1 sec with build 629, 19 seconds with build 835)
Dan
------------------------------
Date: Fri, 07 Nov 2003 06:03:13 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Code to generate random file names
Message-Id: <Xns942C47E0614DCsdn.comcast@216.196.97.136>
Matthew Braid <mb@uq.net.au> wrote in
news:bofg9c$5f6$1@bunyip.cc.uq.edu.au:
> my $rnd = int(rand(1e14)); # sprintf can't handle %014d
Could you elaborate on that comment, please?
--
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
------------------------------
Date: Fri, 7 Nov 2003 07:27:50 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: count of 1s in a binary number
Message-Id: <slrnbqn7em.4ko.tadmc@magna.augustmail.com>
Fred <fJogham@yahoo.com> wrote:
> Fred wrote:
>> if there is not a function that takes a scalar or array and count a
>> given charcter.
[ Snip code corrected below.
Please *trim* the unnecessary text in your followups.
Please start doing this very soon.
]
> my $bit1 = "011001010";
> my @bit2 = qw /01 00 11 01 00/;
> print size_of($bit1), "\n";
> print size_of(@bit2), "\n";
>
> sub size_of {
> my $tmp = shift;
That's a pretty useless choice of variable name...
my $bits = join '', @_;
> my $i = 0;
> foreach my $j (split //, $tmp) {
> if ( $j == 1 ) { $i++ };
> }
> return $i;
> }
>
> I am still unble to modify the code to handle the array and scalar and
> give the count of 1s in either.
I'd do it without all of those temporary variables:
sub size_of {
return scalar grep $_ eq '1', split //, join '', @_;
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Nov 2003 11:23:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to access a (global) variable across files
Message-Id: <bofvb6$ids$1@mamenchi.zrz.TU-Berlin.DE>
Newbie <diwaneel@yahoo.com> wrote in comp.lang.perl.misc:
> thanks 4 ur replies... but thats not working... something trivial is
Oh please... use complete English words. This kind of baby talk has
been out since the last 300 Baud modems disappeared from the market.
> going wrong somewhere
>
> i m doing it from scratch. m creating 2 files A.pl:
> #!/user/local/bin/perl
^
You mean "/usr/...".
>
> use strict;
> use B;
Don't call your module "B". More generally, don't call your module
like an existing module. The Perl standard distribution has a module
B.pm, and that is loaded, not yours.
> my $varA = "cfgA";
> $B::varG = "cfgG";
>
> print "Inside PL file....varA = $varA\n";
> print "Inside PL file....varG = $B::varG\n";
>
> &B::test ();
>
> and B.pm:
>
> package B;
>
> local $varG;
> @EXPORT = qw (&test $varG);
If you want to export, you must load the Exporter module. "require Exporter"
is missing. You also need to let your module inherit the import() routine
from Exporter. "BEGIN { our @ISA = qw( Exporter) }" is missing. See
"perldoc Exporter". You should always look at the documentation of things
if something isn't working as you expect.
The failure to use Exporter correctly is irrelevant here, because you
never call the exported version of test(), you are calling it fully
qualified.
> sub test () {
> print "a: $main::varA\n";
> print "varG = $varG\n";
> }
>
> 1;
>
> running A.pl, it gives:
> Undefined subroutine &B::test called at A.pl line 12.
Because the B.pm you actually loaded doesn't define a test() subroutine.
> P.S.: I have set the env var PERL5LIB=mydir
Why would that matter? Is B.pm in mydir?
Anno
------------------------------
Date: 7 Nov 2003 11:50:23 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: how to access a (global) variable across files
Message-Id: <bog0tv$ckp$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Newbie <diwaneel@yahoo.com> wrote in comp.lang.perl.misc:
>> my $varA = "cfgA";
>> $B::varG = "cfgG";
>>
>> print "Inside PL file....varA = $varA\n";
>> print "Inside PL file....varG = $B::varG\n";
>>
>> &B::test ();
>>
>> and B.pm:
>>
>> package B;
>>
>> local $varG;
>> @EXPORT = qw (&test $varG);
>
> If you want to export, you must load the Exporter module. "require Exporter"
> is missing. You also need to let your module inherit the import() routine
> from Exporter. "BEGIN { our @ISA = qw( Exporter) }" is missing. See
> "perldoc Exporter". You should always look at the documentation of things
> if something isn't working as you expect.
Maybe we can come to a conclusion in this group not to use this
cumbersome idiom of subclassing Exporter by manually pushing onto
@ISA. We recently had a thread ("what is @$?") on this where no one
quite could explain why it is exemplified that way throughout the Perl
documentation. So unless someone can point out any potential (or
non-potential) flaws of
use base qw(Exporter);
we should recommend this notion. After all, this is what the base pragma
was initially made for.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 7 Nov 2003 05:18:53 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: I think what I need is a backreference but it doesn't ever match
Message-Id: <776e0325.0311070518.6db25b5d@posting.google.com>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1031106153545.62394B-100000@vcmr-64.server.rpi.edu>...
> [posted & mailed]
>
> On 6 Nov 2003, Sara wrote:
>
> >Hmm curiously I changed
> >
> > s/^(\w+\d)(.+)\n\1 ...
> >
> > to
> >
> > s/^(\w+\d)(?=.+)\n\1 ...
>
> It breaks because the (?=.+) looks ahead to match one or more characters.
> Once that succeeds, the regex goes back to where it was in the string. It
> then looks for a newline, and what was matched into $1. So unless you
> have
>
> FOO1
> FOO1 is BAR
>
> then it won't work.
Wow.. OK I understand this nuance- I'll need to rethink this once again!
Cheers and thanks for the explaination...
G
------------------------------
Date: Fri, 7 Nov 2003 12:26:04 +0000 (UTC)
From: David Murray-Rust <s0239182@gwendolyn.inf.ed.ac.uk>
Subject: Re: Intermittent Character Encoding Issues
Message-Id: <slrnbqn3qs.8u4.s0239182@gwendolyn.inf.ed.ac.uk>
[ this is a repost of a response which I accidentally emailed to Ben.
Sorry Ben! ]
In comp.lang.perl.misc, Ben Morrow wrote:
> How perl stores the data internally should be considered none of your
> business.
Amen to that. I would far rather not need to know ;)
> However, it may be that how it
> is stored in your mysql database is confusing perl, if the code you
> are using to interface to the database doesn't correctly decode the
> data into perl's own encoding. In particular, if you use iso8859-1 you
> may get bitten far more irregularly than if you use other encodings.
I agree with this, except that the data from the database has been
concatenated, regexed etc. with no problem, before a seemingly
innocent line causes problems.
[ snip good advice about dealing with encodings on the way into and
out of the database ]
>> In the second version of the bug, the line:
>>
>> return $return . $parent;
>>
>> resulted in a string being returned where all the pound signs in
>> $return had been altered. If a different string to $parent is
>> appended, there is no problem.
>
> So what does $parent contain, which causes this problem? And what is
> the result of
> use Encode qw/is_utf8/;
> warn is_utf8($parent) ?
> "\$parent is chars internally" :
> "\$parent is bytes internally";
Ah. Here I find that $parent is characters, while $return is bytes.
This sort of explains things, except that it would mean that:
- perl sees a sequence of characters and a sequence of bytes being
concatenated
- it converts the bytes to characters
- it then concatenates two character sequences
- it then forgets that this is now a character sequence, and treats
the result as bytes.
This does not seem like good behaviour - I'd be tempted to suggest
it's a bug.
Further, what would lead perl to treat one set of data as characters
and one set as bytes? both strings are valid XML fragments (built up
using data from CGI). The $parent string which is treated as
characters contains only [A-Za-z0-9<>-='"/? ], so I can't see any
reason for perl to suddenly decide it needs to be character data.
(As a side note, your snippet implies that the is_utf8 flag indicates
whether the data is to be treated as characters or as bytes, rather
than indicating whether or not it is characters in the utf8 character
set - could you clarify? )
>> The current solution is:
>>
>> my $tmpParent = encode( "iso-8859-1", $parent );
>> return $return . $tmpParent;
>
> This is almost certainly Wrong, as $tmpParent will here be considered
> to be a string of octets rather than a sequence of characters. The
> Right Answer is to make sure $return is considered to be a sequence of
> characters as well.
Yes, that makes sense ;)
> Yup. However, if the module you are using to talk to the database
> and/or Apache hasn't been upgraded to 5.8 yet you will have to do
> those conversions 'at the borders' by hand.
I will have a look into the modules we're using
> Another thing to watch out for is that if any of your locale variables
> (LANG, LC_ALL, etc.) match /utf-?8/i then perl will assume all IO will
> be in UTF8 until you disillusion it. This feature has been removed in
> 5.8.1, though, so it shouldn't be affecting your problem.
Yup, that's why I upgraded :)
> An alternative solution, if you can afford to treat all data as
> 'binary' rather than 'textual', is simply to put
>
> use bytes;
>
> at the top of every file :).
Except that as soon as I did that, someone would decide we needed
unicode support ;)
Thanks for your help,
dave
------------------------------
Date: Fri, 07 Nov 2003 17:03:00 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: math operations
Message-Id: <3afnqv041h8hskmr29rvnkguni5vvvrq54@4ax.com>
On Fri, 07 Nov 2003 06:48:59 +1100, Fred <fJogham@yahoo.com> wrote:
>> Do you really expect someone to go through them all and check what Perl
>> supports and what it doesn't?
>>
>no, I just want to know if I can do the following things with perl:
>
>I have many arrays with their elements being bits, e.g. "010000".
>I need to use bitwise operators ( and, or, xor ) to evaluate sections of
>the arrays against each other as well as against other sections in the
>same array.
Please forgive me if this post of mine will seem an ad hominem attack
to you. It is not meant to be...
However, from the series of articles you've been posting lately, it
seems to me that (i) you're asking questions not paying much attention
to the answer you were given, since more than one poster asked you for
more details on some particular issue, (ii) more generally you're not
helping people to help you, (iii) you don't have clear ideas about
both what you want to do and the tool you are thinking of using, i.e.
perl.
For example, in this language, AFAICT, there are no such things as
"arrays with their elements being bits". But it is easy to have an
approximate idea of what you mean, OTOH your first experiment in this
sense used a string like "010000", that is *not* a field of bits
containing the bits (0,1,0,0,0,0).
Hence the code you pasted in you article *did* work, but your
*interpretetion* of how it did(n't!) didn't work! [please forgive me
for this miserable pun!]
So, what I suggest is to be more verbose about the task you actually
need to accomplish.
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Fri, 7 Nov 2003 07:56:24 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl features
Message-Id: <slrnbqn948.4ko.tadmc@magna.augustmail.com>
Matt Oliverius <moliverius@w-link.net> wrote:
> I am a huge Perl fan.
There is a mailing list for people suffering that condition:
http://lists.perl.org/showlist.cgi?name=advocacy
:-)
> However, after spending the last 4 years of my
> career learning and developing Perl skills, my company is trying to ax
> Perl. In a nutshell, the people that are supposed to be our company
> experts, posted a bunch of false crap on a website
^^^^^^^^^^^^
And the URL is...?
> that stated such false
> statements as:
>
> 1) Perl is hard to understand and maintain
That is not necessarily false.
Perl can be hard to understand and maintain.
Perl can be easy to understand and maintain.
The _programmer_ matters a great deal more than the programming language.
> 2) Perl is not object-oriented
Is that the _actual_ statement?
Or is it more like: Perl does not _enforce_ OOP. ??
> I, along with about 100 others, flamed the heck out of this guy (who is a
> supposed Associate Technical Fellow).
I believe that you can greatly increase your chances of getting
what you want if you can suppress the "religious" fervor.
Engineering decisions should be based on facts rather than dogma.
If you should decide to ask for help on the advocacy mailing list
mentioned above, I caution you to take a more open-minded approach
than evidenced in your post here.
> Anyway, he is giving bean-counter managers the impression that Python is
> light years ahead of Perl
What _positive_ points does he make regarding Python?
Maybe Perl has them and he just doesn't know about them...
> and that Python should be used over Perl for any
> new applications.
Even _I_ can envision a situation where that would be the
Right Thing To Do.
If the programmers are not trained as programmers, then I would
give serious consideration to standardizing on Python...
> Does any know of any major shortcomings of Python that
> Perl can handle?
It depends on a great many things and _we_ don't know any of them.
What type of work must typical programs perform?
Are there often-used functions for which Perl has a module and
Python would require new code? (or the other way around?)
What background/experience level do the programmers have?
Are typical program large or small?
Long or short lived?
Developed by one programmer or by a team of programmers or
even by non-programmers?
...
> I really want to beat on this guy a little.
That is a counter-productive attitude.
I really want to show this guy how Perl is better for our situtation.
or
I really want this guy to show me how Python is better for our situtation.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 7 Nov 2003 08:55:01 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Perl features
Message-Id: <bog87v$3hq@netnews.proxy.lucent.com>
> 2) Perl is not object-oriented
This is not true. Perl is object-oriented.
Have you used any cpan modules?
You create an instance of it and use its functions and not to
worry about its implimentation. Is this OO?
I don't know Python and cannot give much comments on it.
However, I like the pattern match feature in Perl.
It is really easy if you know how to use regular expression.
Lots of good modules on cpan. Perl can be used on web
or standalone modules. The Perl/Tk is a good GUI package
that my customers like it. The Encoding feature that let me
guess the language a user enters. It parses xml file well.
------------------------------
Date: Fri, 07 Nov 2003 12:14:44 GMT
From: Massi <massi@NOSPAMmassimilianosini.it>
Subject: Re: Perl module for analyzing log files?
Message-Id: <Xns942C86A868661massi70Massi@195.31.190.132>
Kenneth Porter <ken.blacklist@sewingwitch.com> wrote in
news:Xns942BAE96E3B2Eshivawellcom@64.164.98.49:
>
> More specifically, what would be the right module to generically parse
> timestamps in any of these log files and do date arithmetic (ie. find
> all lines from a specified time period)?
>
> I'd like to put proper date parsing in the logwatch package
> (http://www.logwatch.org/) and I'd like to use a date parser that's
> generally available on most OS's that run syslog/Apache/BIND.
>
Try using Date::Parse
I used in the past to generate a filtered "messages".
For example: I told the script to output me the messages generated in the
last xxx hours.
Here is a snippet of code:
#!/bin/perl -w
use Date::Parse;
my $HoursBefore=24;
$HoursBefore=time()-($HoursBefore*3600); # transform in second
open(MESSFILE, "</var/log/syslog");
while (<MESSFILE>) {
my $date = /^(.+?\s.+?\s.+?\s)/
# transform in second ???? maybe. But I'm sure there is a way to do it.
# See POD file of the module.
my $dateNum = str2time($date);
if ($dateNum > $HoursBefore) {
.... positive command
} else {
.... negative commands
}
}
close MESSFILE;
This is something I resume from an old (and maybe not functioning)
script.
I never used to parse Apache/BIND logs ... but I think you can with some
trials.
Massi
------------------------------
Date: 7 Nov 2003 06:25:07 -0800
From: skang@leaguedata.com (Hugh Kang)
Subject: Question about split
Message-Id: <257137ea.0311070625.6552af43@posting.google.com>
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
------------------------------
Date: Fri, 7 Nov 2003 14:33:54 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Question about split
Message-Id: <slrnbqnbah.aj8.ak+usenet@vinland.freeshell.org>
In article <257137ea.0311070625.6552af43@posting.google.com>, 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
------------------------------
Date: Fri, 07 Nov 2003 16:14:01 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Question about split
Message-Id: <bogde0$1e1gs8$1@ID-184292.news.uni-berlin.de>
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
------------------------------
Date: Fri, 07 Nov 2003 17:02:59 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Tool to embed images (or other binaries) in your Perl source.
Message-Id: <nsdnqvogfpv9bn30okj51mk58jefpi39rd@4ax.com>
On Wed, 5 Nov 2003 17:06:20 -0700, "Michael Carey"
<usenet@giantsquidmarks.com> wrote:
>Although I cannot say exactly why, I performed a search-replace to satisfy
>your objection.
Well, you can't say *exactly* why. But after all *somehow* you can say
why: otherwise you wouldn't have done it, would you? :-)
However, I gave you a good reason IMHO, by pointing you to the
appropriate faq entry!
Seriously, and indeed OT wrt the subject of this thread, I find
astonishing the difference that there's between the (sub-)cultures of
comp.lang.perl.misc and comp.lang.perl.tk respectively.
Unfortunately I'm not able to report a proper review of this issue,
but only cite a few examples: non-strict and/or non-warnings enabled
scripts are much more tolerated, awkward ways to "do things" also, and
so on.
Please, note that I'm *not* saying that "pTk programmers write crappy
code", only that in CLPT while the attention is focused on GUI's logic
and features much less care *seems* to be dedicated to the
("remaining") perl code itself.
But this involves also posting policies: a post like this one (the one
I'm following-up to) containing no proper quotations and/or references
usually generates a chorus of complaints in CLPM.
Just an observation,
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5763
***************************************