[11697] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5297 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 5 02:06:13 1999

Date: Sun, 4 Apr 99 23:00:19 -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           Sun, 4 Apr 1999     Volume: 8 Number: 5297

Today's topics:
    Re: (newbie) matching value from array??? (Ronald J Kimball)
    Re: (newbie) matching value from array??? (Jerry)
    Re: (newbie) matching value from array??? (Tad McClellan)
    Re: Compiling Perl Scripts luvisi@andru.sonoma.edu
    Re: Different `dir`-results <th.bossert@z.nospam.zgs.de>
        Does anyone know whats wrong with my script? agniora@usa.net
    Re: Does anyone know whats wrong with my script? (Bill Moseley)
        Dump All Variables? <revjack@radix.net>
    Re: Dump All Variables? <zenin@bawdycaste.org>
        How do i use the / character in split command. agniora@usa.net
    Re: How do i use the / character in split command. (Sam Holden)
    Re: Not stupid anymore <mpersico@erols.com>
    Re: Not stupid anymore (Bob Trieger)
    Re: Perl calling MS Word (David Combs)
    Re: Perl Question for generating HTML trimbleman@hotmail.com
    Re: Regular Expression Practice <noSPAMpvoris@earthlink.net>
        Rewrite the input at the begining of the same file. <shengx@seas.upenn.edu>
    Re: Rewrite the input at the begining of the same file. (Sam Holden)
    Re: Rewrite the input at the begining of the same file. <zenin@bawdycaste.org>
    Re: running perl on NT IIS <th.bossert@z.nospam.zgs.de>
        Scope of variables <tszeto@mindspring.com>
    Re: Scope of variables (Ronald J Kimball)
    Re: Scope of variables smnayeem@my-dejanews.com
    Re: Scope of variables (Larry Rosler)
    Re: SENDMAIL not allowing Content-Type: multipart/mixed <Russell_Schulz@locutus.ofB.ORG>
    Re: Trimming a number to only 2 decimal places (Sam Holden)
    Re: Trimming a number to only 2 decimal places (Ronald J Kimball)
        Very new to perl and I need some help displaying images wulffen@newsguy.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 4 Apr 1999 22:28:21 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: (newbie) matching value from array???
Message-Id: <1dpr9xl.16tuhd7zi2baeN@p96.block2.tc1.state.ma.tiac.com>

Larry Rosler <lr@hpl.hp.com> wrote:

> In article <qc18e7.g1p.ln@magna.metronet.com> on Sun, 4 Apr 1999 
> 11:44:26 -0400, Tad McClellan <tadmc@metronet.com> says...
> > Jerry (preeper@cts.com) wrote:
> ...
> > :   $sql_query = "select city,short_name,full_name,url_link ";
> > :   $sql_query .= "from $linktable";
> > :   $sql_result = $dbh->Query($sql_query);
> > :   while (@row = $sql_result->FetchRow()) {
> > :     $link_city = $row[0];
> > :     $link_short_name = $row[1];
> > :     $link_full_name = $row[2];
> > :     $url_link = $row[3];
> > :     }
> > 
> > 
> >    That is a cumbersome way to load up your variables.
> > 
> >    You can shorten the body of the while loop to a single line:
> > 
> >       ($link_city, $link_short_name, $link_full_name, $url_link) = @row;
> 
> Which overwrites those variables each time through the loop, so their
> values on loop exit are those of the last iteration.  That *may* be what
> is wanted, but I doubt it.

Well, it's no different from what the original code did, anyway...
I'd guess that the original poster is asking for code that will complete
the body of that while loop.  I didn't have any better luck than Tad at
understanding the question, though.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: Mon, 05 Apr 1999 04:49:54 GMT
From: preeper@cts.com (Jerry)
Subject: Re: (newbie) matching value from array???
Message-Id: <37083bb4.46887821@news2.cts.com>

Let me try explaining again what I'm trying to do.  I have a table in
a MySQL database that has in it a list of scores and game related info
from a little league, including the name of each team (home team and
away team are listed as such) and the scores, times, etc...  so I can
print weekly schedules and results.

