[23821] in Perl-Users-Digest
Perl-Users Digest, Issue: 6024 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 21:01:33 2004
Date: Thu, 29 Jan 2004 17:55:57 -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 Thu, 29 Jan 2004 Volume: 10 Number: 6024
Today's topics:
Need Help <pin@purdue.edu>
Re: Need Help <me@verizon.invalid>
Re: Need Help <noreply@gunnar.cc>
Re: Need Help <gnari@simnet.is>
Re: Need Help <tadmc@augustmail.com>
Need to extract text between two HTML comments (mmk16)
Re: Need to extract text between two HTML comments <noreply@gunnar.cc>
Re: Need to extract text between two HTML comments <tadmc@augustmail.com>
Re: Need to extract text between two HTML comments <tadmc@augustmail.com>
Re: Need to extract text between two HTML comments <uri@stemsystems.com>
Re: Need to extract text between two HTML comments (mmk16)
Re: Need to extract text between two HTML comments <tore@aursand.no>
Re: Need to extract text between two HTML comments <richard@zync.co.uk>
Net::SCP::Expect not taking auto_yes method (John Call)
newbie help with some help needed with a data array <dlaw001@yahoonospam.co.uk>
Re: newbie help with some help needed with a data array <invalid-email@rochester.rr.com>
Re: newbie help with some help needed with a data array <matthew.garrish@sympatico.ca>
Re: newbie help with some help needed with a data array <matthew.garrish@sympatico.ca>
Re: newbie help with some help needed with a data array <tadmc@augustmail.com>
Re: newbie help with some help needed with a data array (Sam Holden)
Re: newbie help with some help needed with a data array <1usa@llenroc.ude>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Jan 2004 10:55:13 -0500
From: "TP" <pin@purdue.edu>
Subject: Need Help
Message-Id: <bv0ot6$nu6$1@mozo.cc.purdue.edu>
Hi
i have this lines in my html file.. and what it mainly do is list all the
entry in my database...
<form method="listall" action="samp40.cgi">
<input type="submit" value="List All Movies"> </center></form>
what code should i write in my cgi file ... so that when i click on "list
all Movies" it will read the database on my file and print to the
screen!!!!!
thanks
------------------------------
Date: Sun, 25 Jan 2004 16:26:46 GMT
From: "dw" <me@verizon.invalid>
Subject: Re: Need Help
Message-Id: <a7SQb.8296$KU5.4002@nwrddc02.gnilink.net>
"TP" <pin@purdue.edu> wrote in message
news:bv0ot6$nu6$1@mozo.cc.purdue.edu...
>
> <form method="listall" action="samp40.cgi">
> <input type="submit" value="List All Movies"> </center></form>
>
> what code should i write in my cgi file ... so that when i click on "list
> all Movies" it will read the database on my file and print to the
> screen!!!!!
>
what have you tried? what kind of output do you want? what kind of database
do you have?
coming from a DBI source going to html output using CGI.pm:
print $q->Tr($q->td([@row]) while @row = $sth->fetchrow_array;
------------------------------
Date: Sun, 25 Jan 2004 17:22:00 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need Help
Message-Id: <bv0qq4$mg2oc$1@ID-184292.news.uni-berlin.de>
TP wrote:
> what code should i write in my cgi file ... so that when i click on
> "list all Movies" it will read the database on my file and print to
> the screen!!!!!
What have you tried?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 25 Jan 2004 16:14:55 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Need Help
Message-Id: <bv0q7h$7db$1@news.simnet.is>
"TP" <pin@purdue.edu> wrote in message
news:bv0ot6$nu6$1@mozo.cc.purdue.edu...
> Hi
> i have this lines in my html file.. and what it mainly do is list all the
> entry in my database...
>
> <form method="listall" action="samp40.cgi">
> <input type="submit" value="List All Movies"> </center></form>
>
> what code should i write in my cgi file ... so that when i click on "list
> all Movies" it will read the database on my file and print to the
> screen!!!!!
a) you need some way to read the form parameters, (although in this
case there are none to speak of). for this use the CGI module
perldoc CGI
b) you need to read your database info
perdoc -f open
c) then you need to send the results to the browser. (note:
you write 'to the screen in your question, but you mean the browser)
you should print out some HTML with the data in it
perldoc -f print
tell us if you have any problems, we are here to help you.
gnari
------------------------------
Date: Sun, 25 Jan 2004 11:32:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need Help
Message-Id: <slrnc17ve1.l7p.tadmc@magna.augustmail.com>
TP <pin@purdue.edu> wrote:
> Subject: Need Help
Need Subject!
Please put the subject of your article in the Subject of your article.
Have you seen the Posting Guidelines that are posted here frequently?
> what code should i write in my cgi file
Have you seen what the Perl FAQ has to say about writing CGI programs?
perldoc -q CGI
Where can I learn about CGI or Web programming in Perl?
What is the correct form of response from a CGI script?
My CGI script runs from the command line but not the browser. (500
Server Error)
How can I get better error messages from a CGI program?
How do I make sure users can't enter values into a form that cause my
CGI script to do bad things?
How do I decode a CGI form?
Have you seen what the Perl FAQ has to say about databases and Perl?
perldoc -q database
How do I use an SQL database?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Jan 2004 19:25:10 -0800
From: mmk16@rediffmail.com (mmk16)
Subject: Need to extract text between two HTML comments
Message-Id: <109192.0401211925.7352e74f@posting.google.com>
I need to extract all text in a HTML page between two patterns like
<!-- cachedResultsStart --> and <!-- cachedResultsEnd -->.
I am trying something like
my $start_tag = '<!-- cachedResultsStart -->';
my $end_tag = '<!-- cachedResultsEnd -->';
my $num_lines = /$start_tag/ .. /$end_tag/ ;
if ($num_lines ) {
/$start_tag(.+?)$end_tag/m ;
$this_is_what_i_need = $1 ;
}
print $this_is_what_id_need ;
I used this approach from an earlier posting by Uri Guttman
However, this is not working for me.
------------------------------
Date: Thu, 22 Jan 2004 04:29:10 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need to extract text between two HTML comments
Message-Id: <bung5n$ivjq5$1@ID-184292.news.uni-berlin.de>
mmk16 wrote:
> I need to extract all text in a HTML page between two patterns like
> <!-- cachedResultsStart --> and <!-- cachedResultsEnd -->.
>
> I am trying something like
--------------^^^^^^^^^^^^^^
Okay. Would you mind letting us know what you are actually trying?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 21 Jan 2004 23:09:30 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need to extract text between two HTML comments
Message-Id: <slrnc0umoa.8o0.tadmc@magna.augustmail.com>
mmk16 <mmk16@rediffmail.com> wrote:
> $this_is_what_i_need = $1 ;
> print $this_is_what_id_need ;
One of these things is not like the other, one of these things
just isn't the same...
Imagine all the time you would have saved if you had "use strict"
turned on. It would have found that problem right away.
Imagine all the time you would have saved _us_ if you had asked
for a machine's help *before* asking thousands of people for help.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Jan 2004 23:11:03 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need to extract text between two HTML comments
Message-Id: <slrnc0umr7.8o0.tadmc@magna.augustmail.com>
mmk16 <mmk16@rediffmail.com> wrote:
> /$start_tag(.+?)$end_tag/m ;
The "m" modifier is a no-op there. It does nothing.
Perhaps you meant //s instead?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 22 Jan 2004 05:58:26 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need to extract text between two HTML comments
Message-Id: <x71xpsa5j2.fsf@mail.sysarch.com>
>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:
TM> mmk16 <mmk16@rediffmail.com> wrote:
>> $this_is_what_i_need = $1 ;
>> print $this_is_what_id_need ;
TM> One of these things is not like the other, one of these things
TM> just isn't the same...
and he is blaming ME for inspiring him. i tend to strictness and win all
my variable spelling bees.
TM> Imagine all the time you would have saved _us_ if you had asked
TM> for a machine's help *before* asking thousands of people for help.
i ask for help from my machine all the time but it still can't tell me
the picks for the next powerball drawing.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 21 Jan 2004 22:08:16 -0800
From: mmk16@rediffmail.com (mmk16)
Subject: Re: Need to extract text between two HTML comments
Message-Id: <109192.0401212208.1d2e508@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<bung5n$ivjq5$1@ID-184292.news.uni-berlin.de>...
> mmk16 wrote:
> > I need to extract all text in a HTML page between two patterns like
> > <!-- cachedResultsStart --> and <!-- cachedResultsEnd -->.
> >
> > I am trying something like
> --------------^^^^^^^^^^^^^^
>
> Okay. Would you mind letting us know what you are actually trying?
Between <!-- cachedResultsStart --> and <!-- cachedResultsEnd -->
the html page will contain a HTML table with data that I am
interested in. I wish to further process this using HTML::TableExtract
------------------------------
Date: Thu, 22 Jan 2004 10:25:44 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Need to extract text between two HTML comments
Message-Id: <pan.2004.01.22.09.24.16.191929@aursand.no>
On Wed, 21 Jan 2004 19:25:10 -0800, mmk16 wrote:
> I need to extract all text in a HTML page between two patterns like
> <!-- cachedResultsStart --> and <!-- cachedResultsEnd -->.
Working with HTML can be some scary rocket science, but here goes:
my $start = '<!-- cachedResultsStart -->';
my $end = '<!-- cachedResultsEnd -->';
if ( $html =~ m,$start(.*)$end,g ) {
print $1;
}
No need to know how many lines or anything like that. Just grab what you
need.
Problems arise, however, if the HTML code contains more than one occurance
of the expression above. That's when you should consider doing a while()
to match all of them.
--
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
4 will be fought with sticks and stones." -- Albert Einstein
------------------------------
Date: Thu, 22 Jan 2004 11:45:13 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Need to extract text between two HTML comments
Message-Id: <buod4c$vkb$1@news.freedom2surf.net>
In article <109192.0401211925.7352e74f@posting.google.com>, "mmk16"
<mmk16@rediffmail.com> wrote:
> I need to extract all text in a HTML page between two patterns like <!--
> cachedResultsStart --> and <!-- cachedResultsEnd -->. I am trying
> something like
> my $start_tag = '<!-- cachedResultsStart -->'; my $end_tag = '<!--
> cachedResultsEnd -->'; my $num_lines = /$start_tag/ .. /$end_tag/ ;
> if ($num_lines ) {
> /$start_tag(.+?)$end_tag/m ;
> $this_is_what_i_need = $1 ;
>
> }
> print $this_is_what_id_need ;
> I used this approach from an earlier posting by Uri Guttman However,
> this is not working for me.
May I suggest using the HTML::Parser module, specifically the
HTML::PullParser which will easily allow you to get what you want
R
------------------------------
Date: 28 Jan 2004 18:09:35 -0800
From: jcall@gilmerschools.com (John Call)
Subject: Net::SCP::Expect not taking auto_yes method
Message-Id: <8ebb64a.0401281809.7e88c283@posting.google.com>
I am using Net::SCP::Expect for secure copy from a program. I have set
the auto_yes method to answer any connecting questions:
--------
my $scpe = Net::SCP::Expect->new(auto_yes => '1');
--------
I've also tried the '1' outside quotes. I still get the following:
---------
Are you sure you want to continue connecting (yes/no)? at
/storage/mu/etc_defaults.pl line 500
---------
Any ideas about why I would still be getting this?
thanks,
John
------------------------------
Date: Sun, 25 Jan 2004 00:17:57 -0000
From: "LeTubs" <dlaw001@yahoonospam.co.uk>
Subject: newbie help with some help needed with a data array
Message-Id: <k_DQb.28328$OA3.8886102@newsfep2-win.server.ntli.net>
Hi
What I'm trying do is to have a record structure and then create an array
of those structures and then being able to access those structures via
for loop..... sounds simple, well unfortunately I want do this in perl and
being sort of new to it I'm sort of coming stuck( or continuing to think in
C ). I have written a simple little test program that I'm seeing whats is
going on and trying to figure whats going wrong, and would a appreciate
some expert advice !
Thanks
David
#!/usr/bin/perl
use Class::Struct;
#create a simple record structure
struct Wibble =>{
name => '$',
w => '$',
};
#create a blank array for storage....
@some_array = ();
# create the new member
my $p = Wibble->new();
$p->name("David");
$p->w("w");
# store the new member ( is this correct way to do this ? )
push( @some_array, $p );
# create another member.....
my $p = Wibble->new();
$p->name("William");
$p->w("x");
# store it again
push( @some_array, $p );
#now print out the results....
for( $i = 0; $i < @some_array; $i++ ){
print " $i : $some_array[$i].name, $some_array[$i].w";
}
# Ideal Ouput
1 : Davidw
2 : Williamx
------------------------------
Date: Sun, 25 Jan 2004 01:27:12 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: newbie help with some help needed with a data array
Message-Id: <40131B6A.2020604@rochester.rr.com>
LeTubs wrote:
...
> What I'm trying do is to have a record structure and then create an array
> of those structures and then being able to access those structures via
> for loop..... sounds simple, well unfortunately I want do this in perl and
> being sort of new to it I'm sort of coming stuck( or continuing to think in
> C ). I have written a simple little test program that I'm seeing whats is
> going on and trying to figure whats going wrong, and would a appreciate
> some expert advice !
...
> David
>
> #!/usr/bin/perl
use strict; #always during development
use warnings; #always during development -- let Perl help you
> use Class::Struct;
>
> #create a simple record structure
> struct Wibble =>{
> name => '$',
> w => '$',
> };
>
> #create a blank array for storage....
> @some_array = ();
my^
>
> # create the new member
> my $p = Wibble->new();
> $p->name("David");
> $p->w("w");
>
> # store the new member ( is this correct way to do this ? )
> push( @some_array, $p );
>
> # create another member.....
> my $p = Wibble->new();
---^^---delete this my, as it is a duplicate in this scope
> $p->name("William");
> $p->w("x");
>
> # store it again
> push( @some_array, $p );
>
> #now print out the results....
> for( $i = 0; $i < @some_array; $i++ ){
That is a very C-ish for loop. In Perl, it would be better written as:
for(@some_array){
> print " $i : $some_array[$i].name, $some_array[$i].w";
huh?------^----------------------^^^^^-----------------^^^
The syntax would be $some_array[$i]->name, plus you put it in the middle
of a "-quoted string, which means that interpolation, not evaluation, is
performed, which means the -> wouldn't be executed, but rather
substituted. And you forgot to print a newline. See below for a
modified version of your program which works.
Note that you can:
use Data::Dumper;
to print out things like @some_array -- it will show you exactly what
you have with no fuss, and then you can go from there.
> }
>
> # Ideal Ouput
> 1 : Davidw
> 2 : Williamx
#!/usr/bin/perl
use strict;
use warnings; #let Perl help you!!!
use Class::Struct;
#create a simple record structure
struct Wibble =>{
name => '$',
w => '$',
};
#create a blank array for storage....
my @some_array = ();
# create the new member
my $p = Wibble->new();
$p->name("David");
$p->w("w");
# store the new member ( is this correct way to do this ? )
push( @some_array, $p );
# create another member.....
$p = Wibble->new();
$p->name("William");
$p->w("x");
# store it again
push( @some_array, $p );
#now print out the results....
my $i=0;
for(@some_array){
print ++$i.": ".$_->name.", ".$_->w."\n";
}
HTH.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sat, 24 Jan 2004 20:52:26 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: newbie help with some help needed with a data array
Message-Id: <qjFQb.21871$U77.2148207@news20.bellglobal.com>
"LeTubs" <dlaw001@yahoonospam.co.uk> wrote in message
news:k_DQb.28328$OA3.8886102@newsfep2-win.server.ntli.net...
> Hi
> What I'm trying do is to have a record structure and then create an array
> of those structures and then being able to access those structures via
> for loop..... sounds simple, well unfortunately I want do this in perl and
> being sort of new to it I'm sort of coming stuck( or continuing to think
in
> C ). I have written a simple little test program that I'm seeing whats is
> going on and trying to figure whats going wrong, and would a appreciate
> some expert advice !
>
I'll start by saying that you should really go back to the documentation for
Class::Struct and take another look at the examples at the top. No point in
guessing when it's all laid out for you there.
>
> #!/usr/bin/perl
> use Class::Struct;
>
use strict;
use warnings;
> #create a simple record structure
> struct Wibble =>{
> name => '$',
> w => '$',
> };
>
That's not how to create a new structure. As per the module documentation,
it should be:
struct ( Wibble => [
name => '$',
w => '$' ] );
> #create a blank array for storage....
> @some_array = ();
>
Better written as:
my @some_array;
> # create the new member
> my $p = Wibble->new();
> $p->name("David");
> $p->w("w");
>
> # store the new member ( is this correct way to do this ? )
> push( @some_array, $p );
>
Think pointers. You want to create an array of references to the struct:
push @some_array, \$p;
> # create another member.....
> my $p = Wibble->new();
> $p->name("William");
> $p->w("x");
>
If you want to reuse $p, undef it. Redeclaring the variable will cause an
error under strictures and warnings.
> # store it again
> push( @some_array, $p );
>
> #now print out the results....
> for( $i = 0; $i < @some_array; $i++ ){
> print " $i : $some_array[$i].name, $some_array[$i].w";
> }
>
Ugly C-style loops make my head hurt... : )
for my $i (0..$#some_array) {
print "$i : " . ${$some_array[$i]}->name . ' ' . ${$some_array[$i]}->w .
"\n";
}
To access the values above, you need to dereference the hash ref you stored
in the array (${$some_array[$i]}). I'll post a complete working script
below.
Matt
use strict;
use warnings;
use Class::Struct;
struct ( Wibble => [
name => '$',
w => '$' ] );
my @some_array;
my $p = Wibble->new();
$p->name('David');
$p->w('w');
push @some_array, \$p;
my $q = new Wibble;
$q->name('William');
$q->w('x');
push @some_array, \$q;
for my $i (0..$#some_array) {
print "$i : " . ${$some_array[$i]}->name . ' ' . ${$some_array[$i]}->w .
"\n";
}
------------------------------
Date: Sat, 24 Jan 2004 21:01:29 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: newbie help with some help needed with a data array
Message-Id: <VrFQb.21888$U77.2149353@news20.bellglobal.com>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:qjFQb.21871$U77.2148207@news20.bellglobal.com...
>
> "LeTubs" <dlaw001@yahoonospam.co.uk> wrote in message
> news:k_DQb.28328$OA3.8886102@newsfep2-win.server.ntli.net...
>
> > #create a simple record structure
> > struct Wibble =>{
> > name => '$',
> > w => '$',
> > };
> >
>
> That's not how to create a new structure. As per the module documentation,
> it should be:
>
> struct ( Wibble => [
> name => '$',
> w => '$' ] );
>
Sheesh, this was not one of my better posts... : (
I think I thunk I saw an = instead of =>
>
> Think pointers. You want to create an array of references to the struct:
>
Or you can just push the struct right onto the array and avoid dereferencing
it later. I really wasn't looking at the bigger picture when I wrote this
(you got me thinking in C...).
Matt
------------------------------
Date: Sat, 24 Jan 2004 21:13:31 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: newbie help with some help needed with a data array
Message-Id: <slrnc16d2r.5go.tadmc@magna.augustmail.com>
Bob Walton <invalid-email@rochester.rr.com> wrote:
> LeTubs wrote:
>> for( $i = 0; $i < @some_array; $i++ ){
>
>
> That is a very C-ish for loop. In Perl, it would be better written as:
>
> for(@some_array){
That does not do the same thing.
The first loops over the indexes of @some_array.
The second loops over the _values_ of @some_array.
So, in Perl, it would be better written as:
for my $i ( 0 .. $#some_array ) {
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 25 Jan 2004 01:39:29 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: newbie help with some help needed with a data array
Message-Id: <slrnc167ih.r44.sholden@flexal.cs.usyd.edu.au>
On Sun, 25 Jan 2004 01:27:12 GMT,
Bob Walton <invalid-email@rochester.rr.com> wrote:
> LeTubs wrote:
>
> ...
>> What I'm trying do is to have a record structure and then create an array
>> of those structures and then being able to access those structures via
>> for loop..... sounds simple, well unfortunately I want do this in perl and
>> being sort of new to it I'm sort of coming stuck( or continuing to think in
>> C ). I have written a simple little test program that I'm seeing whats is
>> going on and trying to figure whats going wrong, and would a appreciate
>> some expert advice !
> ...
>
>
>> David
>>
>> #!/usr/bin/perl
>
> use strict; #always during development
Always full stop.
> use warnings; #always during development -- let Perl help you
Disabling warnings after development is reasonable - though I
don't bother... Some users might be scared of the messages it
may produce due to thing slike unexpected input.
>> #now print out the results....
>> for( $i = 0; $i < @some_array; $i++ ){
>
>
> That is a very C-ish for loop. In Perl, it would be better written as:
>
> for(@some_array){
Since $i is used in the loop body, how do you propose to produce
the same results with that?
for my $i (0...$#some_array) {
Would be the "more perlish" equivalent.
> #now print out the results....
> my $i=0;
> for(@some_array){
> print ++$i.": ".$_->name.", ".$_->w."\n";
> }
Oh, that's how you propose to do it. You've successfully
introduced an extra variable whose scope it greater than
the scope of the loop. I'd prefer the C style code to that,
and I'd prefer the ... style I showed above to that.
(Of course that variable existed in the original as well, but it
could have its scope reduced via my easily enough.)
--
Sam Holden
------------------------------
Date: 25 Jan 2004 01:48:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: newbie help with some help needed with a data array
Message-Id: <Xns947AD3BF0E30Aasu1cornelledu@132.236.56.8>
"LeTubs" <dlaw001@yahoonospam.co.uk> wrote in
news:k_DQb.28328$OA3.8886102@newsfep2-win.server.ntli.net:
> Hi
> What I'm trying do is to have a record structure and then create an
> array of those structures and then being able to access those
> structures via for loop..... sounds simple, well unfortunately I want
> do this in perl and being sort of new to it I'm sort of coming stuck(
> or continuing to think in C ). I have written a simple little test
> program that I'm seeing whats is going on and trying to figure whats
> going wrong, and would a appreciate some expert advice !
...
> #!/usr/bin/perl
You are missing:
use strict;
use warnings;
Those lines would have helped you see, among other things:
"my" variable $p masks earlier declaration in same scope at C:\Home\t.pl
line 26.
> use Class::Struct;
>
> #create a simple record structure
> struct Wibble =>{
> name => '$',
> w => '$',
> };
>
> #create a blank array for storage....
> @some_array = ();
This is not really necessary.
> #now print out the results....
> for( $i = 0; $i < @some_array; $i++ ){
> print " $i : $some_array[$i].name, $some_array[$i].w";
> }
>
> # Ideal Ouput
> 1 : Davidw
> 2 : Williamx
I do not see any way the loop above could produce that output for many
reasons such as the fact that $i only takes on the values 0 and 1. Also,
you have a comma and a space between the two fields in the print statement.
I have made a few modifications to your script. See below:
#! /usr/bin/perl
use strict;
use warnings;
use Class::Struct;
struct Wibble => {
name => '$',
w => '$',
};
my @some_array;
push @some_array,
Wibble->new(name => 'David', w => 'w'),
Wibble->new(name => 'William', w => 'x');
# Do you really need to display the index?
for (@some_array) {
print $_->name, ' ', $_->w, "\n";
}
# if so, you can use this:
for (0 .. $#some_array) {
print "$_ :", $some_array[$_]->name, ' ', $some_array[$_]->w, "\n";
}
__END__
Sinan
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
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 V10 Issue 6024
***************************************