[10820] in Perl-Users-Digest
Perl-Users Digest, Issue: 4421 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 14 15:07:33 1998
Date: Mon, 14 Dec 98 12:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Dec 1998 Volume: 8 Number: 4421
Today's topics:
Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/) (Tad McClellan)
Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/) (Ronald J Kimball)
Re: a simple puzzle (I suspect) (Ronald J Kimball)
Re: a simple puzzle (I suspect) (Ronald J Kimball)
Re: a simple puzzle (I suspect) <uri@ibnets.com>
Re: Attach a file with a index-related filename (Randy Kobes)
Re: CGI Redirection <gellyfish@btinternet.com>
Date validation (Bill Moseley)
eq to. <jamie@powernetonline.com>
Re: eq to. <jeromeo@atrieva.com>
Re: eq to. <jeromeo@atrieva.com>
Re: Finding what Package my Var is in with Debugger (Ronald J Kimball)
Re: foo bar <metalmd@earthlink.net>
Re: foo bar <garethr@cre.canon.co.uk>
GUI programming <kar@webline.dk>
Re: Left and right halves of s/// parsed differently? chess@watson.ibm.com
length and width info from image files (J. Roy Andrada)
Re: length and width info from image files (Randy Kobes)
Re: length and width info from image files <postmaster@castleamber.com>
Re: Multidimentional arays??? <r28629@email.sps.mot.com>
Re: Newbie Question (Joergen W. Lang)
Re: preserving case insensitive after splitting a strin (Larry Rosler)
Re: returning a socket handle or undef from a sub? <jay@rgrs.com>
Re: Script to Convert Text to HTML <gellyfish@btinternet.com>
Re: Stripping of the _ <r28629@email.sps.mot.com>
Re: timelocal and localtime with negative values? <gellyfish@btinternet.com>
wanted: form that calculates totals goodtimeweb@my-dejanews.com
Re: Why Is Perl not a Language? (Ronald J Kimball)
Works in debuger, not in interpreter <penniman@cats.ucsc.edu>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 14 Dec 1998 07:50:59 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/)
Message-Id: <345357.f25.ln@magna.metronet.com>
Emmett McLean (emclean@slip.net) wrote:
: Randal asked ?
: >In what way did "read the FAQ" disparage you?
: Then continued ...
: > It was accurate and to
: >the point.
: Then this statement :
: >>> Please stop swimming upstream... you missed the spawning season. :)
: The latter statment is clearly meant to be disparaging. A chartible
: reading would be the comment doesn't make sense
That's the problem with using metaphors.
Some folks will not discern the parallels.
So let's restate it in plain language:
Please stop trying to use a regular expression to match
only valid email addresses... it cannot be done.
Randal was trying to help you avoid spending time attempting
the impossible.
: and an unchartible reading
: might be something like advice Clinton could have used two years ago.
Bill tried to match email addresses with a regex?
If that was his offense, censure would be enough ;-)
: My guess is that you are leaning toward the second interpretation.
My guess is that you have no history of reading Randal's
past postings. Many folks here are snipers (e.g me, when
I'm being an ass), but Randal is not one of those folks.
: Hardly a comment which might be described as accurate.
: >Emmett> Just a comment. Aside from the fact that no one has bothered
: >Emmett> to post the FAQ in a long time.
: >
: >The FAQ doesn't get posted because it is INCLUDED with your copy of
: >Perl.
: Not mine.
You have a broken perl.
It is not unreasonable for us to expect that posters to the
Perl newsgroup have a good perl installed.
It is not *our* fault that your perl is misconfigured.
: >
: Yes, I attached an exasparated comment to the end because
: >I've seen this mis-question and mis-answer all too often here.
: Since you see it so often, perhaps you'd be better off if you
: took a break form the newsgroup instead of ignoring the reality
: of new user's questions and posts.
If he doesn't correct mis-answers then they will propogate.
Correct is better than incorrect. But maybe that's just me...
: Accepting reality
: instead of fighting it will leave you with more energy
Good advice.
The reality is that you are expected to make some small effort
yourself to answer the question before posting. Like doing
a word search in the FAQ.
This is a Usenet-wide ethos. Nothing particular to c.l.p.misc
there (though the volume of posts here amplifies its importance).
: but I also expect new users to QUICKLY
: >understand that there are FAQs and Dejanews available for first-line
: >research before posting worn-out questions word-for-word and wasting
: >*all* our time with it.
: Just because someone asks a question doesn't mean they haven't
: come up to speed quickly.
Asking a question that is clearly answered in docs already on
their hard drive does indeed indicate that they are not yet
up to speed.
: >Emmett> In my case I researched the question for over a half hour with
: >Emmett> Wall's text and didn't come up with an answer.
: >
: >Yes, I am intimately familiar with that text, and I can assure you
: >that the answer is not there. :)
: >
: Hum, first you complain I didn't read the FAQ then you agree that the
: answer is not there.
Huh?
The answer is not in Programming Perl.
Programming Perl is not the Perl FAQ.
: >Emmett> A half hour is about
: >Emmett> as much as most people spend researching a question which has
: >Emmett> a very simple answer.
: >
: >Precisely. But five minutes with Dejanews would have found your
: >answer in six minutes. So why did you waste 24 other minutes?
: >Seriously.
: >
: My read on it is that, to you, the *seriously* part has more
: to do with flaming and much less to do with talking about Perl.
No metaphor there, just plain language.
The "seriously" means he really wants to know why you want to
spend 30 minutes rather than 6 minutes to find your answer.
Seems non-productive, leaves us all wondering why that
approach would be preferred...
: >Emmett> So if you're an advanced user and you've seen the question in the FAQ
: >Emmett> and you don't want to respond, don't. Just skip it. Leave the
: >Emmett> question for other, perhaps new, newsgroup participants.
You want answers from new folks rather than from experienced folks?
You are very likely to get lower quality answers that way.
I cannot fathom why that would be desired...
: >No, I'm correcting a mis-answer also in this thread. I hate this FAQ
: >because it gets answered WRONG frequently as well. Mostly from other
: >well-meaning but underinformed posters.
: >
: I supposed the Perl FAQ says that you've been appointed you the
: Perl king of c.l.p.m.
See? It is easy to slip into sniping rather than discussing...
Pot. Kettle. Black.
: I newsgroup is enhanced when it gets well-meaning but underinformed posts.
Can you give at least one reason to support your assertion?
I don't see how wrong answers are enhancing.
I would like to be able to understand your point of view, but
I cannot if you don't try to explain your point of view.
: >Emmett> While I appreciate the help offered in answers to my questions
: >Emmett> I think some of the people in this group should lighten up. Either
: >Emmett> that or some day we'll be programming in Visual Basic.
: >
: >In fact, I find these days that most of the time, I'm merely
: >correcting or augmenting the mis-1answers of others, and I still find
: >it necessary to do that about three to five times a day. If you'd
: >actually like me to go away, I can do that (maybe :), but then you'll
: >be left with not just NO information, but INCORRECT information.
: Yes, go away.
Flamage again?
If it is OK for you to do it, then it is OK for others to do it,
so what's your gripe?
: That would be best.
That would not be best.
Please stay Randal.
We'll just wait a few weeks until Emmett goes away.
: I'd appreciate answers and helpful suggestions
: but don't look forward arrogance, grumpy posts and disparaging comments.
You can avoid those by simply not reasking Frequently Asked Questions.
: You are certainly kidding yourself if you think you are the *only*
: person having correct information about Perl. That is a laugh.
: >Do you really want that? I don't think so.
: Absolutely. If it is difficult for you to tolerate the posts of new users
: you should pass.
There you go again.
Randal tolerates posts of new users just fine.
He does not tolerate incorrect answers to Frequently Asked Questions.
This is a Good Thing.
: We're here to talk about Perl, and if some
: career Perl programmer is offended because after a half hour of research
: I didn't review my non existent perl documentation, and I didn't do a useless
: query on dejanews then what's the big deal? If you aren't posting to help
: Perl users, and you're just the FAQ cop, then just don't post.
Make a killfile entry for people whose posts you don't want to see.
Whenever you notice that a poster seems to know what they are
talking about, killfile them.
Then you will have your desired newsgroup where inexperienced
people attempt to help inexperienced people.
Problem solved!
: I've noted this isn't the only thread where new users have been discouraged
: from posting and disparaged.
It is *not* new users that are disparaged.
It is *not* new users that are disparaged.
It is *not* new users that are disparaged.
It is askers of Frequently Asked Questions that are disparaged.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 13 Dec 1998 01:55:27 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/)
Message-Id: <1djyc7c.5vkxdg1smehpoN@bay1-443.quincy.ziplink.net>
Emmett McLean <emclean@slip.net> wrote:
> The code below :
>
> ($e_mail !~ /\w+[-\w]*\@\w+[-\w]*\.\w+/)
>
> is supposed to check that an $email is
> of the form aaa@somedomain.xxx but
> returns true even if
>
> $e_mail="ok.com" .
Actually, that code checks that an $e_mail is *not* of the form
aaa@somedomain.xxx. In other words, it returns true when the email
address is 'invalid', and false when the email address is 'valid'. [*]
To get true for 'valid' addresses, change the !~ to =~.
!~ is basically !($str =~ /re/).
> So I have two questions :
>
> 1. What does the minus sign in the brackets do ?
Because the hyphen is the first character in the brackets, it means a
literal hyphen. This allows the regex to match email addresses like:
aaa-bbb@some-domain.com.
> and
>
> 2. Does anyone have a suggested modification?
Please refer to the FAQ.
perlfaq9: How do I check a valid email address?
[*] There are valid email addresses that this regex will not match.
In fact, this regex is even worse than what people usually try
to use. It won't even match either of my obviously valid
email addresses (see sig).
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sun, 13 Dec 1998 01:28:06 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: a simple puzzle (I suspect)
Message-Id: <1djybcw.1jb5uwi123s0dsN@bay1-443.quincy.ziplink.net>
[posted and mailed]
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
> >
> > s/$pre\((.*?)\)/$pre(\L$1)/;
> >
> > In case the parentheses following $pre are empty.
>
> Is it a Unicode addition that one can meaningfully uppercase an empty
> string?
Sorry, Ilya, but changing the case of the empty string is not the issue.
$pre = 'CELL';
while (<DATA>) {
s/$pre\((.+?)\)/$pre(\L$1)/; # Original, with plus
print;
}
__END__
CELL() # Don't change case here (OOPS!)
And the output is:
CELL() # don't change case here (oops!)
Do you really think that was the desired result?
(By the way, if a negated character class had been used instead of
non-greedy matching, this would not have been an issue.
s/$pre\(([^\)]+)\)/$pre(\L$1)/;)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sun, 13 Dec 1998 01:28:07 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: a simple puzzle (I suspect)
Message-Id: <1djybgk.lzqlw2q9dif4N@bay1-443.quincy.ziplink.net>
Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "RJK" == Ronald J Kimball <rjk@linguist.dartmouth.edu> writes:
>
> RJK> Uri Guttman <uri@sysarch.com> wrote:
>
> >> s/$pre\((.+?)\)/$pre(\L$1)/;
>
> RJK> s/$pre\((.*?)\)/$pre(\L$1)/;
>
> RJK> In case the parentheses following $pre are empty.
>
> well, he didn't say that was possible. given the input examples, + seems
> like a better choice.
You should know better than that, Uri.
"Well, I tested it with three different inputs, and it worked every
time, so there must not be any bugs in my program, right?"
Using plus, there are demonstrable cases in which the substitution does
not give the desired result. Using asterisk, the substitution gives the
desired result in all cases.
Explain to me again why plus is the better choice...
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 14 Dec 1998 14:13:57 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: a simple puzzle (I suspect)
Message-Id: <39n24qmt8q.fsf@ibnets.com>
>>>>> "RJK" == Ronald J Kimball <rjk@linguist.dartmouth.edu> writes:
RJK> Uri Guttman <uri@sysarch.com> wrote:
RJK> s/$pre\((.*?)\)/$pre(\L$1)/;
RJK> In case the parentheses following $pre are empty.
>> well, he didn't say that was possible. given the input examples, +
>> seems like a better choice.
RJK> Using plus, there are demonstrable cases in which the
RJK> substitution does not give the desired result. Using asterisk,
RJK> the substitution gives the desired result in all cases.
RJK> Explain to me again why plus is the better choice...
i am assuming no null strings in (). maybe that is wrong but the original
poster didn't say anything about it. and changing the case of a null
string is a noop anyway. if a null string is possible then + would break
and * is right.
i wouldn't do any production code with either until i had a definite
spec, so both are viable solutions, given the short input set.
uri
--
Uri Guttman Hacking Perl for Ironbridge Networks
uri@sysarch.com uri@ironbridgenetworks.com
------------------------------
Date: 14 Dec 1998 18:38:04 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: Attach a file with a index-related filename
Message-Id: <slrn77an9o.g72.randy@theory.uwinnipeg.ca>
On Mon, 14 Dec 1998 16:26:16 +0100, Marcel Beekmans <beekmans@iae.nl> wrote:
>
>I know it is possibility to attach a file to an email by using
>MIME::Lite. That is if you know the exact filename. You can write it
>down in the Path => ".... "; statement. But what if the filename is
>depanding on an index-number. I tried the following code, but it isn't
>working coorectly because you probably may not put a variable name in
>the Path => " ...." statment.
>
>The example, which isn't working
>----------------------------------------------
>#!/usr/local/bin/perl -w
>
>use MIME::Lite;
>use Net::SMTP;
>use strict;
>use CGI qw(:standaard);
Hi,
You probably want qw(:standard) here ...
[snip]
>#this part isn't working correctly, because of the $filetosend parameter
>
>attach $msg
> Type => 'text/plain',
> Encoding => '8bit',
> Path => 'D:\Inetpub\hypotheekplein\cgi-bin\$filetosend';
What if you tried it with " " quotes, rather than ' '? Things
within ' ' are taken literally, so '$filetosend' won't take on
whatever value $filetosend might have. With this, you may also have to
escape the \ directory separators (ie, use \\), so that they aren't
interpreted as escaping the following character - alternatively, you
might be able to just use the Unix-style / directory separator.
Also, most people in this group prefer plain text messages -
you might want to change your newsreader configuration to post
that way by default.
--
Best regards,
Randy Kobes
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, Manitoba R3B 2E9 e-mail: randy@theory.uwinnipeg.ca
Canada http://theory.uwinnipeg.ca/
------------------------------
Date: 14 Dec 1998 18:40:06 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: CGI Redirection
Message-Id: <753m26$2p5$1@gellyfish.btinternet.com>
On Mon, 14 Dec 1998 00:06:51 -0600 Adam Levy <adrade@wwa.com> wrote:
>
> Two good ways:
>
> 1. With Perl:
> ------------
> #!/usr/local/bin/perl
>
> $newpage = "http://www.perl.org/";
> print "$newpage\n\n";
> 1;
> ------------
I'll assume you meant
print "Location: $newpage\n\n";
there (or perhaps some other header :)
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 14 Dec 1998 19:43:38 GMT
From: moseley@best.com (Bill Moseley)
Subject: Date validation
Message-Id: <36756a6a$0$203@nntp1.ba.best.com>
Is there a 'common' way to validate input dates?
I'm currently using timelocal() from Time::Local to convert a text date to
time() seconds, then back to text with localtime() to compare with the
original date to see if it is valid.
This catches 2/29/99, for example.
Is there a small module that will do this work for me?
Thanks,
--------------
Bill Moseley
moseley@best.com
------------------------------
Date: Mon, 14 Dec 1998 12:28:51 -0600
From: "jamie dolan" <jamie@powernetonline.com>
Subject: eq to.
Message-Id: <ORcd2.1376$ww5.104954@homer.alpha.net>
HI,
I am going to have a script that will be given any one of around 400
variables. So my script would start out like so:
#!/usr/bin/perl
$CODE = 'variable';
I am wondering what the best way to check the variable and run a command.
For example is the best way to use something like this:
if $CODE eq 1000 do
script that will run;
done
if $CODE eq 1001 do
script that will run;
done
And 398 more of these, most of them will do differnt things.
Is there a better way to do this since I am going to have around 400
variables possible and the script may run several times a minute so I need
something that can finsh execuation is a reasonable amount of time.
What is the best way to do this?
------------------------------
Date: Mon, 14 Dec 1998 10:47:02 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: jamie dolan <jamie@powernetonline.com>
Subject: Re: eq to.
Message-Id: <36755D26.3C031743@atrieva.com>
jamie dolan wrote:
> if $CODE eq 1000 do
> script that will run;
> done
>
> if $CODE eq 1001 do
> script that will run;
> done
>
> And 398 more of these, most of them will do differnt things.
> What is the best way to do this?
My prefered method is to use a hash with $CODE as the value, and a
reference to the desired subroutine as the value. You can then execute
the desired subroutine based upon the key value. This assumes that all
your subroutines accept and return similar values. See perlref and
perlsub for more intimate detail.
Example:
my(%routines) = (
'100' => \&onehun,
'200' => \&twohun,
);
my($return) = &{$routines{$CODE}}();
sub onehun(){ # 100 stuff };
sub twohun(){ # 200 stuff };
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Mon, 14 Dec 1998 10:54:11 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: eq to.
Message-Id: <36755ED3.7F6E6A27@atrieva.com>
Jerome O'Neil wrote:
> My prefered method is to use a hash with $CODE as the value, and a
> reference to the desired subroutine as the value.
For those speaking english this morning, that should be:
My prefered method is to use a hash with $CODE as the key...
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Sun, 13 Dec 1998 01:55:28 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Finding what Package my Var is in with Debugger
Message-Id: <1djycny.ys1yq51kus7tnN@bay1-443.quincy.ziplink.net>
<narins@my-dejanews.com> wrote:
> My program does _not_ explicitly create multiple packages.
>
> In a subroutine called by another subroutine I set a variable.
>
> In the debugger (which I am finding pretty handy dandy at trying fix up this
> other guy's code) if I try
> > x $the_var_in_question
> I get the correct answer. However, if I try
> > x $main::the_var_in_question
> I get
> undef.
>
> So, my question is how do I figure out what package it is in?
$the_var_in_question is not in any package, because $the_var_in_question
is a lexical variable [as in my($the_var_in_question)].
Refer to perlsub, under "Private Variables via my()":
Variables declared with "my" are not part of any package and are
therefore never fully qualified with the package name.
Hope that helps!
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 14 Dec 1998 09:34:50 -0800
From: Marc <metalmd@earthlink.net>
Subject: Re: foo bar
Message-Id: <36754C3A.82345B01@earthlink.net>
It's fubar, if you're referring to the Private Ryan movie. Not sure if it
is the same thing here, but it probably is. And it means f#$%^ up beyond
all recognition. You can add it the first word.
Marc
Todd Smith wrote:
> where's this foo-bar stuff come from? I heard it in that "Search for
> Private Ryan" movie. What's it mean?, and what's it got to do with Perl?
>
> --
> _______________
> Todd Smith
> Perl Programmer
> ITC^Deltacom
------------------------------
Date: Mon, 14 Dec 1998 18:39:05 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: foo bar
Message-Id: <sibtl6in5i.fsf@cre.canon.co.uk>
Todd Smith <tbsmith@viper.net> wrote:
> Where's this foo-bar stuff come from?
"Foo" and "bar" are metasyntactic variables (placeholders in examples
standing in for the real names), and nonces (names for things which are
hard to think up good names for, like temporary files).
The etymologies are discussed in some detail at
http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?foo, which says
The etymology of "foo" is obscure. When used in connection with "bar"
it is generally traced to the WWII-era Army slang acronym FUBAR, later
bowdlerised to foobar.
However, the use of the word "foo" itself has more complicated
antecedents, including a long history in comic strips and cartoons.
...
--
Gareth Rees
------------------------------
Date: Mon, 14 Dec 1998 10:25:45 +0100
From: Kaare Rasmussen <kar@webline.dk>
Subject: GUI programming
Message-Id: <3674D999.E2BE048D@webline.dk>
I need a good advice.
I'm planning to code an accounting program with Perl. The goal is that
it can run under different GUI's, but I have to start one place.
So what is easiest to start with. I know there are interfaces for Qt
(though not updated for a year or so), Gtk, NCurses, HTML and Tk,but I
don't know the strengths and weaknesses.
The best is that there is easy support for a grid (or spreadsheet),
because an accounting program uses that kind of interface a lot.It must
be easy to create screens and control them. And I'd prefer a GUI over
NCurses because of the pleasant look :-)
Can anyone advice me?
------------------------------
Date: Mon, 14 Dec 1998 18:05:25 GMT
From: chess@watson.ibm.com
Subject: Re: Left and right halves of s/// parsed differently?
Message-Id: <753k15$agn$1@nnrp1.dejanews.com>
In article <1djuhnz.1n55fl72y62gvN@bay1-511.quincy.ziplink.net>,
rjk@linguist.dartmouth.edu (Ronald J Kimball) wrote:
> > So neither \Q nor quotemeta lets me see the two characters \t in the output.
>
> What two characters \t???
This is the same confusion that I originally had about quotemeta() and
such. I expected it to behave like Data::Dumper::Useqq(1), converting
tabs into '\t', rather than into "\\\t" (if you get my drift). Escapes
in general are awful confusing!
I think my original confusion had to do with the fact that in
s/big\\noses/large\\eyes/
you have the same level of escaping and quoting and such in each
half of the s///, whereas when you do variable substitution, the
version that works:
s/\Q$this\E/$that/
has different levels of escapage in the different halves. I think
I now understand the low-level reason for it; I still don't really
grok a higher-level strategy-like explanation. (As the Camel book
says, Perl does what you expect, as long as what you expect isn't
consistency!)
DC
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 14 Dec 1998 18:29:55 GMT
From: jroyNOSPAM@Eng.Sun.COM (J. Roy Andrada)
Subject: length and width info from image files
Message-Id: <753lf3$qk$1@engnews2.Eng.Sun.COM>
Hi,
Hopefully someone out there can help me. I have gif
and jpeg images which I want to display on an HTML
page. However, I want to control the display size
in proportion to the actual image size.
I have a perl script that will generate the HTML
page for me. But I don't know how to read the length
and width information of the image file.
First of all, is it possible to extract this
information from an image file such as GIF and JPEG?
Secondly, if it is, can you please show me how to
do this with PERL?
Thanks in advance.
regards,
roy
jroyNOSPAM@eng.sun.com: please remove the "NOSPAM" to reply.
------------------------------
Date: 14 Dec 1998 19:03:41 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: length and width info from image files
Message-Id: <slrn77aops.gr1.randy@theory.uwinnipeg.ca>
On 14 Dec 1998 18:29:55 GMT, J. Roy Andrada <jroyNOSPAM@Eng.Sun.COM> wrote:
[snip]
> I have a perl script that will generate the HTML
> page for me. But I don't know how to read the length
> and width information of the image file.
Hi,
You should check out the Image::Size module, available at
http://www.perl.com/CPAN/authors/id/RJRAY/
Examples of its use are contained in the docs.
--
Best regards,
Randy Kobes
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, Manitoba R3B 2E9 e-mail: randy@theory.uwinnipeg.ca
Canada http://theory.uwinnipeg.ca/
------------------------------
Date: 14 Dec 1998 19:20:00 GMT
From: "John Bokma" <postmaster@castleamber.com>
Subject: Re: length and width info from image files
Message-Id: <01be2796$6011a7a0$02521e0a@tschai>
J. Roy Andrada <jroyNOSPAM@Eng.Sun.COM> wrote in article
<753lf3$qk$1@engnews2.Eng.Sun.COM>...
>
> Hi,
>
> Hopefully someone out there can help me. I have gif
> and jpeg images which I want to display on an HTML
> page. However, I want to control the display size
> in proportion to the actual image size.
>
> I have a perl script that will generate the HTML
> page for me. But I don't know how to read the length
> and width information of the image file.
>
> First of all, is it possible to extract this
> information from an image file such as GIF and JPEG?
> Secondly, if it is, can you please show me how to
> do this with PERL?
This works with most[1] GIF files:
sub gif_dim
{
my $name = shift;
local(*FILE);
my $buffer = ' ' x 10;
open(FILE, "$DIR/images/$name.gif") or die "Can't open:
$DIR/images/$name.gif: $!";
binmode(FILE);
read(FILE, $buffer, 10, 0) == 10 or die "Bad GIF: $!";
close(FILE);
my($sig, $w, $h) = unpack("a6 v2", $buffer);
return ($w, $h);
}
This is just an example. I'm not claiming this is the right and/or the
best way to do it (I don't check $sig for example...)
John
[1] AFAIK this is the "screen size", but most GIF creation software
set this to the width and height of the actual GIF, which is I think, not
the right thing to do
--
------------------------------------------------------------------
C A S T L E A M B E R Software Development (Java/Perl/C/CGI)
http://www.castleamber.com/ john@castleamber.com
http://www.caiw.nl/~jbokma/
http://www.binaries.org/ Guide to Program Binaries and Pictures
------------------------------
Date: Mon, 14 Dec 1998 12:40:29 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Marty Landman <marty@catnmoose.com>
Subject: Re: Multidimentional arays???
Message-Id: <36755B9D.805DF64B@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
Marty Landman wrote:
>
> I'm not a C programmer, used to do PL/I and assembler though which have
> very different syntaxes from each other and Perl. The Perl syntax for a
> multidimensional array is apparently just like C's from what you show
> below.
>
> And here's an example:
>
> # from my tic tac toe program
>
> @win[0] = [0,1,2]; # these are row wins
> @win[1] = [3,4,5];
> @win[2] = [6,7,8];
> @win[3] = [0,3,6]; # columnar wins
> @win[4] = [1,4,7];
> @win[5] = [2,5,8];
> @win[6] = [0,4,8]; # diagonal wins
> @win[7] = [2,4,6];
this is array slice you are talking about. Although it works _here_, you
really should say $win[0] = [0,1,2]; (see the '$' sign?). Also, this is
the better way to declare the 'multi-dimemsion' array:
@win = (
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6],
);
> so $win[0][1] eq 1 would evaluate as true, as would $win[4][1] eq 4.
>
> hth
>
> p.s. sounds like you might want to get the Camel book, best money i spent
> in the past half year.
>
You wouldn't regret spending on the llama book too ;-)
-TK
------------------------------
Date: Mon, 14 Dec 1998 20:36:57 +0100
From: jwl@worldmusic.de (Joergen W. Lang)
Subject: Re: Newbie Question
Message-Id: <1dk1m4l.14yd5t8e7a9tiN@host026-210.seicom.net>
E Brown <absent@DIE_SPAMMERamug.org> wrote:
> #!/usr/bin/perl
> use 'Getopt::Std';
>
> now, around Getopt::Std, are those ticks? single quotes?
> i think i've tried every combination possible
> `Getopt::Std' (<tick>Getopt::Std<single-quote>)
> 'Getopt::Std' (<single-quote>Getopt::Std<single-quote>)
> ,etc....
> what's the deal?
just say
#!/usr/bin/perl -w
use Getopt::Std; # no quotes nor ticks whatsoever
and it should be working.
you need quotes if you require() an external file like
require getopt.pl;
but not with use().
Please also make sure to choose a better subject than "Newbie Question"
the next time you post, thanks.
Joergen
--
-------------------------------------------------------------------
"Everything is possible - even sometimes the impossible"
HOELDERLIN EXPRESS - "Touch the void"
-------------------------------------------------------------------
------------------------------
Date: Mon, 14 Dec 1998 11:50:26 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: preserving case insensitive after splitting a string
Message-Id: <MPG.10df0bdc9853942a9898c1@nntp.hpl.hp.com>
In article <36771c83.42747338@news.cyberway.com.sg> on Mon, 14 Dec 1998
14:45:17 GMT, Jason Q. <pigs_can_fly@mindless.com> says...
...
> @array = (bird, hand, worth, bush);
> $string = "bird in hand is worth two in bush";
>
> If ($string contains every element in @array)
> {
> do this;
> }
>
> problem is elements in arrays are variable so I suppose I have to put
> them through a loop. How?
This is a variant on perlfaq4: "How can I tell whether an array
contains a certain element?" As Tom Christiansen says, if the problem
statement includes the words "contains" or "is in", think hash.
#!/usr/local/bin/perl -w
use strict;
my @array = qw(bird hand worth bush);
my %hash;
@hash{ @array } = ();
my $string = "bird in hand is worth two in bush";
my $n = 0;
foreach (split ' ', $string) {
next unless exists $hash{$_} && ++$n == @array;
print "matches all $n words in \@array\n";
last;
}
__END__
This approach assumes that the members of @array don't change, but the
contents of $string do. If that isn't correct, then splitting $string
and populating the hash from it, then looping on @array, would be
faster.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 14 Dec 1998 14:13:03 -0500
From: Jay Rogers <jay@rgrs.com>
Subject: Re: returning a socket handle or undef from a sub?
Message-Id: <8267beleps.fsf@shell2.shore.net>
"Mike Marshall" <removeMike@SinglepointSys.com> writes:
> I'm just learning, but consider this code extract:
>
> ========= MAIN =========
> use strict;
> my $line;
> my $Sock;
>
> $Sock = SocketConnect($host, $port);
> unless ($Sock) { die "Socket Connect failed.\n"; }
> $line = <$Sock>;
>
> =========== sub =================
> # SocketConnect returns a socket handle or 'undef' on error.
> sub SocketConnect() {
> local *S;
>
> #<snip various socket calls preparing to issue a connect()>
>
> unless connect(S, $paddr) {
> warn "connect(): $!\n";
> return undef;
> }
> return *S;
> =================================
>
> This produces the message:
>
> Can't use string ("*main::*") as a symbol ref while 'strict refs' in
> line....<the SocketConnect() call>
Try this:
sub SocketConnect() {
use Symbol qw(gensym);
my $sock = gensym;
#<snip various socket calls preparing to issue a connect()>
unless connect($sock, $paddr) {
warn "connect(): $!\n";
close $sock;
return;
}
return $sock;
}
> Many thanks in advance.
You're welcome.
--
Jay Rogers
jay@rgrs.com
------------------------------
Date: 14 Dec 1998 19:25:59 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Script to Convert Text to HTML
Message-Id: <753oo7$2pv$1@gellyfish.btinternet.com>
On Mon, 14 Dec 1998 11:44:36 EDT sugar@HWS.EDU wrote:
> I would like to know if anyone could help with a script that could take
> the following and convert it to html:
> Monday|Tuesday|Wednesday..
> MDLN|61|35|NW|5|01|70|32|N|12|01
>
What you need is something that use split() to break up your file into
individual fields and then print it out something like:
#!/usr/bin/perl
print <<OOLALA;
<HTML>
<BODY>
<TABLE>
OOLALA
while(<DATA>)
{
chomp;
my @data = split /\|/ ;
print "<TR>\n";
foreach $field (@data)
{
print "<TD>$field</TD>\n";
}
print "</TR>\n";
}
print "</TABLE></BODY></HTML>\n";
__END__
MDLN|61|35|NW|5|01|70|32|N|12|01
Of course I dont understand your data so it probably isnt as want it but
I leave that as an exercise for the reader.
If you dont understand what is happening here then you should check with the
perlfunc manpage.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Mon, 14 Dec 1998 12:44:34 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Stripping of the _
Message-Id: <36755C92.773D3B22@email.sps.mot.com>
hdiwan@diwanh.stu.rpi.edu wrote:
>
> In article <74ukvn$73v@sjx-ixn6.ix.netcom.com>, E-swap wrote:
> >I need to know if there is a simple line of code which will allow me to
> >strip out a _ and replace with a space when I am displaying something. Also
> >to put it back in if I need to elsewhere.
>
> $str=s/_/\s/; # for replacement
> print $str;
>
I have read two posted from you today, and both contain error or
misinfo. Perhaps you need to look closer before making a post again.
-TK
p/s: I original want to send you a private email, but you email address
suggest that it wouldn't get to you.
------------------------------
Date: 14 Dec 1998 18:48:12 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: timelocal and localtime with negative values?
Message-Id: <753mhc$2p8$1@gellyfish.btinternet.com>
On Tue, 8 Dec 1998 16:48:08 -0800 Larry Rosler <lr@hpl.hp.com> wrote:
>
> So this is Yet Another Y2038 bug. I must admit that I don't much care.
> :-)
>
Except of course if they finally iron the the problems out of cryogenics :-0
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Mon, 14 Dec 1998 19:42:40 GMT
From: goodtimeweb@my-dejanews.com
Subject: wanted: form that calculates totals
Message-Id: <753png$fk3$1@nnrp1.dejanews.com>
i am looking for someone who can make one of forms in our website calculate
totals. the form is all set up and was created using frontpage. you can
check it out at:
http://www.goodtimeweb.com/clientwebsites/aan/order/ordformfrm.htm. we just
need to know the price and how long it will take. it is needed by tuesday
12/15/98. my email address is roger@goodtimeweb.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sun, 13 Dec 1998 01:55:30 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Why Is Perl not a Language?
Message-Id: <1djyd5k.1nf873v663zx0N@bay1-443.quincy.ziplink.net>
Bart Lateur <bart.lateur@skynet.be> wrote:
> *My* Perl "programs" usually don't have a user interface. Just a command
> line. Most of them serve to process/convert files. Compare that to, say,
> a spreadsheet program.
Huh? If your program doesn't have a user interface, how do you run it?
How does it know which files to process/convert?
"User Interface" by no means implies that a program has to
*continuously* accept input from the user.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 14 Dec 1998 10:34:42 -0800
From: Mark Penniman <penniman@cats.ucsc.edu>
Subject: Works in debuger, not in interpreter
Message-Id: <36755A42.80B181D3@cats.ucsc.edu>
This is a multi-part message in MIME format.
--------------62C547672CB43A1CC1EF62C0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
My personal perl knowledge basis is about 1 month old. My programming
knowledge basis is about 20 years. The perl code I have written works
fine in the perl debugger if I just issue the "c" (continue) debug
command, the code works as expected (only slower than desired). If I run
the same code in the interpreter,
it chokes. Any help would be much appreciated. The source is attached.
--------------62C547672CB43A1CC1EF62C0
Content-Type: application/x-perl;
name="match1.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="match1.pl"
#!/usr/bin/perl
# match1.pl mjpenniman 12/98
# open files
$work_dir = "/home/penniman/wip/banner.xref";
$fmtx_dir = "/u50/tmp/banner/fmt";
$tv_list = $work_dir . "/tv_name_list";
$fmtx_list = $work_dir . "/form_list";
$xref_list = "xref_list";
&open_output;
# open table/view name list
&prep_tv_list;
# open form text file name list
&prep_form_text_list;
&search_form_names;
# output list
print "PROGRAM COMPLETE. THE END\n";
# *** END OF MAIN ***
#-----------------------------------------------------------------------------------
# subroutines
#-----------------------------------------------------------------------------------
# open output file: format xref of table/view names
# works mjp 12/14/98
sub open_output {
open(XRF,">$xref_list") ||
die "Unable to open xref_list file for output\n";
}
#-----------------------------------------------------------------------------------
# open table/view names list and load into array called @tv_info. Save it for repetition
# works mjp 12/3/98
sub prep_tv_list {
print "Opening & storing list of tables & views\n";
open(TV_LST,"<$tv_list") ||
die "could not open file '$tv_list' for input";
while (<TV_LST>) {
chop;
push(@tv_info, (split));
}
@tv_info_save = @tv_info;
}
#-----------------------------------------------------------------------------------
# open list of format text file names. # works mjp 12/3/98
sub prep_form_text_list {
print "Opening list of forms\n";
open(FMTX_LST,"<$fmtx_list") ||
die "could not open file '$fmtx_list' for input";
}
#-----------------------------------------------------------------------------------
# open form text files, one by one # works mjp 12/4/98
sub search_form_names {
print "Opening form contents file by file\n";
while (<FMTX_LST>){
chop;
($fmtx_rel, $fmtx_file_long) = split;
# See note (A)
#debug
# the next line prints in debugger but not otherwise
#print $_;
# the next line prints in debugger but not otherwise
#print $fmtx_rel;
# the next line prints in debugger but not otherwise
print " \n", "form:", $fmtx_file_long, ": ";
# split form text name from file type
($fmtx_file, $fmtx_type) = split(/\./,$fmtx_file_long);
# open form text file
$fmtx_file_long = $fmtx_dir . "/" . $fmtx_file_long;
open(FMTX,"<$fmtx_file_long") ||
die "could not open file '$fmtx_file_long' for input";
# add form information to array.
@form_info = (uc($fmtx_file),uc($fmtx_rel),uc($fmtx_type));
&search_form;
# open another format text file
}
}
#-----------------------------------------------------------------------------------
# for each entry in form text search @tv_list
# debug 12/10/98 mjp
sub search_form {
$fl = 0;
while(<FMTX>) {
chop;
# the next lines print in debugger but not otherwise
# shows progress of routine
$fl++;
if (int($fl/10000) == $fl/10000) {
print " \nform text:", $fmtx_file, ": ";
print " ", $fl;
}
if (int($fl/500) == $fl/500) { print " ", $fl }
$fmtxt = uc($_);
# refresh array for each format text record read
@tv_info = @tv_info_save ;
# go through list until end then read next format text line
while ($tv_info[2] !~ /^$/) {
# When end of table/view list, go to next line of format text
if ($fmtxt =~ /\b$tv_info[2]\b/){ &hit_test; }
# if hit for table/view name then go to next entry on tbl/vw list.
shift @tv_info;shift @tv_info;shift @tv_info;
}
}
# When endof table/view list, close current format & open next
}
#-----------------------------------------------------------------------------------
# testing mjp 12/4/98
sub hit_test {
# the next line prints in debugger but not otherwise
# print "hit ";
# if hit, output: version, formname, form type, table/view name, T/V
if ($form_info[1] =~ /FNXT/) {$ver = "3.1";}
elsif ($form_info[1] =~ /BNUT/) {$ver = "2.0";}
elsif ($form_info[1] =~ /BNAD/) {$ver = "2.0";}
elsif ($form_info[1] =~ /BPRD/) {$ver = "2.0";}
if ($tv_info[1] =~ /TABLE/) {$ttype = "T";}
elsif ($tv_info[1] =~ /VIEW/) {$ttype = "V";}
print XRF $ver, " ", $form_info[0], " ", $form_info[2], " ", $tv_info[2], " ", $ttype, "\n";
}
#-----------------------------------------------------------------------------------
# NOTE(A)
# problem area
# this program, if run in the perl debugger, works as expected.
# if run normally it seems to hang here and never seems to print to screen or output file.
--------------62C547672CB43A1CC1EF62C0--
------------------------------
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 4421
**************************************