In another table, I have a list of the teams in the league and for
each team I have the manager's name, the city name and the url for
each team's web site (but only if they have one). This way I don't
have to repeat all the info in the scores table for each team.  

Now I'm trying to figure out how to link to the team's web site (but
only if they have one because not all of the team's do) when I print
out the scores.  And obviously sometimes the team is listed under home
team and sometimes under away team. The team name in the schedule will
always match a team in the team table.

I have the sql query pulling the scores and printing last week's
results just fine.  Now, I figure I need to do a separate query before
I pull the results, that lists the team and url pairs so that I can
match them up against the home team and away team when I loop through
the schedule/results table and then print a link to the team's web
site whenever I print the team's name in the weekly results.

Does that make a little more sense?

Jerry



J Kimball) wrote:

>Larry Rosler <lr@hpl.hp.com> wrote:
>
>> In article <qc18e7.g1p.ln@magna.metronet.com> on Sun, 4 Apr 1999 
>> 11:44:26 -0400, Tad McClellan <tadmc@metronet.com> says...
>> > Jerry (preeper@cts.com) wrote:
>> ...
>> > :   $sql_query = "select city,short_name,full_name,url_link ";
>> > :   $sql_query .= "from $linktable";
>> > :   $sql_result = $dbh->Query($sql_query);
>> > :   while (@row = $sql_result->FetchRow()) {
>> > :     $link_city = $row[0];
>> > :     $link_short_name = $row[1];
>> > :     $link_full_name = $row[2];
>> > :     $url_link = $row[3];
>> > :     }
>> > 
>> > 
>> >    That is a cumbersome way to load up your variables.
>> > 
>> >    You can shorten the body of the while loop to a single line:
>> > 
>> >       ($link_city, $link_short_name, $link_full_name, $url_link) = @row;
>> 
>> Which overwrites those variables each time through the loop, so their
>> values on loop exit are those of the last iteration.  That *may* be what
>> is wanted, but I doubt it.
>
>Well, it's no different from what the original code did, anyway...
>I'd guess that the original poster is asking for code that will complete
>the body of that while loop.  I didn't have any better luck than Tad at
>understanding the question, though.
>
>
>-- 
> _ / '  _      /       - aka -
>( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
>    /                                http://www.tiac.net/users/chipmunk/
>        "It's funny 'cause it's true ... and vice versa."



------------------------------

Date: Sun, 4 Apr 1999 19:07:30 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: (newbie) matching value from array???
Message-Id: <ibr8e7.aup.ln@magna.metronet.com>

Larry Rosler (lr@hpl.hp.com) wrote:
: In article <qc18e7.g1p.ln@magna.metronet.com> on Sun, 4 Apr 1999 
: 11:44:26 -0400, Tad McClellan <tadmc@metronet.com> says...
: > Jerry (preeper@cts.com) wrote:
: ....
: > :   while (@row = $sql_result->FetchRow()) {
: > :     $link_city = $row[0];
: > :     $link_short_name = $row[1];
: > :     $link_full_name = $row[2];
: > :     $url_link = $row[3];
: > :     }
: > 
: >    You can shorten the body of the while loop to a single line:
: > 
: >       ($link_city, $link_short_name, $link_full_name, $url_link) = @row;

: Which overwrites those variables each time through the loop, 


   So does the code it is meant to replace.


: so their 
: values on loop exit are those of the last iteration.  


   Same as the code it is meant to replace.


: That *may* be what 
: is wanted, but I doubt it.

   I doubt it too.

   I didn't even try to fix his code, I can't figure out what
   is wanted. I just offered an alternative to the clunky
   style, aside from his real problem, whatever that may be.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: 04 Apr 1999 23:33:34 -0700
From: luvisi@andru.sonoma.edu
Subject: Re: Compiling Perl Scripts
Message-Id: <m2u2uvefup.fsf@andru.sonoma.edu>

"Peter Sergeant" <petes@hempseed.com> writes:
> 
> If I've written a Perl Script in a Win95 or Dos version of Perl, is there
> any program I can get to compile it as an EXE that will work on any
                                                          ^^^^^^^^^^^
> computer?
  ^^^^^^^^

nope.  EXEs are platform specific.  if you want your script to work on
any computer, write it without using platform specific extensions, and
distribute the source.

andru


------------------------------

Date: 5 Apr 1999 05:27:03 GMT
From: "T. Bossert" <th.bossert@z.nospam.zgs.de>
Subject: Re: Different `dir`-results
Message-Id: <37084A56.93690A6B@z.nospam.zgs.de>

Hi Bob,

In general, I agrre ( and I  do just that ). However, using perl 5.004 a
`dir *.* /s` gives you the contents of the directory ( and the subs )
with, and that's the interesting part, file dates and sizes. That, of
course, can be done in 'normal' perl, too, but not in just one line - I
think-  :-).

