[17121] in Perl-Users-Digest
Perl-Users Digest, Issue: 4533 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 5 21:05:27 2000
Date: Thu, 5 Oct 2000 18:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970794311-v9-i4533@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 5 Oct 2000 Volume: 9 Number: 4533
Today's topics:
Re: [Fwd: reading a secret] (Gwyn Judd)
Re: a 14 day counter <pr.coles@virgin.net>
ANNOUNCE Mail::Bulkmail 2.05 <jim3@psynet.net>
Re: beginner question <jeffp@crusoe.net>
Re: beginner question (Keith Calvert Ivey)
Re: beginner question (Martien Verbruggen)
Re: Can't lock error (Gwyn Judd)
Re: Changing STDOUT (Martien Verbruggen)
Re: counter problem HELP (Gwyn Judd)
Re: Dumping lexical data structures from scratchpads Roy.Ivy.III@nMail.com
Re: Forking, Exiting, and Timing out within an Eval <already_seen@my-deja.com>
Re: Formating output to be read in a form. (Martien Verbruggen)
Re: how to unlink this file? du_bing@my-deja.com
Re: how to unlink this file? <lr@hpl.hp.com>
Re: how to unlink this file? (Ben Coleman)
Newbie with HTTP LWP problem <pr.coles@virgin.net>
Re: Newbie with HTTP LWP problem <bwalton@rochester.rr.com>
OT - silly (was: Re: A matter of style (was Re: Search (David H. Adler)
Perl embeding without creating dll yin@itginc.com
Re: Quirk of strict ?? <david.obrien@ssmb.com.au>
Re: Quirk of strict ?? <barry.allebone@DB.COM>
Reading file into an array <g.soper@soundhouse.co.uk>
Re: Reading file into an array (Martien Verbruggen)
Re: RegEx: I'm stumped adaptivetechnologies@my-deja.com
Re: RegEx: I'm stumped (Martien Verbruggen)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Oct 2000 23:32:05 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: [Fwd: reading a secret]
Message-Id: <slrn8tq3rj.sv.tjla@thislove.dyndns.org>
I was shocked! How could Bap <lists@a1.org.uk>
say such a terrible thing:
>This is a multi-part message in MIME format.
>--------------D5C3AE4D8A408BBFC1A22EC0
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>
>I am resending this as it seems that only the most recent postings get
>looked at!
Not only that but posts that are written in such vague terms as to make
them incomprehensible or are in MIME format routinely get ignored too.
Who 'da thunk it?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I think animal testing is a terrible idea; they get all nervous and give
the wrong answers.
------------------------------
Date: Thu, 5 Oct 2000 23:53:06 +0100
From: "Paul Coles" <pr.coles@virgin.net>
Subject: Re: a 14 day counter
Message-Id: <8rj01g$c7g$1@neptunium.btinternet.com>
in the good old days ;-)
julian dates are the number of days since a specific date ( which was 01 Jan
1970)
these are stored in an integer
max integer is 32767
first 2 digits number of years since start date
last 3 digits number of days gone in year
so a date can be stored in a 2 byte integer field
year 2000 was no problem u wait till 1970+32 year 20002 ;-)))))))))
jtjohnston <jtjohnston@courrier.usherb.ca> wrote in message
news:39DD9707.7072@courrier.usherb.ca...
> > >Use Julian days and your life becomes simple.
> > What is this "Julian Days" thing that keeps popping up? Why is it better
> > than, say, days since Jan 1 1970?
>
> Was there an answer since last night? I must be losing threads?
> Could someone e-mail me?
------------------------------
Date: Thu, 05 Oct 2000 00:21:44 GMT
From: Jim Thomason <jim3@psynet.net>
Subject: ANNOUNCE Mail::Bulkmail 2.05
Message-Id: <stq4u2av49t30d@corp.supernews.com>
Mail::Bulkmail 2.05 is a perl based mass-mailing solution.
2.05 contains the usual bug fixes, minor feature upgrades and so on.
The new envelope_limit method is very useful since it keeps you from
sending 15,000 addresses in one envelope to yahoo or aol or whatever.
That'd probably give you an error.
This is definitely a must-have upgrade for 2.04 users.
2.05 Tues Oct 3, 2000
- Added envelope_limit accessor.
- You can now set more defaults yourself.
- Cleaned up the documentation a lot.
- Re-wrote the date generation methods. They're now 5-10%
faster and I fixed an *old* bug causing mail to sometimes
appear to have been sent yesterday, or tomorrow. Oops.
- Altered logging when using the envelope, see item GOOD, in
the docs.
- Fixed a bug with undefined values in mailmerges
------------------------------
Date: Thu, 5 Oct 2000 18:40:50 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: beginner question
Message-Id: <Pine.GSO.4.21.0010051838280.14163-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 5, Gordon Vrdoljak said:
>$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
>
>The best I can see is that the string thisday is assigned to array element 6 of
>localtime function and then the weekday is somehow pulled out of this. Can
>anyone break it down into smaller steps where I can see how the day is assigned?
>Thanks for the help.
@days = qw( Sun Mon Tue Wed Thu Fri Sat );
$dow = (localtime)[6]; # element 6 of the list returned by localtime()
$thisday = $days[$dow];
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Thu, 05 Oct 2000 23:23:26 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: beginner question
Message-Id: <39dd0bf4.1863033@news.newsguy.com>
Larry Rosler <lr@hpl.hp.com> wrote:
>qw(Sun Mon Tue Wed Thu Fri Sat)[...]
> Use the numerical day of the week to extract
> the name from a list of names. I have corrected
> the expression so it doesn't use barewords,
> which would draw a warning.
I think you need another set of parentheses there.
But the original code doesn't draw a warning, because the
barewords are capitalized. Of course, they're still bad style.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 06 Oct 2000 00:37:41 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: beginner question
Message-Id: <slrn8tq7m9.1kv.mgjv@verbruggen.comdyn.com.au>
On Thu, 05 Oct 2000 23:23:26 GMT,
Keith Calvert Ivey <kcivey@cpcug.org> wrote:
> Larry Rosler <lr@hpl.hp.com> wrote:
>
> >qw(Sun Mon Tue Wed Thu Fri Sat)[...]
> > Use the numerical day of the week to extract
> > the name from a list of names. I have corrected
> > the expression so it doesn't use barewords,
> > which would draw a warning.
>
> I think you need another set of parentheses there.
why?
# perl -w
$thisday = qw(Sun Mon Tue Wed Thu Fri Sat)[(localtime)[6]];
print $thisday
__END__
Fri
> But the original code doesn't draw a warning, because the
> barewords are capitalized. Of course, they're still bad style.
There may not be a warning, but there is a fatal error when a pragma
which I consider to be a must for any serious code is included:
strict.
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: Thu, 05 Oct 2000 23:07:24 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Can't lock error
Message-Id: <slrn8tq2da.sv.tjla@thislove.dyndns.org>
I was shocked! How could Smitty <jpsmith@mediom.qc.ca>
say such a terrible thing:
>But the script generates the following after having written the .dat and
>before updating the .html file:
> The following error occurred : can't lock file
>(/netra/home/.../index.html)
>JPSmith (newbie with perl)
It's okay to be a newbie :) What you need to do if you have a problem
here is to post some code that shows the error otherwise we have no way
of knowing what your error might be.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Inform all the troops that communications have completely broken down.
------------------------------
Date: Thu, 05 Oct 2000 23:09:34 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Changing STDOUT
Message-Id: <slrn8tq2h2.1kv.mgjv@verbruggen.comdyn.com.au>
On Thu, 05 Oct 2000 19:39:39 GMT,
Yanick Champoux <yanick@babyl.sympatico.ca> wrote:
> buck_naked@noiname.spamcom wrote:
> : Let's say I have a program where I change STDOUT in order to pipe it
> : through a pager or something:
>
> : open STDOUT "| /usr/local/bin/less";
>
> : Now, let's say I want to go back to the normal setting for STDOUT in
> : the same program. How would I do that?
>
> open STDOUT, ">-" or die "Ouch. Can't open stdout: $!\n";
# perl -w
open(STDOUT, ">/tmp/feebie") or die $!;
print "Line 1\n";
open(STDOUT, ">-") or die $!;
print "Line 2\n";
__END__
# cat /tmp/feebie
Line 1
Line 2
Doesn't work. The special filename '>-' refers to whatever is the
current STDOUT.
For ways that work, please refer to the documentation:
# perldoc -f open
# perldoc perlopentut
Martien
--
Martien Verbruggen |
Interactive Media Division | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd. | spot.
NSW, Australia |
------------------------------
Date: Thu, 05 Oct 2000 23:36:28 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: counter problem HELP
Message-Id: <slrn8tq43q.sv.tjla@thislove.dyndns.org>
I was shocked! How could amy_v@my-deja.com <amy_v@my-deja.com>
say such a terrible thing:
>Hy all,
> I've had a CGI script that has to display a counter on my web page. The
>program works fine creating a file in the cgi-bin directory on my
> server. I've tried to put the counter on my page using an image with
>src=http://my server/cgi-bin/counter.pl, but it doen't work. Also, with
>a right-click on the image I can see the counter opened in a new window,
>but is not what I want.What should I do to have it on my page???
Let me give you a pointer, you probably want to post this to a newsgroup
with the word "CGI" in the title, such as:
comp.infosystems.www.authoring.cgi
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It occurred to me lately that nothing has occurred to me lately.
------------------------------
Date: Fri, 06 Oct 2000 00:26:40 GMT
From: Roy.Ivy.III@nMail.com
To: mr_joesixpack@yahoo.com
Subject: Re: Dumping lexical data structures from scratchpads
Message-Id: <8rj67r$3n5$1@nnrp1.deja.com>
In article <8p3ue5$mih$1@nnrp1.deja.com>,
Paul Laub <mr_joesixpack@yahoo.com> wrote:
> Dear all,
>
> I want a utility like dumpvar.pl to dump out all lexical (ie., "my")
> data structures in the current block of code. Because these data
> structures are stored in scratchpads, not a package's symbol table, I
> don't know how to get at them. Again, I want to dump ALL lexical
> data structures without having to name them.
>
> Such a module is meant to record the state of the system when trouble
> is detected.
>
> Paul
>
> P.S. Potential flame meisters: I have consulted the perl FAQ, searched
> www.perl.com, perused several Perl books, RTFM, and all of that ...
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
I've also been looking into this... more for debugging purposes. Would
you mind dropping me an email if you get any pointers?
Currently, I'm using "our" variables as a partial workaround ("my"-like
variables but accessible from the symbol table). doesn't sound
appropriate for your application though, sorry.
- Roy Ivy
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 05 Oct 2000 22:56:42 GMT
From: post_to_group <already_seen@my-deja.com>
Subject: Re: Forking, Exiting, and Timing out within an Eval
Message-Id: <8rj0v7$vg5$1@nnrp1.deja.com>
In article <sk6D5.23788$td5.4311996@news1.rdc2.pa.home.com>,
"Ben Kennedy" <bkennedy@hmsonline.com> wrote:
>
> Try sprinkling some
>
> print "Line number ", __LINE__ , ": my PID is $$\n";
>
> statements so you know how many processess are executing at any given
point
> in time in your code. This should give you enough diagnostics to
figure out
> the bug
Ben, thanks for the tip - I actually stripped out all my many print $$
and other diagnostic lines just to post a relatively uncluttered code
strangers would peruse.
> exec() will completely replace the current process with the new
process,
> while system() forks off a child process. Perhaps your confusion over
> system() and exec() (combined with several fork()'s) is causing your
process
> headaches -
> --Ben Kennedy
No I am only using system. I had tried exec and noticed the behaviour
which you've confirmed. I was just making sure as some examples used
exec so I thought perhaps there was a way to use it and still have a
timeout/alarm. But the problem remains even though I am only using
system.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 05 Oct 2000 22:35:37 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Formating output to be read in a form.
Message-Id: <slrn8tq0hc.1kv.mgjv@verbruggen.comdyn.com.au>
On Thu, 5 Oct 2000 12:44:50 +0100,
Phil Latio <verybig@thebedroom.co.uk> wrote:
> >Ooh.. what a clever name and email address. Did you have to think long
> >before you came up with that?
>
> I am glad your impressed. Most people think I am just a twat with a stupid
> name.
Hmmm.
> >Learn to type, at your shell prompt, commands starting with perldoc
>
> I don't have shell access.
You don't need shell access. You do have a computer, right? Get the
perl version for your computer and install it. If you have a *nix or
*BSD variant, you'll find that you can just use perldoc on your own
computer. If you have NT or Win*, you'll find you can use perldoc on
your own computer (fire up a command shell, and try it). If you have
the ActiveState distribution, then you also have all the documentation
installed as HTML.
If you're on a macintosh, you also have all the documentation, and
there should be an application called Shuck (or something like that)
that gives you access to it.
You'll even be able to develop all (or most) of your scripts locally,
before having to put them on your ISP's server.
Martien
--
Martien Verbruggen |
Interactive Media Division | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd. | Universe and Reboot +++
NSW, Australia |
------------------------------
Date: Thu, 05 Oct 2000 22:30:58 GMT
From: du_bing@my-deja.com
Subject: Re: how to unlink this file?
Message-Id: <8rivf3$ubk$1@nnrp1.deja.com>
Gary, thanks for all the suggestions. 'Unlink' does support wildcard
processing. unlink<$tmp/${uid}_attach_*> just works perfect.
Bing
In article <8ria3c$fl4@gap.cco.caltech.edu>,
ansok@alumni.caltech.edu (Gary E. Ansok) wrote:
> In article <8ri3e6$4i1$1@nnrp1.deja.com>, <bing-du@tamu.edu> wrote:
> >===============
> >#!/usr/local/bin/perl
> >
> >$tmp = "/usr/home/me/tmp";
> >$uid = "c24b18d4bb4afdf052330678af9a601d";
> >
> >unlink("$tmp/$uid_attach_*") || die "file can not be deleted\n";
> >exit;
> >===============
>
> There's a couple of problems with this:
>
> 1) unlink doesn't take wildcards. You'll need to get the exact name
> of the file (probably using readdir or glob) to pass to unlink.
>
> 2) You need to separate the variable name from the surrounding text.
> There are a couple of ways to do this, but the simplest is probably
> "$tmp/${uid}_attach_".
>
> Some other suggestions:
>
> 3) Use -w and strict.
>
> 4) Change the die string to include $!, which will tell you why
> the file could not be deleted. In a short script like this it
> may not matter, but in a longer script I would put the filename
> in the die message, like "Cannot delete '$file': $!".
>
> 5) You don't say whether this is a one-time action, or something
> you'll need to do repeatedly, and we don't know what system(s) you
> will need to run this on. Assuming a Unix system, you might just
> want to use the "rm" program and shell wildcard processing --
> system qq(rm "$tmp/${uid}_attach_*"). Sometimes it is simpler
> to use existing tools outside Perl.
>
> -- Gary Ansok
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 5 Oct 2000 15:50:52 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to unlink this file?
Message-Id: <MPG.1446a5a5a142b5ee98ae13@nntp.hpl.hp.com>
In article <8rivf3$ubk$1@nnrp1.deja.com> on Thu, 05 Oct 2000 22:30:58
GMT, du_bing@my-deja.com <du_bing@my-deja.com> says...
> Gary, thanks for all the suggestions. 'Unlink' does support wildcard
> processing. unlink<$tmp/${uid}_attach_*> just works perfect.
It isn't 'unlink', which simply takes a LIST argument. It is the
general globbing construct <...> that produces the LIST.
<SNIP complete quote of previous post. Please don't do that in the
future.>
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 05 Oct 2000 23:03:33 GMT
From: oloryn@mindspring.com (Ben Coleman)
Subject: Re: how to unlink this file?
Message-Id: <39dd0671.91350004@localhost>
On Thu, 05 Oct 2000 22:30:58 GMT, du_bing@my-deja.com wrote:
>Gary, thanks for all the suggestions. 'Unlink' does support wildcard
>processing. unlink<$tmp/${uid}_attach_*> just works perfect.
Technically, unlink doesn't support wildcards. You're using the
fileglob operator to generate a list of filenames. That has nothing
to do the unlink function itself, other than the fact that it does
take a list of filenames. That's OK, but potentially a bit memory
intensive if the glob matches a large number of files.
Ben
------------------------------
Date: Thu, 5 Oct 2000 23:44:43 +0100
From: "Paul Coles" <pr.coles@virgin.net>
Subject: Newbie with HTTP LWP problem
Message-Id: <8rivhq$f66$1@uranium.btinternet.com>
Hi people - im very new to perl and never used newsgroups.
If someone could help I would really appreciate it.
Sorry if its already been answered before i got here!!!
I would like to mimick this HTML
<HTML>
<BODY>
<form method=POST action='http://www.telecom.paper.nl/OS/inp.asp'>
<Input type=hidden name=country value=840>
<Input type=hidden name=posted value=true>
<Input type=submit value="Search">
</form>
</BODY>
</HTML>
It would then be nice if i could extract the country numbers and data only
from the table but i think this is way beyond my perl skills, just dumping
the html in a text file and processing it using a different language is
going to be my limit.
I first thought LWP::Simple and use getstore but the form is a POST method
form so you cant pass the parameters on the url line.
I think the answer may be to use HTTP::Request but im not sure and cant get
it to work.
here's what i have tried, but it doesnt work :-(
use LWP::Simple;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new();
my $req = POST 'http://www.telecom.paper.nl/os/inp.asp', [ country => 840,
posted=>1, submit =>'Search'];
$content = $ua->request($req)->as_string;
print($content)
Thanks for any help.
------------------------------
Date: Fri, 06 Oct 2000 00:20:27 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Newbie with HTTP LWP problem
Message-Id: <39DD1AD0.4E3127E0@rochester.rr.com>
Paul Coles wrote:
...
> here's what i have tried, but it doesnt work :-(
>
> use LWP::Simple;
> use HTTP::Request::Common qw(POST);
> use LWP::UserAgent;
> $ua = LWP::UserAgent->new();
> my $req = POST 'http://www.telecom.paper.nl/os/inp.asp', [ country => 840,
> posted=>1, submit =>'Search'];
> $content = $ua->request($req)->as_string;
> print($content)
>
> Thanks for any help.
Well, I'm not sure what you mean by "doesn't work". When I try your
code verbatim, it prints out a whole bunch of HTML. Does that
constitute "working"? If so, then it works for me.
--
Bob Walton
------------------------------
Date: 5 Oct 2000 23:34:05 GMT
From: dha@panix.com (David H. Adler)
Subject: OT - silly (was: Re: A matter of style (was Re: Search and Destroy))
Message-Id: <slrn8tq3vd.r4c.dha@panix2.panix.com>
On Wed, 04 Oct 2000 20:48:22 GMT, David Steuber
<nospam@david-steuber.com> wrote:
>--
>David Steuber | Perl apprentice, Apache/mod_perl user,
>NRA Member | and general Internet web wannabe.
You want to be a general internet web???
dha, ducking and running...
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You're quite free to convert your strings to byte arrays and do the
entire pattern tree by hand in pure logic code if you'd like. By the
time you finish most of the rest of us will be doing contract work on
Mars." - Zenin on comp.lang.perl.misc
------------------------------
Date: Thu, 05 Oct 2000 23:08:24 GMT
From: yin@itginc.com
Subject: Perl embeding without creating dll
Message-Id: <8rj1l4$19$1@nnrp1.deja.com>
I have successfully create a dll with XS, so I could use perl to
create/access the C++ object in perl. But now I need to create/access
the
c++ object with perl within the same program(that means not to use a
dll).
and I decided to make function calls to create/access the c++ object.
The question is how can I use perl to call a C/C++ function in a program
with out putting that function into a dll?
Any kind comments are welcome.
Wei
cc the comments to yin@itginc.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 06 Oct 2000 10:37:21 +1000
From: Dave O'Brien <david.obrien@ssmb.com.au>
Subject: Re: Quirk of strict ??
Message-Id: <39DD1EC1.1FFB8B96@ssmb.com.au>
Uri Guttman wrote:
>
> >>>>> "DO" == Dave O'Brien <david.obrien@ssmb.com.au> writes:
>
> >> use strict;
> >> $a = "thing1";
> >> $b = "thing2";
> >> $c = "thing3";
> >>
> >> Global symbol $c requires explicit package name at ./t1.pl line 6.
> >>
> >> This I understand but why not similar error messages for $a and $b ?
> DO> You have to declare variables with the my operator e.g.
>
> DO> my $c = "thing3";
>
> you missed his point. he asked why only $c and not $a and $b generated
> the error message. another poster gave the correct answer.
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
> The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net ---------- http://www.northernlight.com
My bad, sorry
------------------------------
Date: Fri, 06 Oct 2000 11:18:08 +1100
From: Barry <barry.allebone@DB.COM>
To: japhy@pobox.com
Subject: Re: Quirk of strict ??
Message-Id: <39DD1A40.8B84FB95@DB.COM>
Jeff Pinyan wrote:
> [posted & mailed]
>
> On Oct 5, Barry said:
>
> > #!/usr/local/bin/perl -w
> > use strict;
> > $a = "thing1";
> > $b = "thing2";
> > $c = "thing3";
> >
> >Global symbol $c requires explicit package name at ./t1.pl line 6.
> >This I understand but why not similar error messages for $a and $b ?
>
> $a and $b are safe from strict vars because they are globals used in
> sort().
>
> perldoc -f sort
>
> --
> Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
> PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
> The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
> CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
Thanks to everyone who responded, especially Jeff, who also emailed me. Now
that I know where to look I even found the reference in Programming Perl.
However it begs a couple of questions:
a) How many more such critters are there ?
b) Why weren't $a and $b implemented as global special variables ?
------------------------------
Date: Fri, 06 Oct 2000 00:04:59 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Reading file into an array
Message-Id: <4a08f0f887g.soper@soundhouse.co.uk>
I have a multi-line file which I wish to read in. I am using the following
segment of code to achieve this. The print lines are to aid my debugging.
An HTML header has already been printed. This results in 'template_line =
' being printed twice with no value for $template_line from the second
print line but the first print prints the file out perfectly into STDOUT.
Can anybody suggest what I am doing wrong?
Thanks
open (NEWSTEMPLATE, "$template_file") || die "can't open file: $!";
my @template_lines = <NEWSTEMPLATE>;
print "@template_lines<br>";
foreach $template_line (@template_lines) {
print "template_line = $template_line<br>";
if ($template_line =~ /<--begin-->/) {
The file is shown below:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>User administration</TITLE>
</HEAD><BODY><H1>News</H1>
Start insertion
<br>
<--begin-->
<br>
End insertion
</BODY></HTML>
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Thu, 05 Oct 2000 23:35:00 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Reading file into an array
Message-Id: <slrn8tq40o.1kv.mgjv@verbruggen.comdyn.com.au>
On Fri, 06 Oct 2000 00:04:59 +0100,
Geoff Soper <g.soper@soundhouse.co.uk> wrote:
> I have a multi-line file which I wish to read in. I am using the following
> segment of code to achieve this. The print lines are to aid my debugging.
> An HTML header has already been printed. This results in 'template_line =
> ' being printed twice with no value for $template_line from the second
> print line but the first print prints the file out perfectly into STDOUT.
>
> Can anybody suggest what I am doing wrong?
Well, first of all, you don't post a complete code example. I suspect
that instead of inserting actual code, you retyped this. Your code
doesn't run under strict, unless you've got variables in scope that
are not part of the code you submit.
Apart from that, the code you show below (with some fixes), works
perfectly fine.
> open (NEWSTEMPLATE, "$template_file") || die "can't open file: $!";
> my @template_lines = <NEWSTEMPLATE>;
Useless use of quotes.
> print "@template_lines<br>";
Don't debug stuff inside of a web server. Do it from the command line.
> foreach $template_line (@template_lines) {
>
> print "template_line = $template_line<br>";
>
> if ($template_line =~ /<--begin-->/) {
That is not an HTML comment, I hope you didn't intend it to be one.
The following script does what you want, and is (apart from some minor
changes) identical to the code you submitted. I haven't even made it
run under strict.
#!/usr/local/bin/perl -w
#use strict;
$template_file = '/tmp/feebie';
open (NEWSTEMPLATE, $template_file) or die "can't open file: $!";
my @template_lines = <NEWSTEMPLATE>;
close NEWSTEMPLATE;
print @template_lines;
foreach $template_line (@template_lines) {
print "template_line = $template_line";
}
Could you please reduce your program to the smallest possible amount
of code that displays the problem, and submit that?
Another note: If you're going to process the file line by line, why do
you read it into an array at all?
open (NEWSTEMPLATE, $template_file) or die "can't open file: $!";
while (my $line = <NEWSTEMPLATE>)
{
# do stuff
}
close NEWSTEMPLATE;
Martien
--
Martien Verbruggen |
Interactive Media Division | Hi, John here, what's the root
Commercial Dynamics Pty. Ltd. | password?
NSW, Australia |
------------------------------
Date: Fri, 06 Oct 2000 00:12:25 GMT
From: adaptivetechnologies@my-deja.com
Subject: Re: RegEx: I'm stumped
Message-Id: <8rj5d6$34d$1@nnrp1.deja.com>
> > I'm writing a script that processes some html
code. Among other
> > things it must do is convert this bit of
html &Amp; to a simple &. I
> > first started with
> >
> > s/&Amp;/&/
> >
> > this did nothing. I admit RegExs are one of
my weak points. What am
> > I doing wrong?
> >
> > jar@mminternet.com
> > James A Roush
I've come across that problem many times before.
Since there are so many special codes in Perl for
non-alphabet characters, I usually preface all of
them with the \ character, so Perl knows that
it's supposed to be the absolute character after
it. Perhaps
s/\&Amp\;/\&/
will work.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 06 Oct 2000 00:45:05 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: RegEx: I'm stumped
Message-Id: <slrn8tq845.1kv.mgjv@verbruggen.comdyn.com.au>
On Fri, 06 Oct 2000 00:12:25 GMT,
adaptivetechnologies@my-deja.com <adaptivetechnologies@my-deja.com> wrote:
[Fixed miswarapped lines]
>
> > > I'm writing a script that processes some html code. Among other
> > > things it must do is convert this bit of html &Amp; to a simple
> > > &. I first started with
> > >
> > > s/&Amp;/&/
This should work fine. Watch:
# perl -wl
$_ = 'Some text with &Amp; in it';
s/&Amp;/&/;
print
__END__
Some text with & in it
#
> > > this did nothing. I admit RegExs are one of my weak points. What am
> > > I doing wrong?
Nothing. As demonstrated, it works fine. Did you have your string in
$_? Do you know that if you don't, that you have to bind the subst to
the variable that contains your string?
$foo =~ s/&Amp;/&/;
# perldoc perlop
> I've come across that problem many times before.
> Since there are so many special codes in Perl for
> non-alphabet characters, I usually preface all of
> them with the \ character, so Perl knows that
> it's supposed to be the absolute character after
> it. Perhaps
>
> s/\&Amp\;/\&/
>
> will work.
Why didn't you test things before coming up with wild conjectures? The
original regex was fine. The substitution was fine. Needlessly
escaping characters is just silly. It makes your regex unreadable for
no reason. If you want all characters to be escaped, but you don't
want to have to remember which ones you _need_ to escape, use
quotemeta() or use the \Q and \E protections.
s/\Q&Amp;/&/;
# perldoc perlre
# perldoc -f quotemeta
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4533
**************************************