[12289] in Perl-Users-Digest
Perl-Users Digest, Issue: 5889 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 4 14:07:30 1999
Date: Fri, 4 Jun 99 11:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 4 Jun 1999 Volume: 8 Number: 5889
Today's topics:
Re: Anyone know what is this script line meaning ?? (Larry Rosler)
automatic html form response (was: Can Perl do this?) mda@discerning.com
Re: Broken Pipe - nit picking <rootbeer@redcat.com>
Re: Calling another Perl script <cassell@mail.cor.epa.gov>
Re: Coloring text in DOS console? <rootbeer@redcat.com>
Re: Copying any files <cassell@mail.cor.epa.gov>
Could someone quickly tell me the syntax for the SSI in <oliver@admiralq.free-online.net>
Re: Could someone quickly tell me the syntax for the SS (Greg Bacon)
Re: Dataset update/Security question <rootbeer@redcat.com>
Re: Executing adduser? Follow Up. <madvin@dds.nl>
Re: Executing adduser? <rootbeer@redcat.com>
Re: FAQ 5.15: How can I open a file with a leading "E<g <cassell@mail.cor.epa.gov>
Re: How do you print a file backwards by line? (M.J.T. Guy)
Re: know Perl to maintain Perl (was: Re: I pass an arra (Greg Bacon)
Re: let me be more specific... <rootbeer@redcat.com>
Re: Looking for password script w/timed access restrict <rootbeer@redcat.com>
Re: LWP::UserAgent and URL redirect... <gisle@aas.no>
Re: MIME-QuotedPrint Module <dontmailmespam@duh.net>
Re: MIME-QuotedPrint Module <cassell@mail.cor.epa.gov>
Re: MIME-QuotedPrint Module <gisle@aas.no>
Newbie: Would really appreciate some pointers on assign <k1001@netzero.net>
Re: Please help with associative arrays of arrays! (Michel Dalle)
Printing control characters from the format statement adavis@cbis.com
Re: s/a*/x/g behavior (James Peregrino)
Re: s/a*/x/g behavior (M.J.T. Guy)
Re: s/a*/x/g behavior <dgris@moiraine.dimensional.com>
Re: Script to cause web page to print? <rootbeer@redcat.com>
Simple question about hashes <nbarney@csd.sdl.usu.edu>
Re: Simple question about hashes (Michel Dalle)
Re: Simple question about hashes (Greg Bacon)
Re: Structures in PERL <tchrist@mox.perl.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 Jun 1999 10:50:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Anyone know what is this script line meaning ??
Message-Id: <MPG.11c1b1be7c8c61c0989b6b@nntp.hpl.hp.com>
In article <xkfwvxk9bps.fsf@valdemar.col.hp.com> on 04 Jun 1999 10:23:11
-0600, Eric The Read <emschwar@rmi.net> says...
> Jonathan Stowe <gellyfish@gellyfish.com> writes:
> > Oh no ! Matt's been posessed by the spirit of Larry R ;-}
>
> That's ridiculous! There wasn't one 'use Benchmark;' in there
> anywhere. :^)
Nein. Too many keystrokes, Herr Mozart.
Unfortunately, I've discovered that occasionally the shortest code and
the fastest benchmarks don't go together. What's a guy to do? :-(
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 04 Jun 1999 16:12:32 GMT
From: mda@discerning.com
Subject: automatic html form response (was: Can Perl do this?)
Message-Id: <7j8tt7$gtb$1@nnrp1.deja.com>
In article <374e839e@cs.colorado.edu>,
tchrist@mox.perl.com (Tom Christiansen) wrote:
> [courtesy cc of this posting mailed to cited author]
Tom (or anyone) --do you have a suggestion for how to go further
and parse the html form, examine all the INPUT
fields for defaults, make sure you've got a value
for all of the non-defaulted ones, etc.?
WWW::Robot seems not to deal with forms.
HTML::TreeBuilder and HTML::Parser and the
various sgml/xml things might help do it, but
surely someone has already hacked together the
requisite parser callbacks for generating
a matching post to a not-entirely-pre-known form?
Also, on a only partially related not, how about
a perl module that tracks cookie values so that
i can be sending them back appropriately?
-mda
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 4 Jun 1999 10:50:43 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Broken Pipe - nit picking
Message-Id: <Pine.GSO.4.02A.9906041046590.10794-100000@user2.teleport.com>
On 4 Jun 1999, M.J.T. Guy wrote:
> Tom Phoenix <rootbeer@redcat.com> wrote:
> >
> >If you instead do the open on "-|" and exec your program directly with the
> >multiple-arg form of exec (after doing your own input redirection or
> >whatever) I think you'll find no Bash, no message, no problem. See the
> >docs on open if you're not familiar with "-|".
>
> Usually, that's overkill. open on "my_command args |" won't
> involve the shell unless shell metacharacters are present. And if
> you're using shell metacharacters, you won't be able to use the
> multi-arg form of exec anyway.
Maybe I was unclear. There was a shell being invoked (and producing the
unwanted message "broken pipe"). I was advising that that be avoided by
using the multi-arg form of exec. Of course, this means handling any shell
meta-chars from within Perl. That's what I meant by the parenthetical
comment about "input redirection or whatever".
I couldn't give more specifics since the original message didn't say what
shell metachars were involved.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 04 Jun 1999 10:13:36 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Calling another Perl script
Message-Id: <37580940.91222C4F@mail.cor.epa.gov>
Wyzelli wrote:
>
> What is the correct (or best) way to invoke one Perl Script from another?
>
> ie I have one script which contains some subroutines and I want to write
> another to test for certain conditions (date related) before running the
> first.
>
> I have searched the FAQ, PerlDOC and all things I can think of but I guess I
> am searching on exactly the wrong keywords.
>
> Even a pointer to the correct FAQ would be appreciated!
Okay, can do(). :-)
My guess is that what you want is:
do 'other_filename.pl';
So look in perlfunc for the section on do().
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 4 Jun 1999 10:46:23 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Coloring text in DOS console?
Message-Id: <Pine.GSO.4.02A.9906041044060.10794-100000@user2.teleport.com>
On Fri, 4 Jun 1999, Mark Priatel wrote:
> - How can I color the output of a Perl program in a MS-DOS shell.
> - How can I reposition the cursor in a MS-DOS shell.
Probably the same way that you do for a non-Perl program. You almost
certainly output some special codes that tell your system what you want it
to do. The docs, FAQs, and newsgroups about MS-DOS may be able to help you
here. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 04 Jun 1999 10:26:40 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Copying any files
Message-Id: <37580C50.53325095@mail.cor.epa.gov>
Alar Pandis wrote:
>
> Hi, Jonathan!
> Thanks.
>
> Can You give example how can I use modules? I have file A and need copy this
> file into location B.
You'll be pleased to know that the modules come with their own
docs, which usually include helpful examples. Just type:
perldoc File::Copy
to see a couple. [This does assume you have Perl installed
on your system.]
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 4 Jun 1999 18:49:11 +0100
From: "Oliver Brown" <oliver@admiralq.free-online.net>
Subject: Could someone quickly tell me the syntax for the SSI include? (nt)
Message-Id: <BqU53.613$Hy4.605@wards>
------------------------------
Date: 4 Jun 1999 17:55:39 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Could someone quickly tell me the syntax for the SSI include? (nt)
Message-Id: <7j93ur$qag$4@info2.uah.edu>
Ask in a group devoted to discussing your particular web server.
Greg
--
In a literary light, if UNIX is the Great Novel, Perl is the Cliffs Notes.
-- Thomas Scoville
------------------------------
Date: Fri, 4 Jun 1999 10:28:27 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Dataset update/Security question
Message-Id: <Pine.GSO.4.02A.9906041013180.10794-100000@user2.teleport.com>
On Fri, 4 Jun 1999, Jeff Miller wrote:
> I have a Perl security question - I have a webpage that is created in
> Perl by reading a data file - the page is a list of monthly specials,
> and the data file contains the items for sale with their price(hopefully
> makes updates eaiser, but not easy enough). What I would like to do( and
> have partially done) is create a form page that is PW protected to read
> the data file from above, then with the submit button, update the data
> file with the new information, thus changing the specials page without
> any FTP or editing. I believe that I have most of the above close to
> working, but I am concerned about security - any
> suggestions/thoughts/additions?? Will PW protecting the pages be enough?
I'm sure that it seems to be a question about _perl_ security, but it's
really about web security. That is to say, even if your program were
written in another language, you'd have the same worries about security.
Although I'll try to help you here anyway, you may get more help through a
web-related newsgroup.
Of course, there can be flaws in your Perl program which can impact
security; see the perlsec manpage for information about those.
You ask whether password protecting the pages will be enough. I don't
think that anyone else can answer that, as only you know how important
this security is to you. Here's my general rule-of-thumb: If the worth of
the data is much less than what it would cost an attacker to obtain it,
it's secure enough. That is, if unauthorized access or damage to the data
would cost you $10 but cost the attacker $10,000, there's nothing to worry
about. But if the access or damage would be a $10,000 headache for you and
only cost an attacker $1000, you need to fix that.
It's worth noting that many (most?) means of password protection which run
over the web send the password over the wires as plaintext. Yow. :-)
Be sure to check out the various web-related security FAQs and docs.
http://www.w3.org/Security/Faq/www-security-faq.html
http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt
http://Stars.com/Authoring/Scripting/Security/
http://language.perl.com/CPAN/doc/FAQs/cgi/perl-cgi-faq.html
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 4 Jun 1999 17:22:21 GMT
From: Vincent Ridderikhoff <madvin@dds.nl>
Subject: Re: Executing adduser? Follow Up.
Message-Id: <37580B4B.B09B9412@dds.nl>
This is the source I use, can anyone give me som help on this one??
#!/usr/bin/perl -w
#use strict;
print "Reading File.\n ";
open(FILE,"new.txt");
$line = <FILE>;
while ($line ne "") {
chomp($line);
($user, $pass) = split(/;/,$line);
#print ($user,"\t",$pass);
$line = <FILE>;
}
$pass = "test";
$user = "bladie";
$command = ("useradd");
@args =
($command,"-g","ftp","-d","/home/",$user,"-s","/bin/ftponly","-p",$pass,$user);
#Here it goes wrong, somehow the first $user becomes empty and the last
$user keeps it's value.
#so in the passwd file it shows the following:
#bladie:x:1000:400::/home/:/bin/ftponly
#@args =
($command,"-g","ftp","-d","/home/",$user,'/./',"-s","/bin/ftponly","-p",$pass,$user);
#Also when I use this it goes wrong completely on the '/./' part I
also tried replacing the ' with " .
#Can anyone please help me with this one???
print("\n",@args,"\n");
system(@args) == 0 or die ("Bla $?");
Vincent Ridderikhoff schreef:
> Hi,
>
> I want to execute adduser from perl, I first get the usernames and
> passwords from a file (which goes just great?) and the I need to pass
> them to the system() or the exec() function.but somehow this always give
> back an error, I don't know why. When I try to execute is without the
> variables $USER and $PASS and just pass static text (const. value) to
> the system() function al goes well, as soon as I use a variable it goes
> completly wrong.
>
> Greetz Vincent...
>
> :-))
------------------------------
Date: Fri, 4 Jun 1999 10:36:03 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Executing adduser?
Message-Id: <Pine.GSO.4.02A.9906041033030.10794-100000@user2.teleport.com>
On 4 Jun 1999, Vincent Ridderikhoff wrote:
> I want to execute adduser from perl, I first get the usernames and
> passwords from a file (which goes just great?) and the I need to pass
> them to the system() or the exec() function.but somehow this always
> give back an error, I don't know why.
It would be helpful to know what error you're seeing.
> When I try to execute is without the variables $USER and $PASS and
> just pass static text (const. value) to the system() function al goes
> well, as soon as I use a variable it goes completly wrong.
It sounds as if you're not passing the values you think you're passing.
Have you tried stepping through your program in the debugger? You can put
a breakpoint on the line which calls system and then use the x command to
see what's in those variables.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 04 Jun 1999 10:16:01 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: FAQ 5.15: How can I open a file with a leading "E<gt>" or t
Message-Id: <375809D1.6BE71C8C@mail.cor.epa.gov>
Lee wrote:
>
> In article <3757be0b@cs.colorado.edu>,
> Tom Christiansen <perlfaq-suggestions@perl.com> wrote:
>
> >Annex Canada now! We need the room, and who's going to stop us?
> > --A Tom Neff .signature
>
> You tried it once before. Looking to have the White House burnt to the
> ground again? :)
Don't be surprised if a large number of Americans reply to
this by saying "YES! PLEASE!" :-)
Besides, we already know about your country's efforts to develop
a Combat Bra, so you're helpless now...
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 4 Jun 1999 17:24:00 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How do you print a file backwards by line?
Message-Id: <7j923g$ndu$1@pegasus.csx.cam.ac.uk>
John Porter <jdporter@min.net> wrote:
>
>Interesting -- the 'last' is not necessary, as long as the <> is
>reading from STDIN (or some explicit handle, like <F> or <DATA>).
>But if it's reading from a file named in @ARGV, then it won't
>work without the 'last'. Strange!
Not strange at all. What is <> defined to do when @ARGV is empty?
Mike Guy
------------------------------
Date: 4 Jun 1999 17:52:19 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: know Perl to maintain Perl (was: Re: I pass an array...)
Message-Id: <7j93oj$qag$2@info2.uah.edu>
In article <37580352.9F18F3D5@mail.cor.epa.gov>,
David Cassell <cassell@mail.cor.epa.gov> writes:
: Bill Jones wrote:
: > But there is no reason not to program any way you
: > see fit, or can, program. I myself spent some time
: > with some of the things I've seen here in the group.
:
: Ditto. Not all of us came into Perl with a graduate degree
: that had an emphasis on operating systems design and
: computational linguistics. :-)
Straw men don't help your argument.
Greg
--
Ironic, isn't it, Smithers? This anonymous clan of slackjawed troglodytes just
cost me the election, but if I were to have them killed, I would be the one to
go to jail. That's democracy for you.
-- Mr. Burns
------------------------------
Date: Fri, 4 Jun 1999 10:43:01 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: let me be more specific...
Message-Id: <Pine.GSO.4.02A.9906041039160.10794-100000@user2.teleport.com>
On Fri, 4 Jun 1999 jamiemw@my-deja.com wrote:
> Subject: let me be more specific...
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> I don't really know perl, and although I have some C++ background, I
> would like something quick and dirty to throw on my site. My
> alternatives are to learn Interdev or Cold Fusion. I'd rather dig
> into perl.
It's not clear to me: Are you trying to learn Perl? Or do you want to
simply install a program?
If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service.
> So I want a script that presents a form where the user enters their
> username and password and clicks, log-in. The script would query the
> flat-file database and return their account balance.
>
> That's it. Maybe they would be able to change their password.
If you're trying to write such a thing, maybe you could hack on one of the
programs found here:
http://www.w3.org/Security/Faq/wwwsf3.html#Q23
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 4 Jun 1999 10:02:14 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Looking for password script w/timed access restrictions
Message-Id: <Pine.GSO.4.02A.9906041001590.10794-100000@user2.teleport.com>
On Fri, 4 Jun 1999, Brian Browning wrote:
> I am looking for a password script that will only allow visitors to
> access a protected part of my site once a week. Any suggestions of
> where I might find such a script would be greatly appreciated.
If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 04 Jun 1999 19:46:09 +0200
From: Gisle Aas <gisle@aas.no>
Subject: Re: LWP::UserAgent and URL redirect...
Message-Id: <m3wvxj5066.fsf@eik.g.aas.no>
dennis@info4.csie.nctu.edu.tw (GEMINI) writes:
> I use LWP::UserAgent to request
> a document from a URL. The response
> is sometimes a redirect message:
>
> _rc=302
> _msg=Moved Temporarily
>
> headers:
> expires=Mon, 01 Feb 1999 08:00:00 GMT
> client-warning=Redirect loop detected
LWP assumes that it have found a "redirect loop" if you get a redirect
back to the same URI you started from. Some servers do this if a
request without cookies arrive and assume that the client will retry
with the cookie(s) set. Unfortunately LWP does not handle this
situation very well. Either you should make sure that you have some
suitable cookie in the first request, or you could try to fix the
"redirect loop" code in &LWP::UserAgent::request and make sure the
$ua->cookie_jar is set, or you let the application deal with this
redirect.
> title=Object moved
> cache-control=private
> set-cookie=sessionId= .....
> client-peer=....
> x-cache=....
> location=....
>
> I found that when I use MSIE 4.0 to browse the page, the browser
> will not report 302 Error, but automatically redirect to the correct
> page according to location in header (I guess).
> So I am wondering if the LWP::UserAgent can also redirect automatically.
>
> By the way, the response headers including "set-cookie", and
> what should I treat it for the next request??
If you set up the $ua->cookie_jar, then the cookie will automatically
be filled out if you retry the request.
--
Gisle Aas
------------------------------
Date: Fri, 04 Jun 1999 10:10:59 -0700
From: Dweezel Zappa <dontmailmespam@duh.net>
Subject: Re: MIME-QuotedPrint Module
Message-Id: <375808A3.3BC2C9E4@duh.net>
It might be here:
http://theory.uwinnipeg.ca/CPAN/data/MIME-Base64/QuotedPrint.html
the1bob@my-deja.com wrote:
> Hello, all!
>
> I just successfully installed Jenda's Mail-Sender PM and can't wait to
> start testing it. :-)
>
> I have, by default, MIME-Base64 installed as part of the ActivePerl
> distribution. Mail-Sender also requires MIME-QuotedPrint. Where can I
> get that module? It was not on her site or the ActiveState list.
> *sigh*
>
> Also.....do any of you have a good working model of the form interface
> that I can look at?
>
> The favor of a reply would be appreciated.
>
> TIA,
>
> Bob
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
--
____________________________________________________________
If you need to email me, my email address is :
_cwillison_ at _vrcis_ dot com (and remove the underscores!)
____________________________________________________________
------------------------------
Date: Fri, 04 Jun 1999 10:43:08 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: MIME-QuotedPrint Module
Message-Id: <3758102C.7899A216@mail.cor.epa.gov>
the1bob@my-deja.com wrote:
>
> Hello, all!
>
> I just successfully installed Jenda's Mail-Sender PM and can't wait to
> start testing it. :-)
>
> I have, by default, MIME-Base64 installed as part of the ActivePerl
> distribution. Mail-Sender also requires MIME-QuotedPrint. Where can I
> get that module? It was not on her site or the ActiveState list.
> *sigh*
I think that if you go to the command prompt and type:
ppm install MIME-tools
you'll get MIME::QuotedPrint as part of the set.
Umm, and I think that Jenda is a *guy*. Of course, I've been
wrong on this sort of problem before. [Abigail knows to whom
I refer.]
> Also.....do any of you have a good working model of the form interface
> that I can look at?
The docs that come with MIME-tools and MIME::Lite are
pretty complete. Once you have them installed, go to your
HTML tree [it's on your Start menu unless you monkeyed
with the ActiveState install]. Go down to the MIME section
and look at the 'Tools' and 'Lite' subsections. There are
lots of details and examples there.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 04 Jun 1999 19:35:29 +0200
From: Gisle Aas <gisle@aas.no>
Subject: Re: MIME-QuotedPrint Module
Message-Id: <m3zp2f50ny.fsf@eik.g.aas.no>
the1bob@my-deja.com writes:
> I just successfully installed Jenda's Mail-Sender PM and can't wait to
> start testing it. :-)
>
> I have, by default, MIME-Base64 installed as part of the ActivePerl
> distribution. Mail-Sender also requires MIME-QuotedPrint. Where can I
> get that module?
MIME::QuotedPrint is bundled together with MIME::Base64. You should
have them both if the MIME-Base64 distribution is installed.
--
Gisle Aas
------------------------------
Date: Fri, 04 Jun 1999 14:13:37 -0400
From: CY <k1001@netzero.net>
Subject: Newbie: Would really appreciate some pointers on assigning index number to RHS replacement of a regex
Message-Id: <37581751.973CBEB5@netzero.net>
Hi Group,
I really look hard at the perlre.html FAQ and some tutorial page,
I think this is not a moron question.
I want to replace apple with orange and assign the index number
(i.e. 1, 2, 3, 4,...) in front of "orange"
I try
$counter=0;
$string =~s/apple/$counter++ orange/ig;
and
$counter=0;
$o="orange";
$styring =~s/apple/($counter++).$o/ige;
neither of them work. What drives crazy is that I don't understand the
output, both of with only assign "0++" and "0" respectively on the FIRST
string of "orange", I thought at least it will put "0" in front of ALL
"orange" strings. Why?
Is that a golbal variable $something that record the order of the
current matched string? While I'm at it, can I use if while statement
to do this?
$_=$string;
$quantity=(/(apple)/ig);
$counter=0; $o=" orange";
foreach (1..$quantity) {/apple/$counter.$o/i; $counter++;}
The above code seems to be incredible stupid to me. I have 10+ s///
regex that I want to assign index number to, I would really appreciate
any pointer, thanks in advance!!
CY
------------------------------
Date: Fri, 04 Jun 1999 17:27:59 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Please help with associative arrays of arrays!
Message-Id: <7j92bk$ela$1@news.mch.sbs.de>
In article <3757E5C1.C8D92E02@americasm01.nt.com>, "Chow, Larry (EXCHANGE:RICH1:2L14)" <chow@americasm01.nt.com> wrote:
>Our perl guru is not in today and I would like to get this script
>working...
Is it still today, or is it tomorrow yet ? :-)
[snip]
> push(@{$Pat_Rel{$pid}},$user); <<<<< HERE IS WHERE IT IS DEFINED
[snip]
>So how come perl has a problem with finding out the number of elements
>in the array using $# ?
>
> if ($#Pat_Rel{$pid} > 1) {
[snip]
>Can't use subscript on array length at
>/opt/corp/mnt/mtxfs/2lxx/s700/bin/pacs_update.pl line 261, near "$pid}"
[snip]
>If I try to add {}'s to the expression it gives different errors about
>syntax.
>
> if (${#Pat_Rel{$pid}} > 1) {
>
>Any ideas? Please reply via email. Thanks!
You haven't tried all combinations of $, # and { yet, have you ?
What about $#{$Pat_Rel{$pid}} ? That should do the trick :-)
BTW, $# does NOT give you the number of elements in the array,
but the subscript of the last element (i.e. usually one less than
than the number of elements, since arrays usually start at 0).
And you don't need to work with indices anyway. As it says
in the Perl FAQ 4, you might try :
for $user (@{$Pat_Rel{$pid}}) {
if ($user eq "anam\@nt.com") {
return 1;
}
}
Of course, once your Perl guru comes back on monday, he'll
probably tell you to simply create a hash based on $user instead
of $pid, but that's another story...
Michel.
------------------------------
Date: Fri, 04 Jun 1999 16:11:57 GMT
From: adavis@cbis.com
Subject: Printing control characters from the format statement
Message-Id: <7j8ts4$gt2$1@nnrp1.deja.com>
I have a perl program that uses the format statement with STDOUT_TOP
to print report headings. I would like to embed control characters
in the title line, so that when the report output is sent to psf
and then to a postscript printer, the title will appear in large
bold characters. This has worked find with perl 4, but when I
switch to perl 5, the control characters are printed as regular
characters.
Has anyone been able to get this to work? Is there a fix or a
workaround for it?
Any help would be appreciated.
Please send responses directly to me, as well as to the list.
Thank you,
Alan Davis
adavis@convergys.com
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Fri, 4 Jun 1999 12:53:18 -0400
From: james_peregrino@harvard.edu (James Peregrino)
Subject: Re: s/a*/x/g behavior
Message-Id: <1dsvkxx.17qafsbmm17s6N@dcepf5.harvard.edu>
> Your explanation doesn't seem quite right to me. I'm going to start
> from the same place you did--showing what was matched.
>
[chomp]
Thanks Daniel, it is much clearer now.
Do you know, (or anywhere else know) where it is documented that Perl
will advance the pointer so that it doesn't infinitely replace the null
string? Is it in perlre or the Friedl book? I'm not claiming it isn't
documented, it just points out to me that I haven't read some section of
the documentation thoroughly enough.
-James
--
James Peregrino (617)496-6288 (v)
Manager of Comp. Services (617)495-5685 (f)
Harvard Div. Cont. Ed.
james_peregrino@harvard.edu
------------------------------
Date: 4 Jun 1999 17:27:45 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: s/a*/x/g behavior
Message-Id: <7j92ah$no6$1@pegasus.csx.cam.ac.uk>
Daniel Grisinger <dgris@perrin.dimensional.com> wrote:
>
>I must be confused, in what way can the letter `H' _not_
>be said to be "ZERO or more a's".
Yes, you are! It must be Friday.
Zero a's is ''.
One a is 'a'.
Two a's is 'aa'.
....
I don't see the string 'H' in that list.
Mike Guy
------------------------------
Date: 04 Jun 1999 11:37:58 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: s/a*/x/g behavior
Message-Id: <m3so87x3wp.fsf@moiraine.dimensional.com>
mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
> Daniel Grisinger <dgris@perrin.dimensional.com> wrote:
> >
> >I must be confused, in what way can the letter `H' _not_
> >be said to be "ZERO or more a's".
>
> Yes, you are! It must be Friday.
Yup, it's Friday and I'm confused. Not that there is
necessarily any correlation between those things. :-)
I was conflating the character `H' with the string
`H', oops.
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Fri, 4 Jun 1999 10:07:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Script to cause web page to print?
Message-Id: <Pine.GSO.4.02A.9906041006310.10794-100000@user2.teleport.com>
On Fri, 4 Jun 1999, Brian Browning wrote:
> I am trying to develop a script that will print out the contents of a
> file, or a web page when the website visitor clicks on a print button
> on my website. Is this possible? Further, I would like the window to
> close, when the push button is activated.
It sounds as if you want to ask a remote browser to do something. Check
the docs, FAQs, and newsgroups about browsers and the protocols they use
to see whether this is possible. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 04 Jun 1999 11:31:36 -0600
From: Neal Barney <nbarney@csd.sdl.usu.edu>
Subject: Simple question about hashes
Message-Id: <37580D78.9000693E@csd.sdl.usu.edu>
Will a hash store a key/value pair whose value is 0 (zero)? Here's the
problem I am having. If I start with something like this:
#!/usr/bin/perl
%hash = (
"ABC" => 0,
"ACB" => 1,
"BAC" => 2,
"BCA" => 3,
"CAB" => 4,
"CBA" => 5);
$junk = "ABC";
if ($hash{$junk}) {
print "$junk is found in \%hash\n";
}
else {
print "$junk is not found in \%hash\n";
}
This will work for everything but "ABC". If I change the value of "ABC"
to
"ABC" => 6 (or whatever) it works fine. Why?
-Neal-
------------------------------
Date: Fri, 04 Jun 1999 17:42:53 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Simple question about hashes
Message-Id: <7j937g$ela$2@news.mch.sbs.de>
In article <37580D78.9000693E@csd.sdl.usu.edu>, Neal Barney <nbarney@csd.sdl.usu.edu> wrote:
> Will a hash store a key/value pair whose value is 0 (zero)? Here's the
>problem I am having. If I start with something like this:
>
>#!/usr/bin/perl
>
>%hash = (
> "ABC" => 0,
> "ACB" => 1,
> "BAC" => 2,
> "BCA" => 3,
> "CAB" => 4,
> "CBA" => 5);
>
>$junk = "ABC";
>
>if ($hash{$junk}) {
> print "$junk is found in \%hash\n";
>}
>else {
> print "$junk is not found in \%hash\n";
>}
>
>This will work for everything but "ABC". If I change the value of "ABC"
>to
>"ABC" => 6 (or whatever) it works fine. Why?
Because $hash{$junk} is 0 ( = false), so it is indeed 'not found'.
You should try using this instead :
if (defined($hash{$junk})) {
..
}
else {
..
}
Michel.
------------------------------
Date: 4 Jun 1999 17:54:33 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Simple question about hashes
Message-Id: <7j93sp$qag$3@info2.uah.edu>
In article <7j937g$ela$2@news.mch.sbs.de>,
michel.dalle@usa.net (Michel Dalle) writes:
: if (defined($hash{$junk})) {
...or
if (exists $hash{$junk}) { ... }
Greg
--
An authority is a person who can tell you more about something than you really
care to know.
------------------------------
Date: 4 Jun 1999 11:58:12 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Structures in PERL
Message-Id: <375813b4@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
planb@newsreaders.com (J. Moreno) writes:
:Tom Christiansen <tchrist@mox.perl.com> wrote:
:I have, and haven't seen what I think is a more serious lack -- what's
:the best way to have the equivalent of a list of records? Currently I
:use a bunch of hashes, but whenever I do I get the nagging feeling that
:there's a better way just around the corner.
Use your imagination.
+--------------------------+
| Building Data Structures |
+--------------------------+
We don't usually bother with classic data structures like records, linked
lists, and trees in Perl because the built-in arrays and hashes take
care of most of those needs. Nonetheless, building them is very easy.
For nearly all of them, the key is to use an anonymous hash as the
fundamental unit in your data structure. For example:
$record = {
NAME => "Jason",
EMPNO => 132,
TITLE => "deputy peon",
AGE => 23,
SALARY => 37_000,
PALS => [ "Norbert", "Rhys", "Phineas"],
};
+---------------------------+
| Accessing Record Elements |
+---------------------------+
Given a record as above, you could get a field like this:
print $record->{NAME}, "\n";
print join(", " => @{$record->{PEERS});
print "\n";
Or even dynamically:
for $field (sort keys %$record) {
print "$field: ";
if (ref $record{$field} eq "ARRAY") {
print "@{ $record->{$field} }\n";
}
else {
print "$record->{$field}\n";
}
}
+-------------------------+
| Grouping Records -- HoH |
+-------------------------+
Once you create the record, it can be stored
in hashes or arrays, or both.
# use %ByName, a hash of records
$ByName{ $record->{NAME} } = $record;
# or later, as though it were a hash of records
$ByName{"Jason"}{SALARY} *= 1.035;
# iterating through whole thing
for $rec (sort keys %ByName) {
printf "%s is age %d.\n",
$rec->{NAME}, $rec->{AGE};
}
+------------------------+
| Storing Records -- AoH |
+------------------------+
Here we'll use an array of hashes to implement a list of records.
# store this record
$Employees[ $record->{EMPNO} ] = $record;
# example using grep
@peons = grep { $_->{TITLE} =~ /peon/i } @Employees;
# example using loop
foreach $num ( 0 .. $#Employees ) {
next unless $Employees[$num];
printf "Employee %d is %s.\n",
$num, $Employees[$num]{NAME};
}
+--------------------------+
| Storing Records -- AoAoH |
+--------------------------+
Imagine creating a structure whose Nth element access the records of
all employees of age N.
push @{ $ByAge[ $record->{AGE} ] }, $record;
# show all the 23 year olds
foreach $rec ( @{ $ByAge[23] } ) {
print $rec->{NAME}, "\n";
}
# show everyone
for $age ( 0 .. $#ByAge ) {
next unless $ByAge[$age];
print "$age: ";
for $rec (@{ $ByAge[$age] }) {
print $rec->{NAME}, " ";
}
print "\n";
}
--
"Yes, you can think of almost everything as a function, but this may upset
your wife." --Larry Wall
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5889
**************************************