Thomas



------------------------------

Date: Mon, 05 Apr 1999 04:49:01 GMT
From: agniora@usa.net
Subject: Does anyone know whats wrong with my script?
Message-Id: <7e9fbr$t8h$1@nnrp1.dejanews.com>

I wrote a function to find the weekday of a given date.
but strangely, if i run it as a program then it works, but when i make it a
subroutine it gives errors.
heres the script :
#print &FindDate('04/04/99');

#Sub FindDate {
#my $Onlydate = @_;
$Onlydate = "04/04/99";
$Onlydate =~ s/\// /g;
@Adate = split(/ /,$Onlydate);
@Days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
%Special =
(
"Jan" => 0,
"Feb" => 3,
"Mar" => 3,
"Apr" => 6,
"May" => 1,
"Jun" => 4,
"Jul" => 6,
"Aug" => 2,
"Sep" => 5,
"Oct" => 0,
"Nov" => 3,
"Dec" => 5,
);
@Months =
('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

print $Months[$Adate[1]-1];
print $Days[(5+$Special{$Months[$Adate[1]-1]} + $Adate[0]-1) % 7];
#return $Days[(5+$Special{$Months[$Adate[1]-1]} + $Adate[0]-1) % 7];
#}

try running this program and it will give the day of any date (at present only
for the year 99).
then try uncommenting the commented lines and running it, it gives various
errors.
does anyone know where i went wrong?
ill appreciate any help.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Sun, 4 Apr 1999 22:18:18 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Does anyone know whats wrong with my script?
Message-Id: <MPG.1171e779cb7962cc989709@206.184.139.132>

In article <7e9fbr$t8h$1@nnrp1.dejanews.com>, agniora@usa.net says...
> I wrote a function to find the weekday of a given date.

I'd use timelocal and localtime to do that work.


> #my $Onlydate = @_;

Eh, I don't think you want the count of the number of elements in @_?



-- 
Bill Moseley mailto:moseley@best.com


------------------------------

Date: 5 Apr 1999 01:47:43 GMT
From: Turin Waterbury <revjack@radix.net>
Subject: Dump All Variables?
Message-Id: <7e94nv$4$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight

Is there an elegant way to get perl to somehow report the values of
*all* variables in memory, including vars like $$, $_, $|, and variables
created by the script, like $foo etc?

Or, would this be a stupid thing to ask perl to do?

-- 
  /~\  inveigle beneficent ethos sanatoria trypsin Walcott Melissa mat
 C oo  Goodwin midpoint honoraria Kirchoff shout ergodic aorta archaic
 _( ^) 1 , 0 0 0 , 0 0 0   m o n k e y s   c a n ' t   b e   w r o n g
/___~\ http://3509641275/~revjack  04/04/99 21:43:52 revjack@radix.net


------------------------------

Date: 05 Apr 1999 02:17:22 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Dump All Variables?
Message-Id: <923278710.689626@thrush.omix.com>

Turin Waterbury <revjack@radix.net> wrote:
: Is there an elegant way to get perl to somehow report the values of
: *all* variables in memory, including vars like $$, $_, $|, and variables
: created by the script, like $foo etc?

	See the "V" and "X" commands of the debugger (perldoc perldebug). 
	Infact, see the debugger in general.

: Or, would this be a stupid thing to ask perl to do?

	There is nothing stupid you can ask of Perl.  Perl's your bitch,
	your whipping boy.  Its job is to do what you tell it to and not ask
	any questions.  If it talks back to, just smack it upside the =back
	of the =head.

	:-) <--For the humor impaired.

