[23676] in Perl-Users-Digest
Perl-Users Digest, Issue: 5883 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 2 14:05:38 2003
Date: Tue, 2 Dec 2003 11:05:06 -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 Tue, 2 Dec 2003 Volume: 10 Number: 5883
Today's topics:
Re: [Newbie]Problem reading text file <asu1@c-o-r-n-e-l-l.edu>
Re: Array Indexing problem (Anno Siegel)
Re: Easy Field Grabbing Question <asu1@c-o-r-n-e-l-l.edu>
Re: hash key evaluation creates an entry ! (Anno Siegel)
LWP::Parallel::UserAgent does not follow redirects (Alex)
Re: Session Management? <zmonteca@zmonteca.com>
substitution question <nertz@numb.no>
Re: substitution question (Tad McClellan)
Re: substitution question (Anno Siegel)
Re: Unexpected tell() result <nobull@mail.com>
using GD module <eddGallary2@hotmail.com>
Re: using GD module <richard@zync.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Dec 2003 16:39:03 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: [Newbie]Problem reading text file
Message-Id: <Xns9445768514EAEasu1cornelledu@132.236.56.8>
Senthil Raja <senthil.raja@adcc.alcatel.be> wrote in
news:3FCC23C1.1ED31E49@adcc.alcatel.be:
> I have problem reading a test file, line by line. I've written the
> following code :-
>
> /* $parse has a file path */
> if (!-e $parse) { die ("Error - File \"$parse\" does not exists\n"); }
> if (!open (PARSE, "$parse")) { die ("Error - Unable to open \"$parse\"
> for reading. Check permissions\n"); }
You do not have (and probably should not) check if a file exists before
attempting to open it. I also prefer to expilictly specify the mode I
want the file opened.
open(PARSE, '<', $parse) or die "Cannot open $parse for reading: $!\n";
> while (<PARSE>)
> {
> /* I process the line in $_ */
> /* If the line matches a particular pattern, I'll extract the no. of
> further lines present in the file to be processed for this format */
> /* Let $record be the no. of further lines to be processed */
> for ($i=1; $i<=$record; $i++)
> {
> $line = <PARSE>;
> }
> /* After coming out of the for loop, go back and continue the while
> loop to retrieve next line */
>>>>>>>>>>Problem is here. The while loop terminates abruptly <<<<<<<<<<<
>
> }
>
> Is there anything wrong in the algorithm I use?
How can we tell?
> Am I missing a basic concept?
You need to post a short, self contained program with sample data so we
can see your particular problem.
Without pretending that the following is great code, is something like
the script below what you are trying to do?
#! perl
use strict;
use warnings;
while(<DATA>) {
if(/^SECTION:\s+(\d+)\srecords$/) {
my $rec;
for (1 .. $1) {
$rec = <DATA>;
print $rec;
}
}
}
__DATA__
SECTION: 4 records
4
3
2
1
SECTION: 2 records
99
75
C:\My Documents>perl ttt.pl
4
3
2
1
99
75
------------------------------
Date: 2 Dec 2003 17:17:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Array Indexing problem
Message-Id: <bqihf0$a5b$1@mamenchi.zrz.TU-Berlin.DE>
Harish <harish_recian@yahoo.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I am having a problem while indexing an element in perl.
>
> Problem Details:
>
> I have a data file which looks like the below
>
> 0.5 2 0.01 0 92 44 19818
> 0.5 2 0.015 0 62 42 19869
> 0.5 2 0.02 0 49 37 19902
> 0.5 2 0.025 0 40 30 19920
> 0.5 2 0.03 0 32 27 19935
> 0.5 2 0.035 0 28 31 19942
> 0.5 2 0.04 0 23 24 19952
>
>
> I need to selectively take few lines from this file store it into
> another file.
> I'm doing this by storing the file into an array. Then i would
> generate the index where the line that i'm interested in is located
> and then access the line and store in another file.My program seems to
> be working fine for everything except for few lines.
>
> if i have $x=4 then when i say $temp[$x] it prints the previous line
^^^^
Look closer. I bet you don't have $x == 4, it only prints as '4'.
> but when i say $temp[4] it prints the line that i'm interested in.
> This does not happen for all the lines.It is just happening for few
> lines.
>
> Could u let me know where I'm going wrong here.
^
Please use complete English words. This kind of jargon makes you look
like a wannabe.
>
> Thanks
> Harish
>
> P.S.
>
> I'm attaching the code below. Here $x is used to generate the index
> number.There is nothing wrong in the logic of genrating $x.
Sez you!
> if (!open(INFILE,"<f1.dat"))
> {
> die("cannot open file data.dat\n");
> }
> @temp = <INFILE>;
> close(INFILE);
> if (!open(OUTFILE,">testdata1.dat"))
> {
> die("cannot open file validation$a.dat\n");
> }
> @aspect = (0.5);
> @delay=(0.01,0.02,0.03);
> @msizes = (2);
>
> foreach $line1 (@aspect)
> {
> $p =($line1-0.5)*20;
> foreach $line2 (@msizes)
> {
> $q = ($line2-2);
> foreach $line3 (@delay)
> {
> $r = (($line3-0.01)*200);
> $x = $p*836+$q*19+$r;
Your $x is not an integer. I bet the undisclosed logic behind the
calculations is such that it *should* be an integer for the values
you calculate. But non-integer arithmetic is imprecise, and the
result may be just a tad smaller than it should be. When this number
is used as an array index, it is truncated to the next smaller integer,
so the resulting index is 3 instead of the expected 4. See
"perldoc -q decimals" for more on this.
The remedy is to round the result (instead of letting it be truncated):
$x = sprintf "%.0f", $p*836+$q*19+$r;
See "perldoc -q round" for this use of sprintf.
> print OUTFILE "$temp[$x]\n";
> }
> }
> }
Anno
------------------------------
Date: 2 Dec 2003 16:15:37 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Easy Field Grabbing Question
Message-Id: <Xns9445728C23AE9asu1cornelledu@132.236.56.8>
Geezer From Freezer <Geezer@Freezer.com> wrote in news:3FCC9B9D.29ABCD16
@Freezer.com:
> Anno Siegel wrote:
>>
>> my $fifth = (split)[4];
>>
>> Anno
>
> ok another stupid question time!
>
> how does the above work for an array?? $fifth is being created but
> does not reference the array?
>
> I've tried the following:
>
> foreach $user (@list){
>
> print "$user"; #output prints fine!
> my $fifth = (split $user[4]);
> print "$fifth"; # gets 0 every time!
> }
Joining this thread a little late, and at the risk of being
misunderstood, I am going to suggest that you read the posting guidelines
for this group. The document is available on the WWW at
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html, and is
posted here regularly (thank you Tad).
Reading that document will alert you to the fact that Perl comes with
searchable documentation accessible via the perldoc command (on Windows,
you also get the docs in HTML format). It will also point out that you
should at least have:
use strict;
use warnings;
in your programs.
While, with perldoc, it can sometimes be a little hard to figure out how
to reach the specific bit of information you are seeking, in your case,
it would have been easy to figure out since you are looking for a way of
splitting text into separate fileds. Hence:
perldoc -f split
In most cases, it is far easier and quicker to figure things out using
tools that are readily available on your computer.
Now, the subtle change you made to Anno's answer indicates you are not on
solid ground with your Perl knowledge. I suggest you invest in a book
first, and learn some of the basics first. Remember, one step at a time.
Sinan.
------------------------------
Date: 2 Dec 2003 16:53:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: hash key evaluation creates an entry !
Message-Id: <bqig1e$8vk$2@mamenchi.zrz.TU-Berlin.DE>
David K. Wall <usenet@dwall.fastmail.fm> wrote in comp.lang.perl.misc:
> Tad McClellan <tadmc@augustmail.com> wrote:
>
> > Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
> >
> >> To find the size of the array, using $# or @
> >
> > The $# syntax does NOT find the size of the array.
>
> Ok, so $#foo gives the *index* of the last element of the array, not
> the size of the array minus one. Other than setting the indices of an
> array to start with something other than zero (but don't do that), is
> there any situation where
>
> scalar @foo == $#foo + 1
>
> is NOT true? Or is the $# syntax available just in case someone DOES
> start array indexing with something other than zero?
>
> (It's not really important to me, I'm just curious.)
Your curiosity is satisfied in perlvar, which states:
... The following is always true:
scalar(@whatever) == $#whatever - $[ + 1;
Version 5 of Perl changed the semantics of $[: files that
don't set the value of $[ no longer need to worry about
whether another file changed its value. (In other words,
use of $[ is deprecated.) So in general you can assume
that
scalar(@whatever) == $#whatever + 1;
Anno
------------------------------
Date: 2 Dec 2003 09:44:26 -0800
From: aturchin@iname.com (Alex)
Subject: LWP::Parallel::UserAgent does not follow redirects
Message-Id: <d3d1b4a1.0312020944.7261005d@posting.google.com>
I am trying to harness the power of LWP::Parallel::UserAgent module
(on RedHat Linux 9, module version 2.56) but for some reason cannot
get it to follow redirects. To illustrate the problem I wrote two HTML
files: test01.html and redirect.html (which redirects to test01.html)
as well as a script (straight from the example at LWP::Parallel). The
script and its output (including a dump of the entire $entries
variable) are attached below.
The only potential issue that I see is that while
$entries->{'redirect_ok'} is '1',
$entries->{'_permitted'}->{'redirect_ok'} is "undef". I am not sure
what the significance of that is as I could not find any reference to
the _permitted variable in the documentation for the module.
Your help will be greatly appreciated!
Feel free to cc me on the email.
Alex
************************************************
SCRIPT:
#!/usr/bin/perl
use CGI;
use URI;
use LWP::Parallel::UserAgent;
use HTTP::Cookies;
use HTTP::Request;
use Data::Dumper;
# shortcut for demo URLs
my $url1 = "http://localhost/~aturchin/test/parallel/test01.html";
my $url2 = "http://localhost/~aturchin/test/parallel/redirect.html";
my $reqs =
[
HTTP::Request->new('GET', $url1),
HTTP::Request->new('GET', $url1),
HTTP::Request->new('GET', $url2),
HTTP::Request->new('GET', $url2),
];
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(0); # ignore duplicates
$pua->timeout (2); # in seconds
$pua->redirect (1); # follow redirects
foreach my $req (@$reqs)
{
print "Registering '".$req->url."'\n";
if ( my $res = $pua->register ($req) )
{
print $res->error_as_HTML;
}
}
my $entries = $pua->wait();
foreach (keys %$entries)
{
my $res = $entries->{$_}->response;
print "Asked for '",$res->request->url, "'.\n";
print "Answer was ", $res->code,": ", $res->message,"\n";
print "Result was:\n", $res->content();
}
print "Dumping all of the entries:\n\n", Dumper($entries);
*******************************************************
OUTPUT (LONG!):
Registering 'http://localhost/~aturchin/test/parallel/test01.html'
Registering 'http://localhost/~aturchin/test/parallel/test01.html'
Registering 'http://localhost/~aturchin/test/parallel/redirect.html'
Registering 'http://localhost/~aturchin/test/parallel/redirect.html'
Asked for 'http://localhost/~aturchin/test/parallel/test01.html'.
Answer was 200: OK
Result was:
<html>
<head>
<title>
test page for lwp::parallel
</title>
</head>
<body>
test page for lwp::parallel::useragent
</body>
</html>
Asked for 'http://localhost/~aturchin/test/parallel/redirect.html'.
Answer was 200: OK
Result was:
<html>
<head>
<title>Redirect to new page</title>
<meta http-equiv="Refresh" content="10; URL=test01.html">
</head>
<body>
This is the redirect test page.
</body>
</html>
Asked for 'http://localhost/~aturchin/test/parallel/redirect.html'.
Answer was 200: OK
Result was:
<html>
<head>
<title>Redirect to new page</title>
<meta http-equiv="Refresh" content="10; URL=test01.html">
</head>
<body>
This is the redirect test page.
</body>
</html>
Asked for 'http://localhost/~aturchin/test/parallel/test01.html'.
Answer was 200: OK
Result was:
<html>
<head>
<title>
test page for lwp::parallel
</title>
</head>
<body>
test page for lwp::parallel::useragent
</body>
</html>
Dumping all of the entries:
$VAR1 = {
'HTTP::Request=HASH(0x84dfc98)' => bless( {
'protocol' =>
bless( {
'ua' => {},
'parse_head' => 1,
'scheme' => 'http',
'max_size' => undef
}, 'LWP::Parallel::Protocol::http' ),
'redirect_ok' =>
1,
'request' =>
bless( {
'_content' => '',
'_uri' => bless( do{\(my $o =
'http://localhost/~aturchin/test/parallel/test01.html')}, 'URI::http'
),
'_headers' => bless( {
'user-agent' => 'libwww-perl/5.65'
}, 'HTTP::Headers' ),
'_method' => 'GET'
}, 'HTTP::Request' ),
'arg' => undef,
'response' =>
bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '<html>
<head>
<title>
test page for lwp::parallel
</title>
</head>
<body>
test page for lwp::parallel::useragent
</body>
</html>
',
'_rc' => '200',
'_headers' => bless( {
'etag' => '"29c257-83-6447c680"',
'content-type' => 'text/html;
charset=ISO-8859-1',
'connection' => 'close',
'last-modified' => 'Tue, 02 Dec 2003
17:07:22 GMT',
'accept-ranges' => 'bytes',
'date' => 'Tue, 02 Dec 2003 17:21:01
GMT',
'title' => 'test page for lwp::parallel',
'client-peer' => '127.0.0.1:80',
'content-length' => '131',
'server' => 'Apache/2.0.40 (Red Hat
Linux)'
}, 'HTTP::Headers' ),
'_msg' => 'OK',
'_request' => $VAR1->{'HTTP::Request=HASH(0x84dfc98)'}{'request'}
}, 'HTTP::Response' ),
'cmd_socket' =>
undef,
'content_size'
=> 131,
'_permitted' =>
{
'request' => undef,
'redirect_ok' => undef,
'protocol' => undef,
'response' => undef,
'arg' => undef,
'content_size' => undef,
'cmd_socket' => undef,
'size' => undef,
'listen_socket' => undef,
'fullpath' => undef,
'proxy' => undef
},
'size' => 8192,
'listen_socket'
=> undef,
'fullpath' =>
'/~aturchin/test/parallel/test01.html',
'proxy' => undef
},
'LWP::Parallel::UserAgent::Entry' ),
'HTTP::Request=HASH(0x84dfcf8)' => bless( {
'protocol' =>
bless( {
'ua' => {},
'parse_head' => 1,
'scheme' => 'http',
'max_size' => undef
}, 'LWP::Parallel::Protocol::http' ),
'redirect_ok' =>
1,
'request' =>
bless( {
'_content' => '',
'_uri' => bless( do{\(my $o =
'http://localhost/~aturchin/test/parallel/redirect.html')},
'URI::http' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/5.65'
}, 'HTTP::Headers' ),
'_method' => 'GET'
}, 'HTTP::Request' ),
'arg' => undef,
'response' =>
bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '<html>
<head>
<title>Redirect to new page</title>
<meta http-equiv="Refresh" content="10; URL=test01.html">
</head>
<body>
This is the redirect test page.
</body>
</html>
',
'_rc' => '200',
'_headers' => bless( {
'etag' => '"29c256-b2-5afb6780"',
'content-type' => 'text/html;
charset=ISO-8859-1',
'connection' => 'close',
'refresh' => '10; URL=test01.html',
'last-modified' => 'Tue, 02 Dec 2003
17:04:46 GMT',
'accept-ranges' => 'bytes',
'date' => 'Tue, 02 Dec 2003 17:21:01
GMT',
'title' => 'Redirect to new page',
'client-peer' => '127.0.0.1:80',
'content-length' => '178',
'server' => 'Apache/2.0.40 (Red Hat
Linux)'
}, 'HTTP::Headers' ),
'_msg' => 'OK',
'_request' => $VAR1->{'HTTP::Request=HASH(0x84dfcf8)'}{'request'}
}, 'HTTP::Response' ),
'cmd_socket' =>
undef,
'content_size'
=> 178,
'_permitted' =>
$VAR1->{'HTTP::Request=HASH(0x84dfc98)'}{'_permitted'},
'size' => 8192,
'listen_socket'
=> undef,
'fullpath' =>
'/~aturchin/test/parallel/redirect.html',
'proxy' => undef
},
'LWP::Parallel::UserAgent::Entry' ),
AND SO ON... CAN SEND THE WHOLE THING IF YOU THINK IT'D BE MORE
HELPFUL
------------------------------
Date: Tue, 02 Dec 2003 16:25:42 GMT
From: Z Monteca <zmonteca@zmonteca.com>
Subject: Re: Session Management?
Message-Id: <a23zb.8367$aw2.3667706@newssrv26.news.prodigy.com>
Malte Ubl <ubl@schaffhausen.de> wrote in news:bqhphg$bka$1@news.dtag.de:
> Z Monteca wrote:
>
>> I just did an implementation of sessions. Personally I used
>> Apache::Session::File, but I see others have used CGI::Session. Does
>> anyone have any pros/cons they could lend on using this method/module
>> for management.
>>
>> So far the one problem that I have run into is all the garbage clean
>> I up that has to be done. For every web request that is made it
>> seems to create a lot of unecessary session files in the session
>> directory (after a few hours I have upwards of 10's of thousands, but
>> only have a few thousand hits a day ~2,000). I am not sure why this
>> is. A true con is that you have to have run a cron script to clean up
>> this directory every few hours. Is this a standard element of using
>> the Apache::Session::File module or is my implementation seem to be
>> messed up a bit?
>
>
> Apache::Session defines an interface to be extended with other backend
> storage machanims. I like Apache::Session::CacheAny that uses the
> Cache::Cache interface. This enables you to use in memory cache which
> might be more appropriate for you.
>
> malte
>
This sounds much more appropriate. Session::File is horrible. I am going
to check out Session::CacheAny. Thanks for the insights.
-Z
------------------------------
Date: Tue, 2 Dec 2003 10:17:21 -0600
From: sparkane <nertz@numb.no>
Subject: substitution question
Message-Id: <MPG.1a3676f67b2b15098968b@news-central.giganews.com>
In case this turns out to be covered in documentation somewhere, I want
readers to know I have been reading documentation trying to find an
answer. If anyone can direct me to a specific doc which answers the
question, that'd be great.
I'm trying to add '<p>' after "\n\n" in a string wherever "\n\n" appears
and is not followed by '<p>'.
I'm unable to figure out a re that will match the \n\n (or whatever two
characters) and then fail if the following 3 characters are '<p>'.
I think I have a re that will match the whole string if '<p>' appears,
and interpolate over it:
$x = "\n\n<p>";
$x =~ s/(\n\n)(<p>)?/$1<p>/g;
but I'd still like to know how to do the substitution where it won't
interpolate if the '<p>' is there; wouldn't it be faster not to have to
interpolate the same string again? I guess I'm looking for something
like
$x =~ s/(\n\n)[^<p>]/$1<p>/g;
which won't interpolate if there's a '<p>', but also won't if there's a
'<font>' for example, so it's isn't satisfactory.
Thanks in advance.
------------------------------
Date: Tue, 2 Dec 2003 10:40:42 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: substitution question
Message-Id: <slrnbspg4a.agq.tadmc@magna.augustmail.com>
sparkane <nertz@numb.no> wrote:
> In case this turns out to be covered in documentation somewhere, I want
> readers to know I have been reading documentation trying to find an
> answer. If anyone can direct me to a specific doc which answers the
> question, that'd be great.
See "(?! )" in the section "Extended Patterns" in perlre.pod.
> I'm trying to add '<p>' after "\n\n" in a string wherever "\n\n" appears
> and is not followed by '<p>'.
> $x =~ s/(\n\n)(<p>)?/$1<p>/g;
$x =~ s/(\n\n)(?!<p>)/$1<p>/g;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Dec 2003 16:44:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: substitution question
Message-Id: <bqifgt$8vk$1@mamenchi.zrz.TU-Berlin.DE>
sparkane <nertz@numb.no> wrote in comp.lang.perl.misc:
> In case this turns out to be covered in documentation somewhere, I want
> readers to know I have been reading documentation trying to find an
> answer. If anyone can direct me to a specific doc which answers the
> question, that'd be great.
>
> I'm trying to add '<p>' after "\n\n" in a string wherever "\n\n" appears
> and is not followed by '<p>'.
>
> I'm unable to figure out a re that will match the \n\n (or whatever two
> characters) and then fail if the following 3 characters are '<p>'.
What you want is negative lookahead. It makes a match fail when the
"wrong thing" follows, without including what follows in the match.
> I think I have a re that will match the whole string if '<p>' appears,
> and interpolate over it:
>
> $x = "\n\n<p>";
> $x =~ s/(\n\n)(<p>)?/$1<p>/g;
>
> but I'd still like to know how to do the substitution where it won't
> interpolate if the '<p>' is there; wouldn't it be faster not to have to
> interpolate the same string again? I guess I'm looking for something
> like
>
> $x =~ s/(\n\n)[^<p>]/$1<p>/g;
^^^^^^
That matches a single character that is not one of "<", "p" or ">".
Definitely not what you want.
> which won't interpolate if there's a '<p>', but also won't if there's a
> '<font>' for example, so it's isn't satisfactory.
s/\n\n(?!<p>)/\n\n<p>/g;
The crucial part is "(?!<p>)". Look up "lookahead" in perlre to see how
it works.
Anno
------------------------------
Date: 02 Dec 2003 17:56:24 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unexpected tell() result
Message-Id: <u91xrn9k8n.fsf@wcl-l.bham.ac.uk>
Dan Wilga <dwilga-MUNGE@mtholyoke.edu> writes:
> In article <u9u14rc5ka.fsf@wcl-l.bham.ac.uk>,
> Brian McCauley <nobull@mail.com> wrote:
>
> > > It seems that under glibc 2.3 a file opened in append mode will read
> > > from the current file position, but writes always go to the end and do
> > > not move that position. Even straight after a write, the file pointer
> > > is still at the beginning: pointing at the next byte to be read.
> >
> > Yeah, now you describe it that does sound like "the right thing". But
> > not so much so that all other behaviour could be considered "the wrong
> > thing".
>
> Then this begs the question: Should Perl account for the fact that this
> code behaves differently on different versions of glibc? Shouldn't Perl
> work the same, independent of glibc version?
No I don't think so - this is sufficiently obscure that I don't think
it really matters.
Incidently, looking at open() in the single Unix specification V3 it
would appear "the right thing" is not actually conformant with SUS3.
I'd be more inclined to see this as carelessness in the drafting of
SUS3 than a bug in glibc.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 03 Dec 2003 04:24:11 +1100
From: Edo <eddGallary2@hotmail.com>
Subject: using GD module
Message-Id: <3FCCCABB.4080405@hotmail.com>
Hello
I am very novice in the areas of using modules, this GD::Graph is a bit
over my head at this time.
what is wrong with this, mostly taken out of the doc examples.
#!/Usr/local/bin/perl
use strict;
use warnings;
use GD::Graph;
my @data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
[ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ]
);
my $graph = GD::Graph::chart->new(400, 300); <---line 12
my $my_graph;
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Some simple graph',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2
) or die $my_graph->error;
my $gd = $my_graph->plot(\@data) or die $my_graph->error;
when I run it, I get
Can't locate object method "new" via package "GD::Graph::chart" (perhaps
you forgot to load "GD::Graph::chart"?) at prog/graph line 12.
thanks
------------------------------
Date: Tue, 02 Dec 2003 18:40:12 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: using GD module
Message-Id: <vspn4chapphked@corp.supernews.com>
In article <3FCCCABB.4080405@hotmail.com>, "Edo" <eddGallary2@hotmail.com>
wrote:
> Hello
> I am very novice in the areas of using modules, this GD::Graph is a bit
> over my head at this time.
> what is wrong with this, mostly taken out of the doc examples.
>
> #!/Usr/local/bin/perl
> use strict;
> use warnings;
> use GD::Graph;
>
> my @data = (
> ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
> [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
> [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ] );
>
> my $graph = GD::Graph::chart->new(400, 300); <---line 12
> my $my_graph;
> $graph->set(
> x_label => 'X Label',
> y_label => 'Y label',
> title => 'Some simple graph', y_max_value
> => 8,
> y_tick_number => 8,
> y_label_skip => 2
> ) or die $my_graph->error;
> my $gd = $my_graph->plot(\@data) or die $my_graph->error;
>
> when I run it, I get
> Can't locate object method "new" via package "GD::Graph::chart" (perhaps
> you forgot to load "GD::Graph::chart"?) at prog/graph line 12. thanks
This error is telling you that you should have "use GD::Graph::chart" at
the top. Unfortunately, this will still give an error to the effect that
GD::Graph::chart can't be found. In the methods section of the GD::Graph
perldoc, it says that the word chart must be replaced by one of: bars,
lines, points, linespoints, area, mixed or pie. So, for example, put "use
GD::Graph::bars" at the top of your script and fix the variable name
problem ($my_graph or $graph ?) and this script should work. Provided
your perl _really_ is in /Usr/local/bin and not /usr/local/bin.
HTH
Rich
------------------------------
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 5883
***************************************