[30695] in Perl-Users-Digest
Perl-Users Digest, Issue: 1940 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 23 00:09:47 2008
Date: Wed, 22 Oct 2008 21:09:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 22 Oct 2008 Volume: 11 Number: 1940
Today's topics:
Re: crisis Perl <jl_post@hotmail.com>
Re: crisis Perl <cartercc@gmail.com>
Re: greping a value from a file <xemoth@gmail.com>
Re: IDE with Class Browser for Perl <saragwyn@yahoo.com>
Need help with a REGEX <mike.pierotti@docomopacific.net>
Re: Need help with a REGEX <tim@burlyhost.com>
Re: Need help with a REGEX <mike.pierotti@docomopacific.net>
Re: Need help with a REGEX <mjcarman@mchsi.com>
Re: open(@_): Do not expect to get ARRAY(0x88a4c0) argu <whynot@pozharski.name>
Question on the length of a Scalar sln@netherlands.com
Re: Question on the length of a Scalar xhoster@gmail.com
Re: Question on the length of a Scalar <tadmc@seesig.invalid>
Re: Question on the length of a Scalar <tim@burlyhost.com>
Re: Question on the length of a Scalar <jurgenex@hotmail.com>
Troubles with first attempt to use the chart package. <r.ted.byers@gmail.com>
Re: Troubles with first attempt to use the chart packag <tadmc@seesig.invalid>
Where is the documentation to show how to add a PNG fil <r.ted.byers@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Oct 2008 12:48:02 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: crisis Perl
Message-Id: <bd358b98-b6e1-479b-bd9a-e02c6df0f9f0@d36g2000prf.googlegroups.com>
On Oct 16, 6:48 am, cartercc <carte...@gmail.com> wrote:
>
> As to writing good code to begin with, it's easier said than done.
> When it's almost midnight, and you've been at work for about 14 hours,
> and you have people (not just your manager, but his boss, the big
> boss, and the guy in charge of the project) calling you every 15
> minutes, and the people you had promised things mad at you because you
> were tasked with doing a job THAT THEY KNEW ABOUT FOUR WEEKS AGO BUT
> DIDN'T GIVE YOU A HEADS UP (!!!) ... well, pretty code takes a back
> seat.
Okay, I know people have already beaten this thread to death, but I
still wanted to add my input.
I've discovered writing any code, including crisis code, is vastly
improved when the lines "use strict;" and "use warnings;" are used at
the top of the script. You might be saying, "I don't have enough time
to put those in!" but hear me out:
It really doesn't take any more time to program with those lines
than without, and they are HUGE timesavers. They basically point out
obscure errors that would take hours to find without them, and they
end up forcing you to write cleaner code to begin with (which doesn't
take any longer than writing "un-clean" code).
I once had a co-worker who was learning Perl. He was writing a
script, and later told me that his script wouldn't compile, but
eventually figured out how to fix it. I praised him for fixing the
bug and asked how he fixed his script, and he replied, "I removed the
'use strict;' line and the script ran just fine." I told my co-worker
that that didn't actually remove the real problem and offered to look
over his code. Sure enough, there was a simple little error that was
easily fixed (that he didn't have enough experience to identify).
Why am I telling you this story? Because a lot of people
mistakenly think that programming with "use strict;" and "use
warnings;" takes lots longer than programming without them, but in
practice, I've found just the opposite is true (they tell you exactly
where a potential error is). All you have to do is learn to program
using them, and then you'll see your development times plummet (or at
least significantly drop). And if you don't regularly program with
them, I suggest learning to as soon as possible, and not waiting for
the next crisis to learn!
As an added bonus, the "use warnings;" line won't actually change
the behavior of your program, but will spit out warnings when it
thinks something's wrong with your script. You might consider this a
bonus because if you discover weeks later that, due to the warnings
your script is giving, your input is in the wrong format, you may have
an easier time convincing your manager that the script needs to be
cleaned up. Otherwise, the script will be silent about your incorrect
input assumptions -- giving the managers the false impression that
everything is okay. (I've seen this a lot myself.)
I also recommend adding "use strict;" and "use warnings;" to any
script that doesn't already have it. I know it's easier said than
done when dealing with "crisis code" that you didn't write yourself,
but the effort you take to convert the script (such as declaring
variables) will be worth it. I've had to do it several times myself,
and I can tell you that it gets easier the more times you do it.
And if you contest that you don't have the time to convert your
script to run with "use strict;" then I seriously recommend that AT
THE VERY LEAST you still put in "use warnings;". Like I said before,
"use warnings;" won't change the behavior of your script -- but IT
WILL report many simple errors, like misspelled variable names (which
are often difficult to track down), uninitialized variables, and input
in the wrong format (like trying to add two non-numbers together).
Also, be aware that you can still use "strict" and "warnings" in
blocks of code that you add in yourself. If you find yourself adding
a new block of code (such as in a loop or a condition), you can still
put "use strict;" and "use warnings;" in that block to take advantage
of their special powers of error-finding. (If you use any outside
variables in that block, however, you'll have to declare those
variables (with "my") where they're first used in order to prevent
"use strict;" from complaining. But that should be fairly easy to
do.)
Also, I highly recommend that you use "or die "[error message goes
here]: $!\n";" (or something similar) after every open(), opendir(),
and chdir() statement you use. Now, several people I've worked with
shun them saying "I don't want the program to die, I want it to
continue." This is usually just a cop-out, but if their reasons are
legitimate, then use "or warn" instead of "or die". The program will
still continue, but it will give a nice warning when something doesn't
happen that it expected to happen.
Another excuse I hear is, "I don't have time to type out 'or die
"blah blah blah: $!\n";' hundreds of time in my code" That's a lousy
excuse, but if they insist, then have them use just " or die;" (or AT
LEAST " or warn;"). Those seven extra keystrokes should be easy
enough for anyone to type that it won't increase development times
(presuming they CAN type).
> I mostly grab data from one place, massage it, and send it to another
> place. The format of the data I get, and/or the format of the final
> form, changes several times a year. It's not that the code breaks a
> lot, but that the specifications change. Since we can't 'fix' the
> specifications, we have to 'fix' the code, and guess who gets blamed
> if the code isn't 'fixed.'
I do a lot of "data massaging" myself, and I can say that it's a
life-saver to be able to code with "use strict;" and "use warnings;".
Otherwise, a simple misspelled variable name will create a bug that
can take hours to track down, and a parsed out value that I expect to
be a number but isn't can go undetected for years (literally!).
And, like you, I have also had cases where the specifications
change. Especially in those cases, I will take care to DOCUMENT IN
THE FORM OF COMMENTS what the input is supposed to look like,
including GIVING EXAMPLES of the input. The examples are a
lifesaver! That's because when the specifications DO change, then
I'll have a record of what the OLD specifications looked like, and
have an easier time massaging the new input into the old data
structures.
Here's an example of how I'd document examples:
# Look for a line that looks like:
# MGAP 30N50W ...INCREASING PRESSURE...
# and store the latitude and longitude in the %location hash:
if (m/^(\w{4})\s+(\d+[NS])(\d+[EW])\b/)
{
$location{$1}{latitude} = $2; # $2 looks like "30N"
$location{$1}{longitude} = $3; # $3 looks like "50W"
}
That way, when the next maintainer encounters the code, they won't
have to decipher the regular expression to figure out what it was
meant to do. They may have to verify that the regular expression does
as advertized, but in my experience this is MUCH simpler to do than
deciphering the expression from scratch, as deciphering the regular
expression (with no intent known as to what it's supposed to be
looking for) makes it almost impossible to figure out if it contains a
bug -- because there is no way to verify if its actual behavior is
what the original programmer meant it to be.
In other words, placing comments of expected input gives the
maintainer (which I suspect will probably be you) an easier time of
following the input along the code, and of being able to tell if a
possible bug lies in one area of code (versus another).
One more thing:
Once I read a post by a poster named "A. Sinan Unur" that
recommended declaring variables IN AS SMALL AS SCOPE AS POSSIBLE.
That is, instead of declaring all your variables at the top of your
script, declare then inside the smallest block needed. So if a
variable isn't needed OUTSIDE a loop nor BETWEEN its iterations, go
ahead and declare it INSIDE the loop brackets.
So instead of code like this (which I've seen before and and had to
clean up):
$level = 0;
$station = "";
.
.
.
while (blah)
{
# some code here
# code that uses $level and $station here
# more code here
$level = 0; # re-initializing for the next loop
$station = $var2; # re-initializing for the next loop
}
do this instead:
while (blah)
{
# some code here
my $level = 0;
my $station = "";
# code that uses $level and $station here
# more code here
}
Note that the first form had to initialize the variables TWICE (once
at the top, and once at the end of a loop to "prepare" the variables
for the next loop-iteration) but the second form only initialized the
variables ONCE and nothing has to be done about them at the end of the
loop.
So if you follow A. Sinan Unur's advice of declaring your variables
in as small as scope as possible, you'll find that your variables
won't have to be set as often, and they'll be easier to follow (and
you'll avoid a lot of unnecessary bugs).
(Just so you know, I used to prefer declaring all my variables at
the top of a function, but once I decided to try A. Sinan Unur's
advice I discovered that both my Perl code and my C++ code became much
cleaner and easier to follow! Naturally, now I prefer declaring my
variables in as small as scope as possible. Nowadays I cringe when I
see Perl and C++ with dozens of variables declared at the top --
almost always a handful of those variables are never even used in the
code!)
In conclusion, I recommend you follow these principles, even when
writing and modifying "crisis code":
1. If you don't already, ALWAYS program with "use strict;" and "use
warnings;" and learn to fix the errors they give out.
2. If you're fixing a script someone else has written that doesn't
use "strict" and "warnings", ALWAYS add "use warnings;" and strongly
consider adding "use strict;".
3. ALWAYS handle open(), opendir(), and chdir() statements. I
recommend you use "or die "[error message]: $!\n"", but using "or die
$!;", "or warn;" or any other method of handling a failure is also
acceptable.
4. When massaging input, ALWAYS give examples of the expected input.
The actual input will eventually change, but having examples of
previous expected input will let the future maintainer know which new
input goes into which existing data structures.
5. Get in the habit of declaring your variables in as small as scope
as possible. This will lead to less-polluted namespaces, less
variables to keep track of at any one time, and fewer chances of like-
named variables writing over each other's values.
I hope this helps. I've been in your situation before, and I've
found that following all of these suggestions helps immensely.
Take care, CC.
-- Jean-Luc Romano
------------------------------
Date: Wed, 22 Oct 2008 14:27:15 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: crisis Perl
Message-Id: <53e22bf9-8b06-4cf5-b4c8-adfe1266765a@u75g2000hsf.googlegroups.com>
On Oct 22, 3:48=A0pm, "jl_p...@hotmail.com" <jl_p...@hotmail.com> wrote:
> 1. =A0If you don't already, ALWAYS program with "use strict;" and "use
> warnings;" and learn to fix the errors they give out.
Agree.
> 2. =A0If you're fixing a script someone else has written that doesn't
> use "strict" and "warnings", ALWAYS add "use warnings;" and strongly
> consider adding "use strict;".
Agree. I tend to test the code with the -w switch rather than use
warnings because users get confused about whatever warning messages
may remain in the script, but yes, always run with warnings enabled.
> 3. =A0ALWAYS handle open(), opendir(), and chdir() statements. =A0I
> recommend you use "or die "[error message]: $!\n"", but using "or die
> $!;", "or warn;" or any other method of handling a failure is also
> acceptable.
Agree. Sometimes I get lazy and omit this, but I've made this a habit
so I have to deliberately omit it.
> 4. =A0When massaging input, ALWAYS give examples of the expected input.
> The actual input will eventually change, but having examples of
> previous expected input will let the future maintainer know which new
> input goes into which existing data structures.
This is where we break down. It takes time to document, and time is
sometimes a luxury I don't have. I generally like to include a README
file along with the script, because it's usually several things (e.g.,
a database query, a distribution list) that wouldn't go in the code. I
almost always include a script header and a function header (required
arguments, return values, and side effects), but honestly, most of the
time it's just a blank header. In particular, POD is time consuming
and only used by me. This is my biggest failure.
> 5. =A0Get in the habit of declaring your variables in as small as scope
> as possible. =A0This will lead to less-polluted namespaces, less
> variables to keep track of at any one time, and fewer chances of like-
> named variables writing over each other's values.
Agree with a couple of caveats. If I use a standard variable
throughout, like $counter, or $sum, I'll declare it at the top simply
to avoid the overhead of a multitude of 'my' declarations. If I'm
writing a CGI script or a module, I'll declare all the variables at
the top as a form of documentation or pseudocode or like fields in OO
languages, such as:
my $nametitle;
my $namefirst;
my $namemiddle;
my $namelast;
my $namesuffix;
my $addressstreet;
my $addresscity;
my $addresszip;
my $phonehome;
my $phonecell;
my $phonework;
... and so on. That way, I can see at a glance my logical fields, even
though I may use some of them only within subs.
> =A0 =A0I hope this helps. =A0I've been in your situation before, and I've
> found that following all of these suggestions helps immensely.
Agree. I think that the biggest problem is a lack of support or a lack
of understanding on the part of the immediate IT upstream. We have
about 12 staff, one software guy (me), a couple of management types
(including my immediate supervisor), and all the rest are hardware
guys who if they have had any programming experience at all have used
a drag and drop IDE like VS and think that all there is to it is
dropping widgets on a canvas and setting their properties. It's
sometimes frustrating to be told to do the obvious by someone who
doesn't have the knowledge or experience to understand why the obvious
won't work.
Thanks, CC.
------------------------------
Date: Wed, 22 Oct 2008 13:51:15 -0700 (PDT)
From: Owen <xemoth@gmail.com>
Subject: Re: greping a value from a file
Message-Id: <a4b7e545-b3e6-4ea9-954c-b96318375838@k36g2000pri.googlegroups.com>
On Oct 23, 12:44 am, paul_0...@yahoo.com wrote:
> I have a file with the following contents(see below) and I want to get
> the value associated with PROCESS_PID using grep or what ever is the
> most effient way. Once I get that value (23491) into a variable
> I am going to use it to send a kill command to a process.
>
> Of course I need to test if the grep was successful or not since all
> my files may not contain that name value pair.
>
> cat file
> PROCESS_START_DATE='20081021'
> PROCESS_PID='23491'
>
> Thanks
Hi,
I tried use the program below to start or stop ktorrent, it may be
relevant to your problem. (it was a failure for me because ktorrent
has a gui, but works ok where non gui programs are invoked)
owen
===============================================
#!/usr/bin/perl -w
use strict;
my $program = "ktorrent";
my $status = `/bin/ps cat | /bin/grep $program`;
if ( length($status) > 0 ) {
$status =~ /(^\d+)/;
print "$1\n"; #extract pid from here
exec "kill -9 $1"
}
else { exec "/usr/bin/ktorrent" } # start program
========================================================
------------------------------
Date: Wed, 22 Oct 2008 16:44:31 -0700 (PDT)
From: saragwyn <saragwyn@yahoo.com>
Subject: Re: IDE with Class Browser for Perl
Message-Id: <d570e359-112f-4dac-8c6a-c2999673d1b0@p10g2000prf.googlegroups.com>
> > Does anyone know of a Perl IDE that has any of that functionality?
> > Komodo 4.4 does not seem to do any class browsing for Perl.
>
> eclipse epic
I've gone through the feature list and user manual for Eclipse with
Epic, and I don't find class browsing described anywhere.
-Sara S
------------------------------
Date: Thu, 23 Oct 2008 11:10:37 +1000
From: "Michael R. McPherson Pierotti" <mike.pierotti@docomopacific.net>
Subject: Need help with a REGEX
Message-Id: <MLOdncBH2a-XUmLVnZ2dnUVZ_hmdnZ2d@giganews.com>
Folks its been awhile (5 years) since I have done anything with Perl so I
consider myself back at newbie statis :(
#strict on
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,Prompt => '/\</' ); #
$t->open(Host => "X.X.X.X");
$t->waitfor('/ENTER USERNAME \</');
$t->print("XXXXXXX");
$t->waitfor('/ENTER PASSWORD \</');
$t->print("XXXXXXX");
$t->waitfor('/\</')
or die "No Prompt";
@out1 = $t->get;
# -------------- #
# Dump all trees #
# -------------- #
@RIR = $t->cmd(String => "ZRIR:;", Output_record_separator => "\n") or die
"EEEK";
print @RIR;
$n=0;
while ($RIR[$n]) {
if ($RIR[$n] =~ m/^TREE/){
$line = $RIR[$n];
$line =~ /\d/;
print $line . "\n";
}
$n++;
}
Now my problem is this. The Net::Telnet command fills my array with lines
like the following
TREE= 950 ATYPE=N TON=INT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
1 0 1011 SPR NGC 11 32 APR 335 2 N 31
ATYPE=N TON=NAT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
671456 0 900 SPR SC 1 32 APR 336 2 N 33
ATYPE=N TON=NAT
DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
SDEST
671476 0 900 SPR SC 1 32 APR 336 2 N 33
My code if ($RIR[$n] =~ m/^TREE/) is successfully REGEX for my "TREE= 950
ATYPE=N TON=INT "
Now want I want to do is a REGEX to pull ONLY the digits out of this (950)
and assign them to s $string. Obviosly my $line =~ /\d/; isn't working and
I am braindead on REGEX since it has been so long.
Any and all help is greatly appricited.
BR Mike
------------------------------
Date: Wed, 22 Oct 2008 18:21:24 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Need help with a REGEX
Message-Id: <pkQLk.36334$SH5.6802@newsfe08.iad>
Michael R. McPherson Pierotti wrote:
...
>
> TREE= 950 ATYPE=N TON=INT
> DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
> SDEST
> 1 0 1011 SPR NGC 11 32 APR 335 2 N
> 31
...
>
> My code if ($RIR[$n] =~ m/^TREE/) is successfully REGEX for my "TREE=
> 950
> ATYPE=N TON=INT "
>
> Now want I want to do is a REGEX to pull ONLY the digits out of this
> (950)
> and assign them to s $string. Obviosly my $line =~ /\d/; isn't
> working and I am braindead on REGEX since it has been so long.
>
> Any and all help is greatly appricited.
>
> BR Mike
$line =~ /\d/ isn't assigning a value. Did you want to drop the digits
or catpure them? I assume capture them.
You said you want to pull them out, did you mean just the "950" match or
other digits on the next lines, too?
Assuming you want the one in question:
my $digits = 0;
if ($RIR[$n] =~ m/^TREE=\s+(\d+)\s+/) {
$digits = $1;
# last; ??
}
You might want to do the match and then assign it and then do a last to
break out of the loop once you get the data you want. If you needed
something else than the above example, please clarify.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Thu, 23 Oct 2008 11:31:36 +1000
From: "Michael R. McPherson Pierotti" <mike.pierotti@docomopacific.net>
Subject: Re: Need help with a REGEX
Message-Id: <T-ydnUbi4KtkTmLVnZ2dnUVZ_o_inZ2d@giganews.com>
"Tim Greer" <tim@burlyhost.com> wrote in message
news:pkQLk.36334$SH5.6802@newsfe08.iad...
> Michael R. McPherson Pierotti wrote:
>
> ...
>>
>> TREE= 950 ATYPE=N TON=INT
>> DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
>> SDEST
>> 1 0 1011 SPR NGC 11 32 APR 335 2 N
>> 31
> ...
>>
>> My code if ($RIR[$n] =~ m/^TREE/) is successfully REGEX for my "TREE=
>> 950
>> ATYPE=N TON=INT "
>>
>> Now want I want to do is a REGEX to pull ONLY the digits out of this
>> (950)
>> and assign them to s $string. Obviosly my $line =~ /\d/; isn't
>> working and I am braindead on REGEX since it has been so long.
>>
>> Any and all help is greatly appricited.
>>
>> BR Mike
>
> $line =~ /\d/ isn't assigning a value. Did you want to drop the digits
> or catpure them? I assume capture them.
>
> You said you want to pull them out, did you mean just the "950" match or
> other digits on the next lines, too?
>
> Assuming you want the one in question:
>
> my $digits = 0;
> if ($RIR[$n] =~ m/^TREE=\s+(\d+)\s+/) {
> $digits = $1;
> # last; ??
> }
>
> You might want to do the match and then assign it and then do a last to
> break out of the loop once you get the data you want. If you needed
> something else than the above example, please clarify.
> --
> Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
> Industry's most experienced staff! -- Web Hosting With Muscle!
Tim,
That's exactly what I was looking for :) I need to pull those digits so I
can run a seperate telnet command just on theose TREE numbers from the first
query.
Thanks,
Mike
------------------------------
Date: Thu, 23 Oct 2008 01:26:55 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Need help with a REGEX
Message-Id: <fpQLk.345518$TT4.127145@attbi_s22>
Michael R. McPherson Pierotti wrote:
> TREE= 950 ATYPE=N TON=INT
> DIGITS AL NBR RT CT SP NL RC DEST CHI CNT
> SDEST
> 1 0 1011 SPR NGC 11 32 APR 335 2 N 31
>
> My code if ($RIR[$n] =~ m/^TREE/) is successfully REGEX for my "TREE= 950
> ATYPE=N TON=INT "
>
> Now want I want to do is a REGEX to pull ONLY the digits out of this (950)
> and assign them to s $string. Obviosly my $line =~ /\d/; isn't working
> and I am braindead on REGEX since it has been so long.
You're doing a match. You need to add a capture.
my ($string) = ($line =~ /(\d+)/);
-mjc
------------------------------
Date: Thu, 23 Oct 2008 00:13:03 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: open(@_): Do not expect to get ARRAY(0x88a4c0) arguments
Message-Id: <slrngfv5qv.r7j.whynot@orphan.zombinet>
On 2008-10-22, kj <socyl@987jk.com.invalid> wrote:
> In <gdndh7$e6p$1@reader1.panix.com> kj <socyl@987jk.com.invalid>
> writes:
>
>>I've written a script that is supposed to serve as a wrapper around an
>>existing command-line utility (which I'll call "foobar" below). This
>>utility has a very rich and complex set of command-line options, so,
>>in order to have the wrapper script follow the original utility's
>>calling conventions as closely as possible, while bypassing the shell,
>>I had the line
>
>> open my $out, '|-', 'foobar', @ARGV or die $!;
>
>>...but open complains with
>
>> Internal error: open(@_): Do not expect to get ARRAY(0x88a4c0)
>> arguments
>
> I found the problem. It seems to be a bug in autodie...
Not for me
perl -wle '
open $out, q{|-}, q{/bin/ls}, qw(-s -i /) or die;
print while(<$out>);
close $out;
wait;'
total 92
112225 4 bin 20 0 initrd.img 320641 4 root
464929 4 boot 13 0 initrd.img.old 368737 4 sbin
448897 4 cdrom 160321 8 lib 1 0 sys
480961 4 cdrom0 11 16 lost+found 2 8 tmp
679 0 dev 496993 4 media 2 4 usr
384769 8 etc 304609 4 mnt 2 4 var
128257 4 floppy 432865 4 opt 18 0 vmlinuz
2 4 home 1 0 proc 12 0 vmlinuz.old
Looking at your headers: Ubuntu, Hardy Heron? So, I believe,
perl5.10.0 (just a guess). Right?
So here we go different ways -- your code fails for you, but succedes
for me; please, provide complete minimal example and exact error
messages you've got. (That means -- copy-paste.)
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: Wed, 22 Oct 2008 21:13:54 GMT
From: sln@netherlands.com
Subject: Question on the length of a Scalar
Message-Id: <rs4vf4d14d56ueo0itjuir6u0tju2u3g9g@4ax.com>
I just have a simple question.
When I call the length function on a scalar, is it read directly
(ie: already know its length), or does it traverse the string
counting its characters until it hits a nul terminator?
As an example, which one of these would be a more efficient test?
I'm not saying these constructs hold any practicality, its just to
test the nature of length.
my $str = 'Start';
my $cnt = 1;
# method 1
while (length ($str) )
{
$str .= (sprintf "more %d", $cnt);
$str = '' if ( $cnt % 10000000 == 0);
$cnt++;
}
# method 2
while (defined $str )
{
$str .= (sprintf "more %d", $cnt);
$str = undef if ( $cnt % 10000000 == 0);
$cnt++;
}
Thanks!
------------------------------
Date: 22 Oct 2008 21:31:25 GMT
From: xhoster@gmail.com
Subject: Re: Question on the length of a Scalar
Message-Id: <20081022173151.508$9M@newsreader.com>
sln@netherlands.com wrote:
> I just have a simple question.
>
> When I call the length function on a scalar, is it read directly
> (ie: already know its length), or does it traverse the string
> counting its characters until it hits a nul terminator?
The first one. It can't just traverse for a nul, because in Perl a nul is
a legal character to be in the middle of a string.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Wed, 22 Oct 2008 16:37:26 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Question on the length of a Scalar
Message-Id: <slrngfv78m.ohh.tadmc@tadmc30.sbcglobal.net>
sln@netherlands.com <sln@netherlands.com> wrote:
> When I call the length function on a scalar, is it read directly
> (ie: already know its length),
Yes.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 22 Oct 2008 14:56:09 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Question on the length of a Scalar
Message-Id: <_jNLk.5655$UD6.109@newsfe07.iad>
sln@netherlands.com wrote:
> I just have a simple question.
>
> When I call the length function on a scalar, is it read directly
> (ie: already know its length), or does it traverse the string
> counting its characters until it hits a nul terminator?
>
In Perl,
$string = "this and that and junk to ending here";
and
$string = "this\nthat\r\nother\lfand whatever else
here
and here
and
here";
will see the string from "^this ... all the way to ... here$" regarding
its total length.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Wed, 22 Oct 2008 19:51:47 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Question on the length of a Scalar
Message-Id: <kcpvf4970v6o0fg0j24u04mrmcugsnacsj@4ax.com>
xhoster@gmail.com wrote:
>sln@netherlands.com wrote:
>> When I call the length function on a scalar, is it read directly
>> (ie: already know its length), or does it traverse the string
>> counting its characters until it hits a nul terminator?
Neither, nor.
First the string representation of that scalar is computed, then the
length of that string representation returned.
jue
------------------------------
Date: Wed, 22 Oct 2008 14:07:49 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Troubles with first attempt to use the chart package.
Message-Id: <3014a21d-0f77-423e-97af-97429f34a756@m36g2000hse.googlegroups.com>
There error message I get is:
Can't use string ("18") as an ARRAY ref while "strict refs" in use at
C:/Perl/site/lib/Chart/Base.pm line 784.
I saw this in the documentation:
# GIFgraph.pm-style API to produce png formatted charts
@data = ( \@x_tick_labels, \@dataset1, ... , \@dataset_n );
$obj->png ( "filename", \@data );
So here are parts of my code:
My Arrays:
my @weeks;
my @ni;
my @fi;
my @number_remaining;
my @number_next_week;
my @totals;
my @totals_nw;
All these are numeric vectors, and are properly populated and used in
creating a PDF file with a table. Imagine them populated with weeks
as integers, and the rest with floating point numbers.
I create the array, following the provided example, as:
my @chart1_data = (\@weeks,\@fi);
my @chart2_data = (\@weeks,\@ni);
my @chart3_data = (\@weeks,\@number_remaining,\@number_next_week);
my @chart4_data = (\@weeks,\@totals,\@totals_nw);
And then I create the chart as follows:
my $chart1 = Chart::Lines->new(500,500);
my $chart2 = Chart::Lines->new(500,500);
my $chart3 = Chart::Lines->new(500,500);
my $chart4 = Chart::Lines->new(500,500);
my %hash = ('title' => 'Estimated Proportion of captures that may
produce a refund.',
'xy_plot' => 'true','precision' => 2,'include_zero' =>
'true','imagemap' => 'true');
$chart1->set(%hash);
%hash = ('title' => 'Estimated Number of captures that may produce a
refund.');
$chart2->set(%hash);
%hash = ('title' => 'Estimated Number of Remaining Refunds.');
$chart3->set(%hash);
%hash = ('title' => 'Estimated Value of Refunds.');
$chart4->set(%hash);
my @labels = ('Total remaining', 'Estimated number of refunds to occur
next week');
$chart3->set ('legend_labels' => \@labels);
@labels = ('Estimated value of total remaining', 'Estimated value of
refunds to occur next week');
$chart4->set ('legend_labels' => \@labels);
$chart1->png("chart1.png",@chart1_data);
$chart2->png("chart1.png",@chart2_data);
$chart3->png("chart1.png",@chart3_data);
$chart4->png("chart1.png",@chart4_data);
this clearly follows the example provided (or so it appears), so why
do I get a complaint about the first 'X' value?
Any assistance would be appreciated.
Thanks
Ted
------------------------------
Date: Wed, 22 Oct 2008 16:03:54 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Troubles with first attempt to use the chart package.
Message-Id: <slrngfv59q.o3g.tadmc@tadmc30.sbcglobal.net>
Ted Byers <r.ted.byers@gmail.com> wrote:
> There error message I get is:
>
> Can't use string ("18") as an ARRAY ref while "strict refs" in use at
> C:/Perl/site/lib/Chart/Base.pm line 784.
>
> I saw this in the documentation:
> $obj->png ( "filename", \@data );
^^
^^
> $chart1->png("chart1.png",@chart1_data);
^
^
One of these things is not like the other,
one of these things just doesn't belong...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 22 Oct 2008 19:11:46 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Where is the documentation to show how to add a PNG file to a PDF
Message-Id: <df16a7e3-b6d0-40e1-880c-a529b8dff7f2@c60g2000hsf.googlegroups.com>
I successfully created a number of PNG files using chart, and I
successfully created my PDF file. Both look quite nice.
I did find, in the documentation of PDF::API2 the image functions
(e.g. my $png1 = $pdf->image_png("chart1.png");), but these do not
actually add the image to the current page. I have looked through all
the documentation I have for PDFs, including PDF::API2, but I do not
see anything about how to actually add the png file (which I assume is
read by "image_png") to a specific page.
I did find the following for PDF::Report
"$pdf->addImg($file, $x, $y);
"Add image $file to the current page at position ($x, $y).
"$pdf->addImgScaled($file, $x, $y, $scale);
"Add image $file to the current page at position ($x, $y) scaled to
$scale. "
But I didn't use PDF::Report, yet, so I am concerned that shifting to
it will break the code I have already written. I use PDF::Table for
much of my PDF file. Do you know if it plays nicely with
PDF::Report? I see PDF::Report is described as a wrapper for
PDF::API2, so I would have thought that there would be something like
'addImg' in the PDF::API2 API, but I don't see it there.
I am looking fo rthe path of least resistance to get these images
added to specific pages in my PDF.
Any help would be appreciated.
Thanks
Ted
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1940
***************************************