[18186] in Perl-Users-Digest
Perl-Users Digest, Issue: 354 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 25 21:05:44 2001
Date: Sun, 25 Feb 2001 18:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983153112-v10-i354@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 25 Feb 2001 Volume: 10 Number: 354
Today's topics:
Re: Active Perl and preinstalled modules... <carvdawg@patriot.net>
Check Out a web based forum of this group at : <TeKno@supportinfo.com>
Re: Check Out a web based forum of this group at : <godzilla@stomp.stomp.tokyo>
delete the own directory <c.gersch@team.isneurope.com>
Re: file size <tore@extend.no>
files.bbs to html converter <tlmiller@chatnfiles.com>
Getting Download Dialogue instead of Proper Execution (No Name)
Re: Getting Download Dialogue instead of Proper Executi (Gwyn Judd)
Graphic file manipulation <berube@odyssee.net>
Re: Graphic file manipulation <godzilla@stomp.stomp.tokyo>
Re: Graphic file manipulation <iltzu@sci.invalid>
Re: perl newbie question (Damian James)
Re: PROPOSAL: Graphics::ColorNames (Ilya Zakharevich)
Re: question about 'for' loop functionality <len.green@ntlworld.com>
Re: question about 'for' loop functionality (Garry Williams)
Re: question about 'for' loop functionality <c_clarkson@hotmail.com>
Re: question about 'for' loop functionality (Martien Verbruggen)
Re: Question.about s/// (Ben Okopnik)
Quick Beginers question. about filling an array. <abcd@ntlworld.com>
Re: Quick Beginers question. about filling an array. <bwalton@rochester.rr.com>
Re: Quick Beginers question. about filling an array. (Garry Williams)
Re: regexp question <bwalton@rochester.rr.com>
Re: SMTP server (Ben Okopnik)
Re: SMTP server (The Mosquito ScriptKiddiot)
Re: splice question (Martien Verbruggen)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Feb 2001 14:29:33 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Active Perl and preinstalled modules...
Message-Id: <3A995D1D.70015803@patriot.net>
If you're using ActiveState Perl, why not use PPM to install the modules you
want?
I think LWP::UserAgent ships with the default installation, but don't quote me
on that...
I've been using it for a while and don't remember exactly...
Alok Menghrajani wrote:
> Hi,
>
> I want to write a program that will fetch a webpage accepting cookies. I was
> wondering how to know what modules are already installed on my system (i'm
> using activePerl on win98). The problem is that when I try to install the
> libwww-perl-5.50.tar I get error messages...
>
> Alok.
------------------------------
Date: Sun, 25 Feb 2001 20:50:53 GMT
From: "TeKno" <TeKno@supportinfo.com>
Subject: Check Out a web based forum of this group at :
Message-Id: <Neem6.2723$69.303192209@newssvr10-int.news.prodigy.com>
http://www.supportinfo.com look in the forums, enjoy the rest of the pages
too!
------------------------------
Date: Sun, 25 Feb 2001 14:19:27 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Check Out a web based forum of this group at :
Message-Id: <3A9984EF.E1C9A138@stomp.stomp.tokyo>
TeKno wrote:
> http://www.supportinfo.com look in the forums, enjoy the rest
> of the pages too!
Your site is amongst the worst designed sites on our internet.
This opening page of yours contains java, style sheets and
some idiotic file more than quarter of a megabyte in size which
would take two minutes to load at 38k modem speed. Additionally
your opening page is a redirect, after waiting several minutes
to load all your garbage. I didn't wait and didn't bother to
pull links from your document source.
This opening page of yours indicates to me you folks at
supportinfo.com don't have friggin clue about our internet
and, most likely, not a clue about computer technology.
You taunt yourself as a support site?
Shoot, your posting from Prodigy and your spamming so
many newsgroups is clue enough you are a total bozo.
* annoyed laugh *
Godzilla!
------------------------------
Date: Mon, 26 Feb 2001 02:27:07 +0100
From: "Christian Gersch" <c.gersch@team.isneurope.com>
Subject: delete the own directory
Message-Id: <97cbdc$o48$02$1@news.t-online.com>
Hi there!
The following situation:
The Perlscript "script.pl" has been executed and deleted itsself by "unlink
<script.pl>;".
Okay, now the directory where the script _was_ is empty.
How can I realize it to delete the empty directory, when the script has
already deleted itsself.
The name of the directory is not know for the script - but there is a
variable, isn't it?
...and what's the command to delete a directory...I think "unlink" is only
for files...?
Thank you very much!
-Chris
--
Christian Gersch, chris@team.isneurope.com
:: www.neukunden.myisn.de - Geld für Ihre Startseite ::
------------------------------
Date: Sun, 25 Feb 2001 23:19:59 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: file size
Message-Id: <MPG.1503a37c170b35629898c3@news.online.no>
In article <3A9668C2.98DF8A2E@bms.umist.ac.uk>, peb@bms.umist.ac.uk
says...
> If you're only interested in the file size then you can use
> the -s file test operator which returns the size of the file
> in bytes.
>
> e.g. print -e "/etc/passwd";
Hmm? I think that one needs some clarification; '-e' checks if the
file exists, while '-s' returns the filesize. Example;
my $filename = '/etc/passwd';
my $filesize = undef;
if (-e $filename) {
$filesize = -s $filename;
}
...to be on the safe side. :)
--
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
------------------------------
Date: Sun, 25 Feb 2001 17:50:38 -0600
From: "Tom Miller" <tlmiller@chatnfiles.com>
Subject: files.bbs to html converter
Message-Id: <t9j6cksbng479b@corp.supernews.com>
I have about 100,000 files or so at www.chatnfiles.com and as a former bbs
sysop I would really like to make the accessing/searching as friendly as it
used to be on my bbs. Does anyone have a lead on some kind of auto-magic
indexing/conversion that will create something userfriendly?
Thanks,
Tom
------------------------------
Date: Sun, 25 Feb 2001 19:53:51 GMT
From: bdrobin@zdnetonebox.com (No Name)
Subject: Getting Download Dialogue instead of Proper Execution
Message-Id: <3a996420.160888715@news.ne.mediaone.net>
Help! I am a beginner....
I have a chunk of fairly simple code... crawls a web page, discovers
links. When I run it, instead of executing properly... I suddenly
get a download dialogue box. Wierd thing is, that if rip out the body
and leave nothing but a few print statements, the print statements
work. Then, if I slowly add the rest of the "offending" back in,
usually small chunks at a time, once fully restored, it works
perfectly.
But if I come back tomorrow, and run the same code that worked
perfectly tonight, it goes back to giving me a download dialogue and I
have to start all over again.
Any help would be much appreciated.
Thanks.
bd
------------------------------
Date: Sun, 25 Feb 2001 21:03:09 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Getting Download Dialogue instead of Proper Execution
Message-Id: <slrn99isoc.c92.tjla@thislove.dyndns.org>
I was shocked! How could No Name <bdrobin@zdnetonebox.com>
say such a terrible thing:
>Help! I am a beginner....
As a beginner, one of the first things you have to learn is about
context. Context being the stuff you have to provide to us, in the form
of actual, working (hopefully) source code so that we can understand
what the hell you are trying to do. Code speaks louder than words, a lot
of the time. Generally you don't need to post your whole script.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
BOFH excuse #91:
Mouse chewed through power cable
------------------------------
Date: Sun, 25 Feb 2001 15:15:38 -0500
From: "Neb" <berube@odyssee.net>
Subject: Graphic file manipulation
Message-Id: <97bodg$803$1@cti15.citenet.net>
Hi,
I have a script that reads from a database an image file content (.gif or
.jpg) into a variable. What I want to do is to resize this image and send
it back to the client browser (content-type: image/gif).
I'm trying to use Image::Magick, but the problem is that the Read method
*needs* a FILEHANDLE to the image file. But since the image data is in
memory, there can't seem to be a way to create the image object. Note that
I don't want to write the image data to a file.
Is there a way to bypass this problem ? Or is there an other graphic
manipulation lib that will allow to do this ?
Thanks,
Ben
------------------------------
Date: Sun, 25 Feb 2001 14:06:14 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Graphic file manipulation
Message-Id: <3A9981D6.55E9B6C7@stomp.stomp.tokyo>
Neb wrote:
(snippage)
> I have a script that reads from a database an image file content (.gif or
> .jpg) into a variable. What I want to do is to resize this image and send
> it back to the client browser (content-type: image/gif).
> I'm trying to use Image::Magick, but the problem....
> Is there a way to bypass this problem ?
Yes there is. Open your graphic image with a graphic
editor such as Paint Shop Pro or Photoshop, then
edit your image to be the size you want. Upload
your edited image to your server, problem resolved.
Many servers store two sizes of an image. One small,
the other, full size. A small one serves as a clickable
thumbnail leading to a larger version.
Editing your graphics to be the size you want, is more
logical than trying to resize an image on the fly.
It is equally logical to not send graphic data to a
browser via a script but rather print an auto-load link
and have a browser load it directly. Sending binary
data via a script is highly inefficient.
Godzilla!
------------------------------
Date: 26 Feb 2001 01:33:16 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Graphic file manipulation
Message-Id: <983150870.20527@itz.pp.sci.fi>
[Followups set to clpm. comp.lang.perl doesn't exist anyway.]
In article <97bodg$803$1@cti15.citenet.net>, Neb wrote:
>
>I'm trying to use Image::Magick, but the problem is that the Read method
>*needs* a FILEHANDLE to the image file. But since the image data is in
>memory, there can't seem to be a way to create the image object. Note that
>I don't want to write the image data to a file.
http://search.cpan.org/search?mode=module&query=IO%3A%3AString
No, I've no idea which of them is better, having used neither.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"However, what you are implying is *probably* anatomically impossible, if
not topologically." -- Simon Cozens in the monastery
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: 25 Feb 2001 23:38:01 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: perl newbie question
Message-Id: <slrn99j5pc.ev5.damian@puma.qimr.edu.au>
So said Bart Lateur on Sat, 24 Feb 2001 22:12:50 GMT:
>Matthias Reis wrote:
>
>>I'd like to include a perl file in another perl file. I tried that with
>>require "/path/file.pl", but the variables from "/path/file.pl" don't seem
>>to be in the scope of the main file.
>>...
>
>By using global variables. In oither words: any variables declared with
>"my" will NOT be visible from within any other files. So don't do that.
>
>You may have package related problems, but I doubt that. Anyway: if you
>want to access variables from another package, you have to fully qualify
>them, so that @foo in package Flintstone::Fred can be accessed from
>anywhere by using the name @Flintstone::Fred::foo.
>
Another option is to stash them all in a data structure suspended off one
hash reference, then return that hash reference. A little extra syntax for
deferencing the vars, but a much cleaner namespace...
Cheers,
Damian
--
#!/usr/bin/perl -w
use strict;$|=1;$:=79;for $; (split//,<DATA>){print" "x($:-$_),
$;,"\x"x600,"\b"x($:-$_+1)for 0..--$:;print$;}; __END__
Just another Perl Hacker
------------------------------
Date: 25 Feb 2001 19:19:42 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: PROPOSAL: Graphics::ColorNames
Message-Id: <97blse$e80$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Abigail
<abigail@foad.org>],
who wrote in article <slrn9936hg.594.abigail@tsathoggua.rlyeh.net>:
> || Aye! A few hundren color names for X-windows multipled by 3 elements in
> || an array? That's a lot.
>
> Even if you have 333 colour names, you end up with less than a thousand
> numbers. An SV holding an integer might be a couple of dozen bytes.
Well, there is all the associated data too. Things tend to multiply.
But even with this the overhead is not that bad (with 334 names and 3
floating point colors per name):
env PERL_DEBUG_MSTATS=2 perl -wle '$t = shift; $h{$_} = [$t+1,$t+2,$t+3]
for 0..333' 153
Name "main::h" used only once: possible typo at -e line 1.
Memory allocation statistics after compilation: (buckets 4(4)..8184(8192)
18060 free: 187 72 37 22 11 1 2 2 1 0 0
450 117 51 8 17
40632 used: 68 55 89 40 5 7 2 10 0 1 1
61 53 119 76 8
Total sbrk(): 60360/7:155. Odd ends: pad+heads+chain+tail: 968+700+0+0.
Memory allocation statistics after execution: (buckets 4(4)..8184(8192)
15232 free: 187 72 37 22 11 1 2 1 0 0 0
450 130 50 10 17
108404 used: 68 55 89 40 5 7 2 49 0 2 1
61 720 120 410 8
Total sbrk(): 127944/26:174. Odd ends: pad+heads+chain+tail: 968+1292+0+2048.
Note the difference in the size after compilation/execution: around
68K more is "used", which results in 67K more "allocated".
Ilya
------------------------------
Date: Sun, 25 Feb 2001 18:52:18 -0000
From: "len.green" <len.green@ntlworld.com>
Subject: Re: question about 'for' loop functionality
Message-Id: <kDcm6.25581$MN.628652@news2-win.server.ntlworld.com>
Hi
Can I ask what's wrong with doing it this way, what do you need to achieve
cos $count will hold the length of the array unless you exit the loop
early????
> $count = 1;
> foreach (@array){
> #some code with $_
> $count++;
> }
David <NOSPAM4MEdrh@engineer.com> wrote in message
news:igii9t0qbv7hvvnodc315vo4868uqff46v@4ax.com...
> Hello
>
> My apologies if this message appears more than once. I've been having
> problems with my isp's news server as of late.
>
>
> I have a question about 'for' loop functionality.
>
> I understand the following:
>
> for ($count=1 ; $count<10 ; $count++){
> #some code...
> } # no problem here
>
> And
>
> for (@array){
> #some code with $_
> } # now problem here either
>
>
> But what if I want to cycle through all elements of @array as well as
> initialize $count then auto increment it:
>
> for ($count=1 ; @array ; $count++){
> #some code...
> }
>
> This doesn't work. It just tests for existence of elements in @array
> creating an endless loop if @array holds anything.
>
> The following doesn't work either:
>
> for ($count=1 ; $element = @array ; $count++){
> #some code with $element ...
> }
>
> This sets $element with the number of elements in array.
>
> I've built the following kludge to do the trick but I'm sure there's a
> more eloquent way of doing this.
>
> $count = 1;
> foreach (@array){
> #some code with $_
> $count++;
> }
>
> Can anyone clue me in?
>
> Thanks,
> David.
------------------------------
Date: Sun, 25 Feb 2001 19:33:42 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: question about 'for' loop functionality
Message-Id: <q6dm6.1096$C5.49775@eagle.america.net>
On Sun, 25 Feb 2001 18:03:25 GMT, David <NOSPAM4MEdrh@engineer.com>
wrote:
>I have a question about 'for' loop functionality.
[snip]
>But what if I want to cycle through all elements of @array as well as
>initialize $count then auto increment it:
>
>for ($count=1 ; @array ; $count++){
> #some code...
>}
>
>This doesn't work. It just tests for existence of elements in @array
>creating an endless loop if @array holds anything.
Well, yes. If @array is non-empty, then scalar @array is non-zero
which is true. What did you expect?
>The following doesn't work either:
>
>for ($count=1 ; $element = @array ; $count++){
> #some code with $element ...
>}
>
>This sets $element with the number of elements in array.
Well, yes. That's what `$element = @array;' means! And, again, it
will evaluate to true, if @array is non-empty. So the test part of
the for() statement will forever be true, unless @array is modified in
the block. Again, what did you expect?
>I've built the following kludge to do the trick but I'm sure there's a
>more eloquent way of doing this.
>
>$count = 1;
>foreach (@array){
> #some code with $_
> $count++;
>}
I wouldn't call that a kludge. Maybe this qualifies as a kludge:
{
local($_);
for ($count = 1, $_ = $array[$count-1];
$count <= @array;
$count++, $_ = $array[$count-1])
{
#some code with $_
}
}
Yea, your solution is better.
--
Garry Williams
------------------------------
Date: Sun, 25 Feb 2001 17:11:05 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: question about 'for' loop functionality
Message-Id: <D969BAD65B506130.1B661FB9BED57BEE.EA28ADD90F985E1B@lp.airnews.net>
"Garry Williams" <garry@zvolve.com> wrote:
: On Sun, 25 Feb 2001 18:03:25 GMT, David wrote:
:
[SNIP]
:
: >I've built the following kludge to do the trick but I'm sure there's a
: >more eloquent way of doing this.
: >
: >$count = 1;
: >foreach (@array){
: > #some code with $_
: > $count++;
: >}
:
: I wouldn't call that a kludge. Maybe this qualifies as a kludge:
:
: {
: local($_);
: for ($count = 1, $_ = $array[$count-1];
: $count <= @array;
: $count++, $_ = $array[$count-1])
: {
: #some code with $_
: }
: }
:
: Yea, your solution is better.
$count is 1 + the array index. Since your trying to
step through each array item anyway:
foreach (0 .. $#array){
# some code with $array($_) and ($_ + 1)
}
Now each item is $array($_)
and each $count is ($_ + 1).
The for loop does the incrementing for you.
HTH,
Charles K. Clarkson
------------------------------
Date: Mon, 26 Feb 2001 10:37:58 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: question about 'for' loop functionality
Message-Id: <slrn99j5qm.gl1.mgjv@martien.heliotrope.home>
On Sun, 25 Feb 2001 18:03:25 GMT,
David <NOSPAM4MEdrh@engineer.com> wrote:
> Hello
>
> My apologies if this message appears more than once. I've been having
> problems with my isp's news server as of late.
>
>
> I have a question about 'for' loop functionality.
>
> I understand the following:
>
> for ($count=1 ; $count<10 ; $count++){
> #some code...
> } # no problem here
Normally, you'd see a loop going from 0 onwards, especially when you
want to work with arrays, since array indexes are 0 based.
for (my $count = 0; $count < @array; $count++)
{
# do something with $array[$count]
# $count + 1 gives you the 1-based index
}
If you find the 1 to n_elements counting more intuitive, then I first of
all suggest you get over it :). next I'd say, this is how you could do
that:
for (my $count = 0; $count <= @array; $count++)
{
# do something with $array[$count - 1]
}
> $count = 1;
> foreach (@array){
> #some code with $_
> $count++;
> }
Nothing wrong with that code, really.
Another way:
foreach my $count (1 .. @array)
{
# do something with $array[$count - 1]
}
You see why I mentioned that you probably should get used to the fact
that arrays in Perl are 0-based? you'll get terribly confused if you
keep basing your idea of an index on 1.
BTW, if all you want is the number of elements:
$count = @array;
or
$count = $#array + 1; # [1]
See perldata and perlsyn for more info.
Martien
[1] And as the standard disclaimer with this: Only if you haven't
meddled with $[
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: 25 Feb 2001 23:04:52 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: Question.about s///
Message-Id: <slrn99j3ru.gcr.ben-fuzzybear@Odin.Thor>
The ancient archives of 24 Feb 2001 18:36:46 GMT showed
Ilmari Karonen of comp.lang.perl.misc speaking thus:
>In article <slrn99ejk3.bu.ben-fuzzybear@Odin.Thor>, Ben Okopnik wrote:
>>
>>tr/[\302-\306]/o/;
>
>Why do you want to translate '[' and ']' to 'o'?
I just tried it out, and you're right: "tr" takes '[' and ']' as characters
to be converted rather than range enclosures (which I thought were
necessary there.) My mistake.
I also realized that I supplied incorrect values for the characters (that's
what you get when you try to do octal conversions in your head when you're
short on sleep...); the correct version would be
tr/\362-\366/o/;
Ben Okopnik
-=-=-=-=-=-
------------------------------
Date: Sun, 25 Feb 2001 21:56:00 -0000
From: "Chile" <abcd@ntlworld.com>
Subject: Quick Beginers question. about filling an array.
Message-Id: <UXem6.26275$MN.654576@news2-win.server.ntlworld.com>
Hi,
can someone please show me how the below code should look in perl. basically
i want to learn how to dynamically fill/declare an array.
#here i want to declare and array that can hold upto 200 entries
@array1[200];
#here i want to loop through 200 times and fill the array at position i with
the value of i then just to test print that array position out.
for ($i=0;$i<200;$i++){
@array1[i] = i;
print @array1[i];
}
Thanks
Scott
------------------------------
Date: Sun, 25 Feb 2001 22:38:25 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Quick Beginers question. about filling an array.
Message-Id: <3A998A62.4B3EBEC1@rochester.rr.com>
Chile wrote:
...
> can someone please show me how the below code should look in perl. basically
> i want to learn how to dynamically fill/declare an array.
>
> #here i want to declare and array that can hold upto 200 entries
> @array1[200];
Well, I assume you mean $array1[200]='value'; . If so, that would
create an array that has 201 entries. It is not necessary to predeclare
Perl arrays, and if you do, you normally wouldn't specify a size, as the
allocation of storage is fully automatic. A proper predeclaration would
be:
my @array1;
>
> #here i want to loop through 200 times and fill the array at position i with
> the value of i then just to test print that array position out.
>
> for ($i=0;$i<200;$i++){
> @array1[i] = i;
> print @array1[i];
> }
That would work fine with a couple of adjustments:
First, your assignment statement should be:
$array1[$i]=$i;
Using @array1[...] tells Perl it is expecting an array, not a scalar.
Since the value you are storing is a scalar, you should use a $. But it
works anyway, since a 1-element array and a scalar are somewhat similar.
Using a bareword for the variable is a huge mistake. Perl would have
informed you of this error if you had used the -w switch when you ran
Perl, as:
perl -w foo.pl
Perl would have provided you with detailed commentary about the errors
it reported if you would have used the diagnostics module, as:
perl -w -Mdiagnostics foo.pl
If you want a variable, you need to specify the type of variable you are
dealing with in front of the name: $ for scalar, @ for array, % for
hash, * for typeglob. A bareword is interpreted as a file handle or a
directory handle, at least in some locations. In your code, it doesn't
work. It looks like it is interpreted as if it were the string 'i',
which, in numeric context (for the subscript) is 0. Thus, your code
repeatedly stores the string i in $array1[0].
Second, the print statement should be:
print $array1[$i];
with the same commentary.
A more Perlish way of doing exactly the same thing (except that variable
$i isn't set) is:
print @array1=(0..199);
although that by itself will also generate a warning about variable
@array1 being used only once in the program.
...
> Scott
--
Bob Walton
------------------------------
Date: Sun, 25 Feb 2001 23:36:21 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Quick Beginers question. about filling an array.
Message-Id: <VFgm6.1133$C5.51588@eagle.america.net>
On Sun, 25 Feb 2001 21:56:00 -0000, Chile <abcd@ntlworld.com> wrote:
>can someone please show me how the below code should look in perl.
>basically i want to learn how to dynamically fill/declare an array.
>
>#here i want to declare and array that can hold upto 200 entries
>@array1[200];
Take a look at the perlsyn manual page. The first section discusses
declarations in Perl:
Declarations
The only things you need to declare in Perl are report
formats and subroutines--and even undefined subroutines can
be handled through AUTOLOAD. A variable holds the undefined
value (`undef') until it has been assigned a defined value,
which is anything other than `undef'.
That's not to say that you shouldn't declare a variable in Perl,
however. As a matter of fact, you should get used to telling Perl to
_require_ you to declare variables. Start your Perl programs with:
#!/usr/bin/perl -w
use strict;
Now you _must_ declare variables before using them.
For your question, to declare an array, simply do:
my @array;
You do not specify a size when declaring an array in Perl because
_all_ variables in Perl will grow as needed. This is very different
than C.
Now that you have declared that array, it will hold as many items as
your system's memory will allow!
>#here i want to loop through 200 times and fill the array at position
>i with the value of i then just to test print that array position
>out.
>
>for ($i=0;$i<200;$i++){
>@array1[i] = i;
>print @array1[i];
>}
What happened when you tried the snippet above? What did perl say
about it?
If you are not following my advice above as to the way to start _all_
of your Perl programs, you saw this:
$ perl
for ($i=0;$i<200;$i++){
@array1[i] = i;
print @array1[i];
}
__END__
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii$
(I supplied the line-wrapping to keep my lines under 80 characters in
length.)
I assume you were not expecting that.
But if you start your Perl programs differently, you will get a lot of
help from perl:
$ perl
#!/usr/bin/perl -w
use strict;
for ($i = 0; $i < 200; $i++) {
Global symbol "$i" requires explicit package name at - line 3.
Global symbol "$i" requires explicit package name at - line 3.
Global symbol "$i" requires explicit package name at - line 3.
@array1[i] = i;
Scalar value @array1[i] better written as $array1[i] at - line 4.
Global symbol "@array1" requires explicit package name at - line 4.
print @array1[i];
Scalar value @array1[i] better written as $array1[i] at - line 5.
Global symbol "@array1" requires explicit package name at - line 5.
}
__END__
Bareword "i" not allowed while "strict subs" in use at - line 4.
Bareword "i" not allowed while "strict subs" in use at - line 4.
Bareword "i" not allowed while "strict subs" in use at - line 5.
Execution of - aborted due to compilation errors.
$
Perl will let you know when you made a mistake if you ask.
Now let's correct that program and try again:
$ perl
#!/usr/bin/perl -w
use strict;
my @array; # declare our array
for (my $i = 0; $i < 200; $i++) { # declare $i scoped in the loop only
$array[$i] = $i;
print $array[$i];
}
__END__
0123456789101112131415161718192021222324252627282930
3132333435363738394041424344454647484950515253545556
5758596061626364656667686970717273747576777879808182
8384858687888990919293949596979899100101102103104105
106107108109110111112113114115116117118119120121122123
124125126127128129130131132133134135136137138139140141
142143144145146147148149150151152153154155156157158159
160161162163164165166167168169170171172173174175176177
178179180181182183184185186187188189190191192193194195
196197198199$
(I supplied the line-wrapping to keep my lines under 80 characters in
length.)
Which is what I think you expected.
Unlike C, you will rarely use the above form of the for statement.
Most of the time, you end up using this form instead:
foreach my $elt (@array) {
# do something with $elt
}
Or:
for (@array) {
# do something with $_
}
although these forms will not work to _initialize_ the array like you
asked to do. They are used to iterate over an already initialized
array. (See the rest of the perlsyn manual page.)
To store stuff in an array, you often just use push().
Now, go read the very fine manual that came with your copy of perl.
Start by reading the perl manual page. It will suggest the order in
which you should read other manual pages. (You may also want to pick
up a book on learning to program in Perl. Check the perl.com site for
some recommendations.)
--
Garry Williams
------------------------------
Date: Sun, 25 Feb 2001 23:07:02 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: regexp question
Message-Id: <3A999115.F3878E70@rochester.rr.com>
Michael Weaver wrote:
>
> I'm trying to write a regular expression to parse and HTML SELECT element
> and extract the values of each option.
...
> Thanks,
>
> Mike
HTML parsing is much more difficult than you think. My recommendation
is to bite the bullet right now and
use HTML::Parser;
or one of the other HTML parsing modules. If you consider all the
possibilities for your situation (one tag on multiple lines; multiple
tags on one line; HTML commentary that looks like your tag; stuff in the
ID tag string that looks like a value=; etc), I'm sure you will agree.
--
Bob Walton
------------------------------
Date: 25 Feb 2001 23:12:17 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: SMTP server
Message-Id: <slrn99j49r.gcr.ben-fuzzybear@Odin.Thor>
The ancient archives of 24 Feb 2001 05:49:03 GMT showed
The Mosquito ScriptKiddiot of comp.lang.perl.misc speaking thus:
>hey
>
>sorry if this mite sound off-topic, but i haven't been able to find a decent
>SMTP server...i've looked all over, meaning i've searched using search engines,
>and it's true that MANY so-called "valid" hits r returned...sites that
>literally contain lists of what they call "free" smtp servers, but when u try
>them, they're all fake...the ones that work say stuff like "relaying
>denied"....
>
>i did find one that accepted : chem.boisestate.edu
Great! Thanks for letting us know.
[ Sysadmin at chem.boisestate.edu notified of security hole ]
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Besides, its really not worthwhile to use more than two times your physical
ram in swap (except in a select few situations). The performance of the
system becomes so abysmal you'd rather heat pins under your toenails while
reciting Windows95 source code and staring at porn flicks of Bob Dole than
actually try to type something. -- Seen on c.o.l.development.system
------------------------------
Date: 26 Feb 2001 01:31:12 GMT
From: anotherway83@aol.com (The Mosquito ScriptKiddiot)
Subject: Re: SMTP server
Message-Id: <20010225203112.03254.00003342@ng-cg1.aol.com>
>Sysadmin at chem.boisestate.edu notified of security hole
hahaha now thats funny...
peace
The Mosquito ScriptKiddiot
Championing the Cause of Mosquitoes in Technology
------------------------------
Date: Mon, 26 Feb 2001 10:19:24 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: splice question
Message-Id: <slrn99j4ns.gl1.mgjv@martien.heliotrope.home>
On Sun, 25 Feb 2001 16:41:22 GMT,
Joseph Pepin <jdpepin@optonline.net> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn99h1d3.pen.mgjv@martien.heliotrope.home...
>>
>> Looks like it might be worth a bug report. I am not saying that I would
>> expect Perl to behave either way, although it should probably behave as
>> you expect. But there being a difference in the way these two work is
>> not acceptable.
>>
>> If you don't know how to submit a bug report, let me know, and I'll
>> prepare one.
>
> Martien, why don't you submit a bug report. I'd probably mess it up. Do you
> suppose this is crazy enough to rate a "Yikes!" ?
I will, as soon as I can get in touch with one of the maintainers of
the perlbug mail address. For some reason they seem to think that my ISP
is a spam haven, so I can't submit anything, and there's no alternative
interface.
It really is a bit ridiculous to have a bug reporting addres shielded
off by these fascist spam blockers.
Martien
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 354
**************************************