-- 
-Zenin (zenin@archive.rhps.org)

        Yah, Emacs is a good OS, but I prefer FreeBSD.


------------------------------

Date: Mon, 05 Apr 1999 03:10:13 GMT
From: agniora@usa.net
Subject: How do i use the / character in split command.
Message-Id: <7e99ig$ocn$1@nnrp1.dejanews.com>

In the split command how will i use the / character.
eg
to split the string

$t = '21/03/99';
@t=split (/\//,$t);

this doesnt work.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: 5 Apr 1999 03:22:12 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: How do i use the / character in split command.
Message-Id: <slrn7ggb34.r85.sholden@pgrad.cs.usyd.edu.au>

On Mon, 05 Apr 1999 03:10:13 GMT, agniora@usa.net <agniora@usa.net> wrote:
>In the split command how will i use the / character.
>eg
>to split the string
>
>$t = '21/03/99';
>@t=split (/\//,$t);
>
>this doesnt work.

Please define 'doesnt work'.

It works for my definition of 'work'.

-- 
Sam

PC's are backwards ... throw them out! Linux is ok though.
	--Rob Pike (on the subject of CR/LF etc)


------------------------------

Date: Sun, 04 Apr 1999 22:17:18 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Not stupid anymore
Message-Id: <37081D2E.EF28FF2F@erols.com>

Rob Sweet wrote:
> 
> Thanks to all who posted.  I took Bob's advice to "Take a deep breath
> and relax,", and realized that as Ran says, from the point of view of
> the server, there is no difference between POSTING direct to the
> underlying CGI vs. "remote controling" the web page.   Duh.  The web
> page runs on MY WORKSTATION.  That realization was what turned the
> light on.
> 
> In my defense, I'm not normally an idiot.... er... well, anyway.   The
> web admin at the destination had misled me, claiming that their site
> wouldn't work if I posted direct to the CGI.  Obviously I *CAN* post
> direct to the CGI, since any HTML form is running on my server, and
> the target CGI has no idea what is generating the post.
> 
> My true idiocy, for which I deserve a good slap, is that I believed a
> client without thinking it through ... and to think I call myself a
> professional.
> 
> On Sun, 04 Apr 1999 02:49:42 GMT, ran@netgate.net    (Ran) wrote:
> 
> >From the point of view of the underlying client-server code,  those
> >actions are identical.

Relax. Everyone has a V8 moment now and then.
-- 
Matthew O. Persico
http://www.erols.com/mpersico
http://www.digistar.com/bzip2


------------------------------

Date: Mon, 05 Apr 1999 02:43:54 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Not stupid anymore
Message-Id: <7e97uh$mkq$1@fir.prod.itd.earthlink.net>

"Matthew O. Persico" <mpersico@erols.com> wrote:
o>Relax. Everyone has a V8 moment now and then.

I don't have V8 moments, I have VO moments.

Bob Trieger
sowmaster@juicepigs.com

"Contrary to popular belief, man can live on Ramen Noodles alone"    



------------------------------

Date: Mon, 5 Apr 1999 01:00:50 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: Perl calling MS Word
Message-Id: <dkcombsF9oytE.C1F@netcom.com>

In article <370251f3.0@news.new-era.net>,
Scott McMahan <scott@aravis.softbase.com> wrote:
>Bob Daly (bdaly@averstar.com) wrote:
>> Does anyone know how to call Word in Perl?
>
>You must use Automation.
>
>If you can wait til August, I have a book coming out which 
>discusses this.
>
>Scott

What is this book you're writing?  About PERL?  O'Reily?  Title?

Thanks!

David



------------------------------

Date: Mon, 05 Apr 1999 03:04:50 GMT
From: trimbleman@hotmail.com
Subject: Re: Perl Question for generating HTML
Message-Id: <7e998e$nvk$1@nnrp1.dejanews.com>

In article <1rs4e7.61h.ln@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> cjsub@hotmail.com wrote:
> : I have been using perl for a few years to manipulate text files.
> : Now i want to start formatting my output into HTML docs.
> : Is the best way to do this using the Format Statement to create the misc
> : stuff at the top of my html doc ??
>
>    No.
>
> : and then use the Format again for the body
>
>    No.
>
> : and then use format a third time for my closing <\> tags ??
>
>    No.
>
> : Any help or faq's will be greatly appreciated
>
>    Perl's 'format' is handy for producing columnated reports,
>    though I have never needed it in several years of Perl
>    programming (I get what I need with (s)printf).
>
>    Whitespace is "folded" in the presentation of HTML (it is
>    ignored by the browser), so getting things lined up in
>    pretty columns is unneeded work, since the browser will
>    undo the work anyway.
Is this true if you are passing the data into HTML Borders
with cells and rows ??
>
>    print() with a here-doc is handy for outputting a block
>    of text, such as the head/tail of the HTML output:
>
> print <<'ENDHTML';
> Content-Type: text/html
>
> <html>
> <head>
>    <title>My Web Page</title>
> </head>
> <body>
> ENDHTML
So this produces the headers portion of each html document ??
then you would use another print <<
for the body ??
and a third for the ending ??

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Sun, 04 Apr 1999 21:56:08 -0700
From: Phil Voris <noSPAMpvoris@earthlink.net>
Subject: Re: Regular Expression Practice
Message-Id: <37084268.B0640415@earthlink.net>

Here's some simple ones:

remove all doubled words in a file.

use regexes to help sort a list of pretty-printed dates (ie, Mon, Dec
20th, 1947, 12:23:43 PST)  (hint, it helps to use hashes ... modules are
cheating).

convert every third word in a file to uppercase

delete everwithout using a loop, delete every line ending in a file
ending with any number of non-tab, non-\n spaces.

Knock yourself out.



------------------------------

Date: Sun, 4 Apr 1999 21:52:09 -0400
From: "Upenn news" <shengx@seas.upenn.edu>
Subject: Rewrite the input at the begining of the same file.
Message-Id: <7e94vu$sg5$1@netnews.upenn.edu>

Hi,
  I am a beginer in perl and am writing a script that basically echo a file
until it first encounters the <body>. Delete everything before that tag and
writes different things in front of it.

My questions is :
1. How to delete lines in the actually file. It won't help to delete the
line that I've read, because the real line in the file is not deleted.

2. For now, whatever I insert, it is inserted at the back of the file, how
can we make it insert at the front.

thanks a lot.

steve







------------------------------

Date: 5 Apr 1999 02:03:31 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Rewrite the input at the begining of the same file.
Message-Id: <slrn7gg6fj.ogj.sholden@pgrad.cs.usyd.edu.au>

On Sun, 4 Apr 1999 21:52:09 -0400, Upenn news <shengx@seas.upenn.edu> wrote:
>Hi,
>  I am a beginer in perl and am writing a script that basically echo a file
>until it first encounters the <body>. Delete everything before that tag and
>writes different things in front of it.

Well you should read the documentation that comes with perl. How else are
you meant to know how to use perl. Asking here is not the way, since it
takes longer, and bothers lots of people who here the same questions
over and over again...

>
>My questions is :
>1. How to delete lines in the actually file. It won't help to delete the
>line that I've read, because the real line in the file is not deleted.

perlfaq5 : How do I change one line in a file/delete a line in a file/insert
           a line in the middle of a file/append to the beginning of a file?

>
>2. For now, whatever I insert, it is inserted at the back of the file, how
>can we make it insert at the front.

perlfaq5 : How do I change one line in a file/delete a line in a file/insert
           a line in the middle of a file/append to the beginning of a file?



-- 
Sam

So I did some research. On the Web, of course. Big mistake...
	--Larry Wall


------------------------------

Date: 05 Apr 1999 02:21:22 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Rewrite the input at the begining of the same file.
Message-Id: <923278951.114287@thrush.omix.com>

[posted & mailed]

Upenn news <shengx@seas.upenn.edu> wrote:
: I am a beginer in perl and am writing a script that basically echo a file
: until it first encounters the <body>. Delete everything before that tag
: and writes different things in front of it.
:
: My questions is :
: 1. How to delete lines in the actually file. It won't help to delete the
: line that I've read, because the real line in the file is not deleted.
:
: 2. For now, whatever I insert, it is inserted at the back of the file, how
: can we make it insert at the front.

	perldoc -q 'insert a line'

	After that, run 'perldoc perldoc' and spend a few minutes reading up
	on all the cool things it can do.

	HTH

-- 
-Zenin (zenin@archive.rhps.org)

        Yah, Emacs is a good OS, but I prefer FreeBSD.


------------------------------

Date: 5 Apr 1999 05:44:21 GMT
From: "T. Bossert" <th.bossert@z.nospam.zgs.de>
Subject: Re: running perl on NT IIS
Message-Id: <37084E63.AA30728F@z.nospam.zgs.de>

Hi Pete,

'perl5 for windows systems' being what ?
The binary distribution from CPAN has an 'install' (and a detailed
'readme') after unpacking and the ActiveState-distribution installs
itself when executing the distributetd 'exe'.
They both install fine on NT workstation and server.

Thomas





------------------------------

Date: Sun, 4 Apr 1999 20:45:07 +0100
From: "Ted" <tszeto@mindspring.com>
Subject: Scope of variables
Message-Id: <7e9bji$nks$1@camel25.mindspring.com>

As a rule of thumb, is it generally a good idea to limit the scope of
variables to their subroutines?

I remeber in a beginning C class I took, that the scope of variables was
limited to their functions. This seemed to help cut confusion.

-Ted




------------------------------

Date: Mon, 5 Apr 1999 00:27:35 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Scope of variables
Message-Id: <1dpridk.trfik21fbo99sN@p69.block2.tc1.state.ma.tiac.com>

Ted <tszeto@mindspring.com> wrote:

> As a rule of thumb, is it generally a good idea to limit the scope of
> variables to their subroutines?
> 
> I remeber in a beginning C class I took, that the scope of variables was
> limited to their functions. This seemed to help cut confusion.

Yes, that is generally a good idea.

Very recently, I had to track down a bug in one of my scripts that was
caused by forgetting to limit a variable's scope to its subroutine.  As
a result, the subroutine clobbered the value of a variable of the same
name in another part of the code.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: Mon, 05 Apr 1999 05:09:40 GMT
From: smnayeem@my-dejanews.com
Subject: Re: Scope of variables
Message-Id: <7e9gif$u6a$1@nnrp1.dejanews.com>

In article <7e9bji$nks$1@camel25.mindspring.com>,
  "Ted" <tszeto@mindspring.com> wrote:
> As a rule of thumb, is it generally a good idea to limit the scope of
> variables to their subroutines?
>
> I remeber in a beginning C class I took, that the scope of variables was
> limited to their functions. This seemed to help cut confusion.
>
> -Ted
>
>

so far ive noticed that avoiding global variables is always a good idea, for
it keeps the subroutines independent and also makes it very portable. and its
also more economic resourcewise. passing references to a subroutine is an
easier way to avoid global variables in some cases. agniora

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Sun, 4 Apr 1999 22:24:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Scope of variables
Message-Id: <MPG.1171e8cc1c4d5e298982e@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7e9bji$nks$1@camel25.mindspring.com> on Sun, 4 Apr 1999 
20:45:07 +0100, Ted <tszeto@mindspring.com >says...
> As a rule of thumb, is it generally a good idea to limit the scope of
> variables to their subroutines?

You bet!  Ideally, the only interface between a subroutine and the rest 
of the program is via its arguments and return values.  (There are also 
interfaces to the file system and the operating system, of course.)

> I remeber in a beginning C class I took, that the scope of variables was
> limited to their functions. This seemed to help cut confusion.

The default scope for variables inside a C function is limited to the 
function.  This is a Good Thing.

Unfortunately, the default scope for variables inside a Perl subroutine 
is global.  However, the "use strict 'vars';" pragma forces you to 
declare all variables, so you can approximate the C semantics by 
declaring all variables inside a Perl subroutine using 'my' (*not* 
'local'!).

Search the Perl documentation for 'strict'.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Sun, 4 Apr 1999 21:00:38 -0400
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: SENDMAIL not allowing Content-Type: multipart/mixed header
Message-Id: <19990404.210038.6y0.rnr.w164w@locutus.ofB.ORG>

  [ This is not particularly about perl ]

Julian Madle <julian.madle@mcmail.com> writes:

> $bound = "------------6B797646304";

a. I have found that beginning boundaries with `-' causes grief with
   people who forget how the boundaries are formed.
b. Have you considered something with $bound="===1999-04-05-11-35-42" ?

> However I do not know much about SENDMAIL

That's not relevant here.

> and I cannot manage to get the multipart/mixed stuff in the email
> header, therefore my mail client (Netscape Messenger) does not
> recognize the attachment

Did you try dumping the contents you're sending to a file instead of
to a pipe, so you could compare it against the MIME examples and see
what you're missing?

> print MAIL qq{\n$bound\nContent-Type: text/plain; charset=us-ascii;

There's your first use of $bound.  See point a.

Where's your closing $bound?  Also, see point a.
-- 
Russell_Schulz@locutus.ofB.ORG  Shad 86c


------------------------------

Date: 5 Apr 1999 01:17:29 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Trimming a number to only 2 decimal places
Message-Id: <slrn7gg3p9.nh6.sholden@pgrad.cs.usyd.edu.au>

On Sun, 04 Apr 1999 19:11:12 GMT, Rob Sweet <sweet@enterpriseusa.com> wrote:
>You realize that if you're going to use %f you've gotta use printf not
>print, right?  Just a quick thought...

I must admit I didn't see a %f in the question...

The real answer is :

perlfaq4 :  Does perl have a round function?  What about ceil() and floor()?
            Trig functions?

>
>Rob Sweet
>sweet@enterpriseusa.com
>
>
>On Sun, 04 Apr 1999 22:44:49 GMT, hogringer@earthlink.net wrote:
>
>>Can someone tell me how to trim a dollar amount to just 2 decimal
>>places?  I want to print "Federal tax is $xxx.xx" and I get a number
>>with 6-8 numbers to the right of the decimal.  I tried using %.2f but
>>I must not be using it right because it wont display right.  I have a
>>line  that reads
>>
>>$ftax = ($gross*.10);
>>
>>and then it is displayed with this line
>>
>>print "         | Federal tax is \$$ftax
>>
>>I would like to get rid of all the extra digits.  Can someone help me
>>with this?  Thanks


-- 
Sam

Every human culture has good and bad points. Every computer program has
Eveone more bug. Even Perl.
	--Larry Wall


------------------------------

Date: Sun, 4 Apr 1999 22:28:22 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Trimming a number to only 2 decimal places
Message-Id: <1dprd0z.y56cu3rope4gN@p96.block2.tc1.state.ma.tiac.com>

<hogringer@earthlink.net> wrote:

> Can someone tell me how to trim a dollar amount to just 2 decimal
> places?

The FAQ can.

perlfaq4:

  Does perl have a round function?  What about ceil() and floor()?
  Trig functions?

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: Mon, 05 Apr 1999 04:53:15 GMT
From: wulffen@newsguy.com
Subject: Very new to perl and I need some help displaying images..
Message-Id: <37083ff5.21080720@enews.newsguy.com>

email i check the most : lmonagan@columbus.rr.com


I got a password protect script which seems to work well with html
pages with text only.  I also would like it to work for images.
Here's the code I got from www.freecode.com.  If someone could steer
me in the right direction it would be greatly appreciated.  

#             ### *** CONFIGURATION SECTION *** ###

# Enter the complete path and name of the people.log
$people_log = './people.log';

# Enter the path and name of the file you want to password protect
# the file can be named anything you like. ie secure.dat, secure.txt
# or just secure - it's best not to have an .htm extention even though
# it is an HTML file. This program will print the file to the user
# as HTML


$txt_file = "../notes/OurHouse.txt";

     ############ Do not change any thing below ############

# If you edit the file below, do not disturb the -  print <<"EOT"; 
# or the - EOT - lines or you will get an error         


&parse;

&whoareyou unless $FORM{'password'};
&whoareyou unless $FORM{'username'};



open (PEOPLE, "$people_log") || &open_error($people_log);
@lines = <PEOPLE>;
close (PEOPLE);
foreach $line (@lines)

{

    chop $line;
    ($realname, $realpassword) = split(/\|/,$line);
    $pwordlist{$realname}=$realpassword;
    
}


if (!$pwordlist{$FORM{'username'}}) {

   # NOT AN AUTHORIZED USER

   print "Content-type: text/html\n\n";

   print <<"EOT"; 

<HTML>
<HEAD>
   <TITLE>Access Denied</TITLE>
</HEAD>
<BODY>
<H1>Access Denied</H1>
I can't let you in, because I don't know who
"$FORM{'username'}" is.
<P>
<a href="$ENV{'HTTP_REFERER'}">Try again.</a>
</BODY>
</HTML>

EOT

}elsif ($FORM{'password'} ne $pwordlist{$FORM{'username'}} ) {

   # PASSWORDS DON'T MATCH

   print "Content-type: text/html\n\n"; 

   print <<"EOT";

<HTML>
<HEAD>
   <TITLE>Access denied</TITLE>
</HEAD>
<BODY>
<H1>Access Denied</H1>
I can't let you in, because that's not the right password for
$FORM{'username'}
<P>
<a href="$ENV{'HTTP_REFERER'}">Try again.</a>
</BODY>
</HTML>

EOT

}else{ # The user is cleared to proceed


# THIS SECTION OPENS THE HTM FILE AND PRINTS IT

   print "Content-type: text/html\n\n";
binmode(STDOUT);
open(FILE, "$txt_file") || &open_error($txt_file);

@filein = <FILE>;
close(FILE); 
        
	print @filein;

}

exit;

                         ### *** *** ###


sub whoareyou {

   print "Content-type: text/html\n\n";

print <<EOT;

<HTML>
<Head><Title>ERROR</Title></Head>
<Body bgcolor=ffffff>
<CENTER>
<H1><FONT COLOR=0000FF>Log In</FONT></H1>
<H2>You must enter a username and password.</H2>
<P><UL>
</CENTER>
<a href=\"$login_page\">Try again.</a>

EOT

exit;

}


sub parse {

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);

   # Un-Webify plus signs and %-encoding
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;

   if ($allow_html != 1) {
      $value =~ s/<([^>]|\n)*>//g;
   }

   $FORM{$name} = $value;
 } 
}

                         ### *** *** ###

sub open_error
    {

    local ($errorname) = @_;
    print "Content-Type: text/html\n\n";
    print <<"EOT";
<HTML>
<HEAD>
<TITLE>Open Error!</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF Link=#0000FF vlink=#1D307E>
<P>
<HR>
<P>
<H1>Error!</H1>
<P>
<H4>The program can not find, or is not able to open the 
specified file:</H4>
<H3>$errorname</H3>
<P>
<B>  
Please check the path and file name in $ENV{'SCRIPT_NAME'}.
<P>
Also check the file permissions (chmod) for the file.
<P>
</BODY>
</HTML>

EOT

exit;
} # End sub open_error

                         ### *** *** ###


------------------------------

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 5297
**************************************

home help back first fref pref prev next nref lref last post