[17930] in Perl-Users-Digest
Perl-Users Digest, Issue: 90 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 18 14:08:17 2001
Date: Thu, 18 Jan 2001 11:05:16 -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: <979844715-v10-i90@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 18 Jan 2001 Volume: 10 Number: 90
Today's topics:
Re: Can anyone give a quote on Perl/CGI Programming? <hazel.robinson@virgin.net>
Re: change STDIN and $/="" script to use (Richard J. Rauenzahn)
Re: Command line switch (-s) <ccx138@coventry.ac.uk>
Re: Command line switch (-s) (Tad McClellan)
Re: Converting single quoted string to double quoted st (Rafael Garcia-Suarez)
Re: Converting single quoted string to double quoted st <davidwaters@bigfoot.com>
Re: Converting single quoted string to double quoted st mike_solomon@lineone.net
Re: Converting single quoted string to double quoted st <Peter.Dintelmann@dresdner-bank.com>
Re: Converting single quoted string to double quoted st (Tad McClellan)
Re: Eval scoping problem? nobull@mail.com
Re: File::Find wont traverse CDROM !? nobull@mail.com
Re: Forwarding NT Event Log to Syslog <jack.haberle@bigfoot.com>
Re: HELP!! : Bi-Directional TCP Perl Sockets nobull@mail.com
HELP: httpS protocol (https and NOT http)! <fedebari@supereva.it>
Re: How can I extract strings from a Perl program? <kstep@pepsdesign.com>
How to determine current array element during a for loo <xchris.rogers@xvifanusa.com>
Re: How to determine current array element during a for <ccx138@coventry.ac.uk>
Re: How to determine current array element during a for <kstep@pepsdesign.com>
Re: How to determine current array element during a for <tony_curtis32@yahoo.com>
Re: How to determine current array element during a for <ren.maddox@tivoli.com>
Re: How to determine current array element during a for <xchris.rogers@xvifanusa.com>
Re: How to determine current array element during a for <xchris.rogers@xvifanusa.com>
Re: How to determine current array element during a for (Tad McClellan)
interesting regex? <davidwaters@bigfoot.com>
Re: interesting regex? nobull@mail.com
Re: interesting regex? (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Jan 2001 18:07:30 -0000
From: "Hazel Robinson" <hazel.robinson@virgin.net>
Subject: Re: Can anyone give a quote on Perl/CGI Programming?
Message-Id: <TkG96.7888$3N1.160675@news2-win.server.ntlworld.com>
Don
Forgive me for using a reply to your message to get into the newsgroup -
I'm a bit new to IE as I previously had Lotus Notes.
I 'm busy on a project right now for a client
| This client is a recruitment agency and they require a feedback form and a
| "search" facility on their web site - the search facility that has
impressed
| this client is visible on the site
|
| www.jhint.com
|
| Please see their "opportunities" page.
| Please could you tell me if you would be prepared to quote on the CGI
| required for the form and the PERL for the search facility? I could
download
| the free code from such as Bravenet.com but the client is an
| professional recruitment specialist and does not want
| advertisements to show. I have advised him that this will cost money and
he
| is OK with it.
|
.
| Please let me know
| Best regards
| Hazel
|
|
| ----- SNIP -----
------------------------------
Date: 18 Jan 2001 18:23:33 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: change STDIN and $/="" script to use
Message-Id: <979842213.21961@hpvablab.cup.hp.com>
nospam@hairball.cup.hp.com (Richard J. Rauenzahn) writes:
>Then don't do it in paragraph chunks. The idiom I've used is...
>
>$/ = "\nFrom ";
>
>while(<DATA>) {
> chomp;
> $_ = "From " . $_ unless(/^From /s);
> print ">>>>$_<<<<\n";
>}
I forgot a caveat -- this assumes your mail delivery agent escape's
/^From / within the body of the message.
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Thu, 18 Jan 2001 17:02:26 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: Command line switch (-s)
Message-Id: <3A6721A2.48BD4016@coventry.ac.uk>
It worked after I used
use var qw/$camel/;
but
use var $camel;
did not.
The perl I'm using is version 5.004_04 built for alpha-dec_osf
Tad McClellan wrote:
> John Tutchings <ccx138@coventry.ac.uk> wrote:
> >.
> >The use vars $camel and the our $camel did not work,
>
> Then you have a broken perl installation!
>
> (or you have used them incorrectly)
>
> Show us your "use vars" code that does not work (after reading
> the output from typing: perldoc vars ).
>
> >Anno Siegel wrote:
> >
> >> John Tutchings <ccx138@coventry.ac.uk> wrote in comp.lang.perl.misc:
> >> >Does anyone know of problems passing in command line switches and using
> >> >"use strict".
>
> >> > #!/usr/bin/perl -s
>
> >> > my($camel);
> >> > if ($camel){print "How many humps\n";}
>
> [snip]
>
> >> To get the expected behavior under strict, you must declare the
> >> package variable, (with "use vars $camel" in older Perls, alternatively
> >> "our $camel" in newer ones), or use the fully qualified "$main::camel".
>
> Those must _all_ (except our() in pre-5.6 perls) work.
>
> If they are not working, then you have found a bug in perl (not
> too likely). Show us your code and we will help you fix it.
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Thu, 18 Jan 2001 18:46:50 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Command line switch (-s)
Message-Id: <slrn96e69v.58t.tadmc@tadmc26.august.net>
John Tutchings <ccx138@coventry.ac.uk> wrote:
>It worked after I used
> use var qw/$camel/;
That is a correct syntax.
>but
> use var $camel;
>did not.
That is not correct syntax.
Perl can't know what you said if you don't say it correctly :-)
[ snip backwards-time quotation of an entire article including
.sig. Please learn how to followup on Usenet.
]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 18 Jan 2001 16:15:56 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Converting single quoted string to double quoted string
Message-Id: <slrn96e5mi.md5.rgarciasuarez@rafael.kazibao.net>
pricesteve wrote in comp.lang.perl.misc:
> I have a variable
> $fred = 'Two lines\nof text';
> returned from a T-SQL query using DBI::ODBC
> I need to print this as if it was double quoted
> ie $fred="two lines\nof text";
> print $fred; #prints without expanding the \n
> print "$fred"; #prints without expanding the \n
>
> any suggestions as to how to convert this single quoted string as returned
> by my
> SELECT statement into a double quoted string that will allow \n and
> $varnames to be interpolated??
It's possible to force interpolation by using eval(); but this will also
interpolate the $xxx variables, etc. This is a security risk.
In your case, I suggest to use a substitution :
$fred =~ s/\\n/\n/g;
You may need to substitute also '\t'.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
If they can get you asking the wrong questions, they don't have to worry
about the answers.
-- Thomas Pynchon, Gravity's Rainbow
------------------------------
Date: Thu, 18 Jan 2001 16:31:04 GMT
From: David Waters <davidwaters@bigfoot.com>
Subject: Re: Converting single quoted string to double quoted string
Message-Id: <9475o8$c6q$1@nnrp1.deja.com>
$fred = 'Two lines\nof text';
How about,
$fred =~ s/\'/\"/;
David
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 18 Jan 2001 16:38:10 GMT
From: mike_solomon@lineone.net
Subject: Re: Converting single quoted string to double quoted string
Message-Id: <94765h$ckd$1@nnrp1.deja.com>
In article <mpE96.1394$jr.10928@news2-hme0>,
"pricesteve" <pricesteve@yahoo.com> wrote:
> I have a variable
> $fred = 'Two lines\nof text';
> returned from a T-SQL query using DBI::ODBC
> I need to print this as if it was double quoted
> ie $fred="two lines\nof text";
> print $fred; #prints without expanding the \n
> print "$fred"; #prints without expanding the \n
>
> any suggestions as to how to convert this single quoted string as
returned
> by my
> SELECT statement into a double quoted string that will allow \n and
> $varnames to be interpolated??
>
> Regards
>
>
this should do what you want
$fred =~ s/\\n/\n/g;
Regards
Mike Solomon
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 18 Jan 2001 17:47:04 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: Converting single quoted string to double quoted string
Message-Id: <9476mo$7qf5@intranews.bank.dresdner.net>
Hi,
"pricesteve" <pricesteve@yahoo.com> wrote in message
news:mpE96.1394$jr.10928@news2-hme0...
> I have a variable
> $fred = 'Two lines\nof text';
> returned from a T-SQL query using DBI::ODBC
> I need to print this as if it was double quoted
> ie $fred="two lines\nof text";
> print $fred; #prints without expanding the \n
> print "$fred"; #prints without expanding the \n
I once copied the following code snippet from a posting
of Larry Rosler to my tipps&tricks file:
my $escapes = 'befnrt';
my %escapes = map { $_, eval "qq(\\$_)" } split // => $escapes;
$_ = 'abc\ndef\tghi\zjkl\n';
s/\\([$escapes])/$escapes{$1}/go;
print;
(thanks Larry!)
Regards,
Peter Dintelmann
------------------------------
Date: Thu, 18 Jan 2001 18:46:52 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Converting single quoted string to double quoted string
Message-Id: <slrn96e75e.58t.tadmc@tadmc26.august.net>
David Waters <davidwaters@bigfoot.com> wrote:
>$fred = 'Two lines\nof text';
^^^^^^^^^
Errr, even if that was double quotish it wouldn't be 2 lines.
$fred = 'Two lines\nof text\n';
_that_ would become 2 lines...
>How about,
>
>$fred =~ s/\'/\"/;
That does not work (and you don't need either of the backslashes either).
The OP wants a newline in the string, your suggestion does not
get a newline into the string.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Jan 2001 18:03:04 +0000
From: nobull@mail.com
Subject: Re: Eval scoping problem?
Message-Id: <u966jcg2lj.fsf@wcl-l.bham.ac.uk>
"Andrew Cragg" <caesura@freenetname.co.uk> writes:
> It seems that [...] using eval the global variable is not set unless
> I use the variable in some way (assignment to another variable for
> instance).
Actually you mean 'lexical' not 'global'. What you describe does not
apply to global variables.
The fact that lexical variables are accessible at all inside eval()ed
strings is fairly deep voodoo. What you are describing here is an
artifact of the interaction between closures and eval.
If an eval inside a closure tries to reference a lexical variable and
that lexical variable is not also directly referenced withing the same
closure it may not access the right instance of the lexical.
{
my $x = 1;
sub f1 { $x };
sub f2 { eval '$x' };
sub f3 { $x; eval '$x' };
}
print 'f1: ',f1,' f2: ',f2,' f3: ',f3;
__END__
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 18 Jan 2001 17:41:36 +0000
From: nobull@mail.com
Subject: Re: File::Find wont traverse CDROM !?
Message-Id: <u9bst4g3lb.fsf@wcl-l.bham.ac.uk>
rog <rfoskett@my-deja.com> writes:
> Does anyone have any ideas on this??
$File::Find::dont_use_nlink = 1;
(Alternatively fix the CD-ROM filesystem implementation in your OS).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 18 Jan 2001 16:12:24 GMT
From: RUATurtle <jack.haberle@bigfoot.com>
Subject: Re: Forwarding NT Event Log to Syslog
Message-Id: <9474ku$b9g$1@nnrp1.deja.com>
Lou,
Thanks for the response. Ordinarily I'd agree with you. In this
instance we have a lot of NT servers and no spare change, though.
If I can't find something free (e.g. a module that will work with
Activestate perl for NT) I'll most likely write a perl script to read
the log on the NT box and send (via sockets) anything useful to a
listener on our linux syslog collector, then have the listener write to
the syslog.
-Jack
In article <m05c6tc12prkb8shqkkqkt22mdbrekuv7t@4ax.com>,
Lou Moran <lmoran@wtsg.com> wrote:
> On Wed, 17 Jan 2001 14:54:32 GMT, RUATurtle <jack.haberle@bigfoot.com>
> wrote wonderful things about sparkplugs:
>
> >Hi,
> >
> >I'm looking for a way to forward NT Eventlogs to a syslog on a Linux
> >box. I've found some shareware (Adiscon EventReporter; $29/license)
but
> >no luck thus far finding something completely free.
>
> <rant>
> Hint: Writing Software is hard work. $29 bucks is "practically"
> free. Assuming the product works I would suggest you purchase it.
>
> Open Source does not me Free...
> </rant>
>
> >
> >Any hints that anyone might offer will be appreciated.
> >
> >TIA,
> >-J
> >
> >
> >Sent via Deja.com
> >http://www.deja.com/
>
> lmoran@wtsgSPAM.com
> print "\x{263a}"
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 18 Jan 2001 17:42:08 +0000
From: nobull@mail.com
Subject: Re: HELP!! : Bi-Directional TCP Perl Sockets
Message-Id: <u9ae8og3kf.fsf@wcl-l.bham.ac.uk>
"Dennis Fortin" <dfortin@eftia.com> writes:
> I have a question involving bi-directional communication using TCP sockets
> in Perl.
Actually your choice of Perl as the implementation language is
irrelvant. This is a language-independant socket newbie mistake.
> while($line = <$new_sock>) {
> $request .= $line;
> }
The above will block until an EOF condtion occurs reading $new_sock.
Since $new_sock is a socket this means it blocks until the thing at
the other end of the socket closes the socket or does a shutdown() to
say that it's finished writing.
> In any case, I'm looking for some insite to my problem. Maybe there's
> something that I missed, or am not looking at.
shutdown()
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 18 Jan 2001 17:50:50 +0100
From: "Federico Bari" <fedebari@supereva.it>
Subject: HELP: httpS protocol (https and NOT http)!
Message-Id: <947719$60t$1@lacerta.tiscalinet.it>
Hi all,
I have a lot of problem to find out informations and above all example
of how to install and use HTTPS (secure http) protocol module. Using the
standard http I get an error answer something as "404 https protocol not
allowed". I have given a look to te documents at www.perl.com but there are
too few information. If somebody PLEASE could give me an example; here above
some lines of code. How have I to modify them?
use LWP::UserAgent;
$interfaccia = new LWP::UserAgent;
$interfaccia->agent('Mozilla/5.0');
$interfaccia->timeout($tempo_max);
$richiesta=HTTP::Request-> new("POST" => "$url");
$richiesta->content("$cgi_variables");
$richiesta->content_type('application/x-www-form-urlencoded');
$risultato = $interfaccia->request($richiesta);
Thank you very much,
Federico.
------------------------------
Date: Thu, 18 Jan 2001 11:56:09 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: How can I extract strings from a Perl program?
Message-Id: <947772$6r6$1@slb1.atl.mindspring.net>
"Shimon Bollinger" <shimon@photonet.com> wrote in message
news:3a670418@news.bezeqint.net...
> I would like to extract all the strings from a Perl program. I need to
take
> into account all the various ways of quoting strings (' " qw q qq << etc.)
> as well as embedded quotes.
>
> Does anyone know of a module that can do this?
>
> Thanks,
> Shimon
>
Try this...
[start code]
use strict;
use warnings;
my $script = 'strings.pl';
open IN, "perl -MO=Showlex $script 2>&1 |"
or die "Can't open pipe: $!";
my @strings = grep {
chomp;
s/^\d+:\s*PV\s*\(0x[0-9a-f]+\)\s*\"(.*)"$/$1/;
} <IN>;
close IN or die "Can't close pipe: $!";
print "'$_'\n" foreach @strings;
[end code]
Kurt Stephens
------------------------------
Date: Thu, 18 Jan 2001 11:57:42 -0500
From: "Chris Rogers" <xchris.rogers@xvifanusa.com>
Subject: How to determine current array element during a for loop
Message-Id: <heF96.1322$ed.565345@nntp2.onemain.com>
I want to output the contents of an array element by element. I also need
to output the current element's name during a for loop but don't know how to
access that. I searched the camel book and can't find the answer. Here's a
small example describe what I'm trying to do.
Let's say that:
$grouplogins[1] = 12
$grouplogins[2] = 86
$grouplogins[4] = 3
$grouplogins[8] = 34
$grouplogins[9] = 104
foreach $line(@grouplogins)
{
print "Logins for group $#grouplogins: $line\n";
}
Originally, I thought that the $#grouplogins would give me the current
element in the for loop but now I know that it returns the identifier for
the last element in the array regardless of the loop. How do I determine
the current element of the array during this loop?
------------------------------
Date: Thu, 18 Jan 2001 17:09:07 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: How to determine current array element during a for loop
Message-Id: <3A672333.CEB8C8CB@coventry.ac.uk>
$grouplogins[1] = 12;
$grouplogins[2] = 86;
$grouplogins[4] = 3;
$grouplogins[8] = 34;
$grouplogins[9] = 104;
for ($a = 0; $a < $#grouplogins; $a++){
if (defined($grouplogins[$a])){
print "Logins for group $a: $grouplogins[$a]:\n";
}
}
Chris Rogers wrote:
> I want to output the contents of an array element by element. I also need
> to output the current element's name during a for loop but don't know how to
> access that. I searched the camel book and can't find the answer. Here's a
> small example describe what I'm trying to do.
>
> Let's say that:
> $grouplogins[1] = 12
> $grouplogins[2] = 86
> $grouplogins[4] = 3
> $grouplogins[8] = 34
> $grouplogins[9] = 104
>
> foreach $line(@grouplogins)
> {
> print "Logins for group $#grouplogins: $line\n";
> }
>
> Originally, I thought that the $#grouplogins would give me the current
> element in the for loop but now I know that it returns the identifier for
> the last element in the array regardless of the loop. How do I determine
> the current element of the array during this loop?
------------------------------
Date: Thu, 18 Jan 2001 12:32:07 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: How to determine current array element during a for loop
Message-Id: <94796i$gnp$1@slb6.atl.mindspring.net>
"Chris Rogers" <xchris.rogers@xvifanusa.com> wrote in message
news:heF96.1322$ed.565345@nntp2.onemain.com...
> I want to output the contents of an array element by element. I also need
> to output the current element's name during a for loop but don't know how
to
> access that. I searched the camel book and can't find the answer. Here's
a
> small example describe what I'm trying to do.
>
> Let's say that:
> $grouplogins[1] = 12
> $grouplogins[2] = 86
> $grouplogins[4] = 3
> $grouplogins[8] = 34
> $grouplogins[9] = 104
>
>
> foreach $line(@grouplogins)
> {
> print "Logins for group $#grouplogins: $line\n";
> }
Unlike a lot of cases where programmers go through a lot of unnecessary
contortions trying to force indexing on a perl array, this looks like a case
where an indexed for loop is what you want. See the perlsyn documentation
on for loops. Since your example is missing the array elements
@grouplogins[0,3,5..7], you may want to add a test to the loop to avoid
warnings on undefined values: If your actual data has blocks of
non-contiguous elements, you might consider using a hash instead of an
array.
for (my $i=0; $i < @grouplogins; $i++) {
next unless defined $grouplogins[$i];
print "Logins for group $i: $grouplogins[$i]n";
}
[ or ]
foreach my $i (0..$#grouplogins) {
print "Logins for group $i: $grouplogins[$i]n" if defined
$grouplogins[$i];
}
HTH,
Kurt Stephens
------------------------------
Date: 18 Jan 2001 11:37:07 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to determine current array element during a for loop
Message-Id: <87bst4sqws.fsf@limey.hpcc.uh.edu>
>> On Thu, 18 Jan 2001 11:57:42 -0500,
>> "Chris Rogers" <xchris.rogers@xvifanusa.com> said:
> I want to output the contents of an array element by
> element. I also need to output the current element's
> name during a for loop but don't know how to access
> that. I searched the camel book and can't find the
> answer. Here's a small example describe what I'm trying
> to do.
> Let's say that: $grouplogins[1] = 12 $grouplogins[2] =
> 86 $grouplogins[4] = 3 $grouplogins[8] = 34
> $grouplogins[9] = 104
This looks like you really want to be using a hash. It's
not really an array, but an association between values:
my %grouplogins = ( 1 => 12, 2 => 86, ... );
while (my ($k, $v) = each %grouplogins) {
print "$k => $v\n";
}
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: 18 Jan 2001 11:39:31 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: How to determine current array element during a for loop
Message-Id: <m3itncrc8c.fsf@dhcp11-177.support.tivoli.com>
"Chris Rogers" <xchris.rogers@xvifanusa.com> writes:
> I want to output the contents of an array element by element. I also need
> to output the current element's name during a for loop but don't know how to
> access that. I searched the camel book and can't find the answer. Here's a
> small example describe what I'm trying to do.
>
> Let's say that:
> $grouplogins[1] = 12
> $grouplogins[2] = 86
> $grouplogins[4] = 3
> $grouplogins[8] = 34
> $grouplogins[9] = 104
>
>
> foreach $line(@grouplogins)
> {
> print "Logins for group $#grouplogins: $line\n";
> }
In addition to the problem already stated, this code (after adding the
requisite semicolons to the data initialization lines) will produce
more output than I think is desired. It will output a line even for
the index numbers that do not have values.
Both problems can be fixed by using:
foreach my $index (0..$#grouplogins) {
next unless defined $grouplogins[$index];
print "Logins for group $index: $grouplogins[$index]\n";
}
__END__
Alternatively, if you don't want to loop over the indices, you can use
a counter:
my $index;
foreach my $entry (@grouplogins) {
next unless defined $entry;
print "Logins for group $index: $entry\n";
} continue {
$index++;
}
__END__
I prefer the previous method.
Finally, you could do something silly like:
foreach my $index (grep defined $grouplogins[$_], 0..$#grouplogins) {
print "Logins for group $index: $grouplogins[$index]\n";
}
__END__
But it is difficult for me to imagine when this (having two loops,
really) would be preferable to simply using next as in the first two
examples.
HTH...
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 18 Jan 2001 13:38:35 -0500
From: "Chris Rogers" <xchris.rogers@xvifanusa.com>
Subject: Re: How to determine current array element during a for loop
Message-Id: <rIG96.2682$AN.198860@nntp1.onemain.com>
Thanks to all for your quick and helpful responses. As always in purl,
there is more than one to skin a cat but the cat always gets skinned.
Thanks,
Chris
"Chris Rogers" <xchris.rogers@xvifanusa.com> wrote in message
news:heF96.1322$ed.565345@nntp2.onemain.com...
> I want to output the contents of an array element by element. I also need
> to output the current element's name during a for loop but don't know how
to
> access that. I searched the camel book and can't find the answer. Here's
a
> small example describe what I'm trying to do.
>
> Let's say that:
> $grouplogins[1] = 12
> $grouplogins[2] = 86
> $grouplogins[4] = 3
> $grouplogins[8] = 34
> $grouplogins[9] = 104
>
>
> foreach $line(@grouplogins)
> {
> print "Logins for group $#grouplogins: $line\n";
> }
>
> Originally, I thought that the $#grouplogins would give me the current
> element in the for loop but now I know that it returns the identifier for
> the last element in the array regardless of the loop. How do I determine
> the current element of the array during this loop?
>
>
>
------------------------------
Date: Thu, 18 Jan 2001 13:40:44 -0500
From: "Chris Rogers" <xchris.rogers@xvifanusa.com>
Subject: Re: How to determine current array element during a for loop
Message-Id: <kKG96.1369$ed.611922@nntp2.onemain.com>
Sorry about the typo. I have no idea how I type purl instead of perl.
"Chris Rogers" <xchris.rogers@xvifanusa.com> wrote in message
news:rIG96.2682$AN.198860@nntp1.onemain.com...
> Thanks to all for your quick and helpful responses. As always in purl,
> there is more than one to skin a cat but the cat always gets skinned.
>
> Thanks,
> Chris
>
> "Chris Rogers" <xchris.rogers@xvifanusa.com> wrote in message
> news:heF96.1322$ed.565345@nntp2.onemain.com...
> > I want to output the contents of an array element by element. I also
need
> > to output the current element's name during a for loop but don't know
how
> to
> > access that. I searched the camel book and can't find the answer.
Here's
> a
> > small example describe what I'm trying to do.
> >
> > Let's say that:
> > $grouplogins[1] = 12
> > $grouplogins[2] = 86
> > $grouplogins[4] = 3
> > $grouplogins[8] = 34
> > $grouplogins[9] = 104
> >
> >
> > foreach $line(@grouplogins)
> > {
> > print "Logins for group $#grouplogins: $line\n";
> > }
> >
> > Originally, I thought that the $#grouplogins would give me the current
> > element in the for loop but now I know that it returns the identifier
for
> > the last element in the array regardless of the loop. How do I
determine
> > the current element of the array during this loop?
> >
> >
> >
>
>
------------------------------
Date: Thu, 18 Jan 2001 18:46:54 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to determine current array element during a for loop
Message-Id: <slrn96e7dk.58t.tadmc@tadmc26.august.net>
John Tutchings <ccx138@coventry.ac.uk> wrote:
>for ($a = 0; $a < $#grouplogins; $a++){
^^
^^
You have a classic Off By One bug there.
Did you test your code before posting it?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 18 Jan 2001 16:26:13 GMT
From: David Waters <davidwaters@bigfoot.com>
Subject: interesting regex?
Message-Id: <9475ep$c0j$1@nnrp1.deja.com>
Just wondering how I would use a regeex to pull out all the top level
tags from the following?
<companies_house_data>
<cro_number values="Y(Yes),N(No)"></cro_number>
<name></name>
<acc_ref_date></acc_ref_date>
<dissolved_flag></dissolved_flag>
<dissolved_date></dissolved_date>
<company_status></company_status>
<no_accounts_filed></no_accounts_filed>
<ro_address>
<line_one></line_one>
<line_two></line_two>
<line_three></line_three>
<line_four></line_four>
<postcode></postcode>
</ro_address>
</companies_house_data>
<hello>
<hi></hi>
</hello>
The result should only contain "companies_house_data" and "hello" .
Thanks
David
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 18 Jan 2001 18:10:29 +0000
From: nobull@mail.com
Subject: Re: interesting regex?
Message-Id: <u9zogoenoq.fsf@wcl-l.bham.ac.uk>
David Waters <davidwaters@bigfoot.com> writes:
> Just wondering how I would use a regeex to pull out all the top level
> tags from the following?
You can't.
FAQ: "Can I use Perl regular expressions to match balanced text?"
There are modules on CPAN for parsing XML.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 18 Jan 2001 18:46:52 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: interesting regex?
Message-Id: <slrn96e6sa.58t.tadmc@tadmc26.august.net>
David Waters <davidwaters@bigfoot.com> wrote:
>Just wondering how I would use a regeex to pull out all the top level
>tags from the following?
[ snip hierarchical data with "start" and "end" delimiters ]
Maintain a stack, pseudocode inside some sort of "read tags"
loop construct:
if ( is start tag )
{ push @stk, $tag_name }
elsif ( is end tag )
{ $closed = pop @stk}
else
{ warn "dunno what the heck it is...\n" }
print "$closed\n" unless @stk; # is root element if stack size is zero
Your data looks suspiciously like XML. If it is, then ignore
my answer, there are better ways (i.e. my way above may not work
with arbitrary XML).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 90
*************************************