[24043] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6240 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 9 18:05:40 2004

Date: Tue, 9 Mar 2004 15:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 9 Mar 2004     Volume: 10 Number: 6240

Today's topics:
    Re: $result = system('/usr/bin/cksum TEST.mp3 >&1'); <1usa@llenroc.ude>
    Re: [OT] Rockets Alternative <usenet@morrow.me.uk>
    Re: Flat file database problem <jgibson@mail.arc.nasa.gov>
    Re: MS SQL 2000 (bob)
    Re: MS SQL 2000 <usenet@morrow.me.uk>
    Re: Multiple compares -- TMTOWTDI (Anno Siegel)
    Re: Multiple compares -- TMTOWTDI <jgibson@mail.arc.nasa.gov>
    Re: Multiple compares -- TMTOWTDI <perl@my-header.org>
    Re: Multiple compares -- TMTOWTDI <perl@my-header.org>
    Re: Need help with Undeliverable Emails (Malcolm Dew-Jones)
    Re: Ordering large files (in perl?) <jgibson@mail.arc.nasa.gov>
    Re: Rockets Alternative <georgekinley@hotmail.com>
    Re: Rockets Alternative <tadmc@augustmail.com>
    Re: Rockets Alternative <jgibson@mail.arc.nasa.gov>
    Re: Rockets Alternative <jgibson@mail.arc.nasa.gov>
    Re: storing and accessing a has in a package <mgjv@tradingpost.com.au>
    Re: teaching myself perl - stumped on this one! <kirk@strauser.com>
    Re: teaching myself perl - stumped on this one! <ittyspam@yahoo.com>
    Re: teaching myself perl - stumped on this one! (Randal L. Schwartz)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Mar 2004 19:44:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: $result = system('/usr/bin/cksum TEST.mp3 >&1');
Message-Id: <Xns94A795F2A91CDasu1cornelledu@132.236.56.8>

Paul Lalli <ittyspam@yahoo.com> wrote in
news:20040309113930.E27834@dishwasher.cs.rpi.edu: 

> On Tue, 9 Mar 2004, A. Sinan Unur wrote:
> 
>> "Ewald van Gemert" <news@vangee.nl> wrote in news:404db668$0$80589
>> $ee9da40f@news.wanadoo.nl:
>>
>> > Hi,
>> >
>> > I would like to get the output:
>> >     1306701436 266 TEST.mp3
>> > in the $result string.
>>
>> Output from what?
>> Where does $result come from?
>>
> 
> In his subject line.  Someone already responded to him that he should
> look at the faq.  Someone should also probably tell him to read the
> posting guidelines.

Arrrgh! I did not see the subject line.

I guess it falls on me to suggest to the OP to read:

http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Tue, 9 Mar 2004 20:15:41 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [OT] Rockets Alternative
Message-Id: <c2l8lc$edb$1@wisteria.csv.warwick.ac.uk>


Quoth "John W. Kennedy" <jwkenne@attglobal.net>:
> George Kinley wrote:
> > Is there any  way  for rockets to fly in space , other then throwing mass
> > out in one direction and moving in other
> 
> Assuming that you meant "space vessel", and not "rocket", the answer is 
> that gravity can be used for certain purposes, under certain conditions, 
> but you couldn't get anywhere using gravity alone; in general, there is 
> no known way other than reaction.

Not true. Here is not the place to go into detail, but a large 'sail'
silvered on one side and black on the other will accelerate due to
photon pressure. Obviously this will only work in the Solar system, not
in deep space.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

Date: Tue, 09 Mar 2004 11:49:01 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Flat file database problem
Message-Id: <090320041149010653%jgibson@mail.arc.nasa.gov>

In article <404daec6@daisy.ans.com.au>, Paul B <abcsydney@ans.com.au>
wrote:

> Hi guys,
> 
> I have a problem with my flatfile database when using the Add Record part of
> the script.
> 
> It removes the last character of the line above the line it just added.  I
> have included below the code that adds a record to my database.
> 
> Any ideas would be appreciated.
> 
> Kind Regards
> Paul
> 
> *Remove 'abc' from my email to respond.
> 
> sub add_record {
> foreach $required (@required){
> if($q->param($required) eq "") {
> $title = "Add A Record"; $error_message = "You did not fill out the required
> information!"; &access_problem($error_message); exit; } }
> 
> foreach $field (@fields){
> ${$field}  = $q->param($field);
> ${$field}  = filter(${$field});
> $record .= "${$field}\|";
> }
> chop $record;

Like the other posters, I don't really want to take the time to
understand your program, since you haven't indented the code to make it
readable, and I can't run it on my computer since you haven't provided
a complete, running program that demonstrates the problem, but if you
are losing the last character in a record, then this line would be
suspect. chop will remove the last character, no matter what it is. The
newer chomp will conditionally remove a line terminator if it exists,
so try that here instead. Or just figure out why you are doing a chop
here and maybe don't do it at all.

> unless (-e $database){ open (DB, ">$database") || die "Error creating
> database.  $!\n"; }
> else { open (DB, ">>$database") || die "Error opening database.  $!\n"; }
> flock DB, $EXCLUSIVE;
> seek DB, 0, 2;
> if($q->param('add_this_record') eq "Add This Record") {
> print DB "\n$record";
> } else {
> print DB "$record";
> }
> flock DB, $UNLOCK;
> close(DB);
> } # End of add_record subroutine.
> 
>


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

Date: 9 Mar 2004 11:38:47 -0800
From: bob@coolgroups.com (bob)
Subject: Re: MS SQL 2000
Message-Id: <41b3745b.0403091138.15162c83@posting.google.com>

OK, so how would I use this DBD::Sybase class to connect?

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c2ipat$ib0$1@wisteria.csv.warwick.ac.uk>...
> [quoting fixed. don't top-post]
> 
> Quoth anonymous@coolgroups.com:
> > anonymous@coolgroups.com wrote:
> > >
> > > Does anyone know how to connect to an MS SQL 2000 db from 
> > > Perl?
> > > 
> > > thanks.
> >
> > So, should this code work on a Unix system:
> > 
> > my $dbhandle = DBI->connect(
> >    "DBI:ADO:DRIVER={SQL
> > Server};SERVER=$servername;DATABASE=$dbname",
> >    $uid, $pwd,{ RaiseError => [1],
> >                 PrintError => [1],
> >                 AutoCommit => [1])
> >   ) || die "Db connection not made: $DBI::errstr";
> 
> I doubt it, as I thing DBD::ADO needs Win32 to run. Try using DBD::Sybase.
> 
> Ben


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

Date: Tue, 9 Mar 2004 20:32:00 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: MS SQL 2000
Message-Id: <c2l9k0$edb$2@wisteria.csv.warwick.ac.uk>

[quoting fixed again. stop it, now]

Quoth bob@coolgroups.com (bob):
> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c2ipat$ib0$1@wisteria.csv.warwick.ac.uk>...
> > Quoth anonymous@coolgroups.com:
> > > anonymous@coolgroups.com wrote:
> > > >
> > > > Does anyone know how to connect to an MS SQL 2000 db from 
> > > > Perl?
> > > > 
> > > > thanks.
> > >
> > > So, should this code work on a Unix system:
> > > 
> > > my $dbhandle = DBI->connect(
> > >    "DBI:ADO:DRIVER={SQL
> > > Server};SERVER=$servername;DATABASE=$dbname",
> > >    $uid, $pwd,{ RaiseError => [1],
> > >                 PrintError => [1],
> > >                 AutoCommit => [1])
> > >   ) || die "Db connection not made: $DBI::errstr";
> > 
> > I doubt it, as I thing DBD::ADO needs Win32 to run. Try using DBD::Sybase.
> 
> OK, so how would I use this DBD::Sybase class to connect?

my $dbh = DBI->connect("dbi:Sybase:server=$servername;database=$dbname", 
                       $uid, $pwd...

You will need to set $ENV{SYBASE} in a BEGIN block as detailed in the docs.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: 9 Mar 2004 19:25:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <c2l5ng$jft$1@mamenchi.zrz.TU-Berlin.DE>

Matija Papec  <perl@my-header.org> wrote in comp.lang.perl.misc:
> X-Ftn-To: Steve The Geek 
> 
> slkleine@hotmail.com (Steve The Geek) wrote:
> >Thanks in advance!
> >
> >Steve the (Just Another Perl Hacker Wannabe) Geek
> >
> ><begin paste>
> 
> I think you could benefit from "use strict;" on top of your script. There is
> also "use diagnostics;" which is very useful.
> 
> >sub RemoveIrrelevantCodes

That is not a good name for a sub.  The caller is interested in what it
returns, not what it does to get there.  "select_codes" says the
same thing in a user-oriented way.

> >{$ReturnCode = '';  #Initialize $ReturnCode
>   ^^^^^^^^^^^-- do you really need it?

It wasn't used (the initialization wasn't) if I remember the original
code right.  If it *is* used, the comment is a perfect example of a
spurious one.  Anyone who knows enough Perl to read a program has
seen that the code initializes $ReturnCode.  The only question is why,
because Perl variables don't need initialization, and *that*
would have belonged in a comment: "# caller doesn't cope with undef's",
or something more specific.

> >  if ((@DataLine[14] == "6")) #General class of TRAP
> 
> $DataLine[14] not @DataLine[14], you want one scalar, not slice.
> You shouldn't quote numbers, also read about differences between == and eq.
> 
> #untested
> sub RemoveIrrelevantCodes {
>   my %err = map { $_ => 1 } (1, 2, 418, 419);
> 	
>   #General class of TRAP
>   return if $DataLine[14] == 6 and $err{ $DataLine[15] };
>   return join (",", @DataLine[1,2,5,7..9,14,15]);
> }

Much better.  I'd move %err and its initialization out of the sub. The
obvious efficiency argument may not be relevant, but it makes it clearer
that %err is a constant lookup table.  It could become a file global
or go into a bare "container" block with the sub if the program is large.

The initialization should happen at compile time, in my opinion.  I like
to use a BEGIN block for the no-longer-bare container block, so

    # {{ marks an un-indented block

    BEGIN {{
    my %err = map ...
    sub select_codes {
       # Matija's code here
    }}

Compiling a sub in a BEGIN block has no measurable semantic effect :)

Anno


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

Date: Tue, 09 Mar 2004 13:13:44 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <090320041313445654%jgibson@mail.arc.nasa.gov>

In article <863f122c.0403090937.688d1c2d@posting.google.com>, Steve The
Geek <slkleine@hotmail.com> wrote:

> The logic works, but there's gotta be a better way.
> 
> FUNCTION
> The job of this subroutine is to filter out TRAP codes from our daily
> syslog files, specifically Generic TRAP 6 in combination with specific
> trap 1, 2, 418 or 419.[1]
> 
> I've searched through Perl CD Bookshelf 4.0 to little gain[2].
> 
> FWIW, I'm of classification 'Newbie'.
> 
> Thanks in advance!
> 
> Steve the (Just Another Perl Hacker Wannabe) Geek
> 
> <begin paste>

It is best to post a complete, working program. Always put these lines
at the top:

use strict;
use warnings;

Had you done so, Perl would have told about the syntax errors in your
program.

> 
> sub RemoveIrrelevantCodes
> {$ReturnCode = '';  #Initialize $ReturnCode
>   if ((@DataLine[14] == "6")) #General class of TRAP

The syntax for an array element is $DataLine[14] (not $). You are using
an array slice of one element, which is probably not what you want. 

>   {
>     if (@DataLine[15] == "1") #RMON exceeded

The == equality test is for numbers. Use eq for strings. Use
$DataLine[15] to access the array element.

>     {return}
>     if (@DataLine[15] == "2") #RMON in spec
>     {return}
>     if (@DataLine[15] == "418") #Port up
>     {return}
>     if (@DataLine[15] == "419") #Port down
>     {return}
>   }
>     $ReturnCode = join (",", @DataLine[1,2,5,7..9,14,15])
> }
> 
> <end paste>

You can use the grep function to search a list for a specified scalar:

my @rejected_fields = qw/ 1 2 418 419 /;
 .
 .
 .
if( grep { $DataLine[15] eq $_ } @rejected_fields ) {
  return;
}

For efficiency with a large number of elements, you can set up a hash
with the matching search terms defined as keys and arbitrary non-zero
values (assume @rejected_fields defined as above):

my %rejected_hash;
map { $rejected_hash{$_} = 1 } @rejected_fields;
 .
 .
 .
if( $rejected_hash{$DataLine[15]} ) {
  return;
}


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

Date: Tue, 09 Mar 2004 23:14:46 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <d5gs40tq6121pih556s0qvmbulpq547h1u@4ax.com>

X-Ftn-To: Anno Siegel 

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> >sub RemoveIrrelevantCodes
>
>That is not a good name for a sub.  The caller is interested in what it
>returns, not what it does to get there.  "select_codes" says the

Yes, it would be better.

>> >{$ReturnCode = '';  #Initialize $ReturnCode
>>   ^^^^^^^^^^^-- do you really need it?
>
>It wasn't used (the initialization wasn't) if I remember the original

I was referring to underlined piece (variable), not to initialization
itself. Variables like $ReturnCode aren't necessary in such simple code
since it's used only once for implicit return value at the end of sub.

>code right.  If it *is* used, the comment is a perfect example of a
>spurious one.  Anyone who knows enough Perl to read a program has
>seen that the code initializes $ReturnCode.  The only question is why,
>because Perl variables don't need initialization, and *that*
>would have belonged in a comment: "# caller doesn't cope with undef's",
>or something more specific.

Very unlikely, $ReturnCode is used to return a value in such way that it
can't become undef.

>that %err is a constant lookup table.  It could become a file global
>or go into a bare "container" block with the sub if the program is large.
>
>The initialization should happen at compile time, in my opinion.  I like
>to use a BEGIN block for the no-longer-bare container block, so
>
>    # {{ marks an un-indented block
>
>    BEGIN {{
>    my %err = map ...
>    sub select_codes {
>       # Matija's code here
>    }}

I'm not sure(uneven brace number?), but shouldn't this be:
    BEGIN {
    my %err = map ...
    sub select_codes {
      ..
    }}

>Compiling a sub in a BEGIN block has no measurable semantic effect :)

Perhaps, but I would like to have private variables defined more like in
some other language, this BEGIN block seems like, "hey, we have BEGIN
already so we could also use it for persistent lexicals!" :))



-- 
Matija


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

Date: Tue, 09 Mar 2004 23:27:26 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <lpgs40pjajk268bouc9suhvvn8kilnrj35@4ax.com>

X-Ftn-To: Jim Gibson 

Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>For efficiency with a large number of elements, you can set up a hash
>with the matching search terms defined as keys and arbitrary non-zero
>values (assume @rejected_fields defined as above):
>
>my %rejected_hash;
>map { $rejected_hash{$_} = 1 } @rejected_fields;

Actually, foreach is always preferred over map in void context,
$rejected_hash{$_} = 1 for @rejected_fields;

or maybe,
@rejected_hash{@rejected_fields} = (1) x @rejected_fields;



-- 
Matija


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

Date: 9 Mar 2004 12:27:42 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Need help with Undeliverable Emails
Message-Id: <404e28be@news.victoria.tc.ca>

James Willmore (jwillmore@remove.adelphia.net) wrote:

: I mean, if all *you* do is turn taint checking on and 'use
: strict', then your code isn't as secure as what you think it might be.

I'm not sure what you mean.

If that was all the user did then in this case (calling an external
program) the perl script would die with a warning before it could do
anything bad - which seems pretty safe.



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

Date: Tue, 09 Mar 2004 13:22:45 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Ordering large files (in perl?)
Message-Id: <090320041322458099%jgibson@mail.arc.nasa.gov>

In article <ffde43bc.0403081722.6fdc2988@posting.google.com>, Oeln
<ohmy9od@yahoo.com> wrote:

> I've got a large file in which there is one word on each line. I've
> got to output each word it includes to a new file, in order. I've
> currently got the following:
> 
>  @order = <INFILE>;
>  @ordered = sort(@order);
> 
>  foreach $o (@ordered) {
>     print OUTFILE "$o";
>  }
> 
> In general this is working fine; but if I've got to open a larger file
> (over 1gb, for example, or even 10 gb..whatever) it fails.
> 
> I've found this issue being gone over to an extent; but the
> information is not clear to me. I've got a few ideas on how to get
> this to work (for instance, if I could get one word out of the infile
> at a time and insert it to the outfile, in order in the first place;
> but I'd imagine this would be incredibly inefficient).

Yes. Do not reinvent the wheel. If you are on linux, use the sort
command. 'man sort'.

> 
> One idea I came upon implied that exec(sort) would be a good option.
> I'd imagine like exec(sort INFILE -o OUTFILE); but I'm not certain, or
> clear on the other options it offers. Is that good enough by itself
> for large files? I get the impression there is a way to output to a
> group of temp files, and then 'integrate' them into one file, etc.
> etc.

Try 'system("sort infile -o outfile"). The exec command won't return
execution to your program, probably not what you want. 

If you have one word per line, that should be all you need. Try it from
the command line and see if it does what you want, then run with it. I
am sure you have better things to worry about than implementing a merge
sort method. You might want '-b' option to sort to ignore leading
whitespace, -i to ignore non-ascii characters, and -f to use
case-insensitive sorting.

> 
> I guess what I'm looking for is either guidance to further info on
> this, or example code. I'd like to 'get' what's going on tho either
> way, though. I'm interested in the learning experience, too - not only
> in getting it to work.
> 
> I'm on fedora linux/perl 5.8.3 installed. I've only got 128mb on here,
> which I imagine is on of my issues..
> 
> Thank you for any input on this.


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

Date: Tue, 09 Mar 2004 19:34:52 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: Re: Rockets Alternative
Message-Id: <w%o3c.11169$k4.234091@news1.nokia.com>

Sorry Guys, it got posted to wrong group
I realized later,
Apologies again
"George Kinley" <georgekinley@hotmail.com> wrote in message
news:jmk3c.11154$k4.233803@news1.nokia.com...
> Hi
> Is there any  way  for rockets to fly in space , other then throwing mass
> out in one direction and moving in other
>
>
>




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

Date: Tue, 9 Mar 2004 08:52:23 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Rockets Alternative
Message-Id: <slrnc4rmh7.4bu.tadmc@magna.augustmail.com>

George Kinley <georgekinley@hotmail.com> wrote:

> Is there any  way  for rockets to fly in space , other then throwing mass
> out in one direction and moving in other


What is your Perl question?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 09 Mar 2004 13:30:42 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Rockets Alternative
Message-Id: <090320041330426758%jgibson@mail.arc.nasa.gov>

In article <c2kl7o$t8t$1@wisteria.csv.warwick.ac.uk>, Ben Morrow
<usenet@morrow.me.uk> wrote:

> Quoth "George Kinley" <georgekinley@hotmail.com>:
> > Hi
> > Is there any  way  for rockets to fly in space , other then throwing mass
> > out in one direction and moving in other
> 
> Yes.
> 
> Ben

Can you give us a patent number or other reference on your
"reactionless drive", Ben? :)


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

Date: Tue, 09 Mar 2004 13:33:02 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Rockets Alternative
Message-Id: <090320041333025139%jgibson@mail.arc.nasa.gov>

In article <24m3c.44509$Ak2.13908812@news4.srv.hcvlny.cv.net>, John W.
Kennedy <jwkenne@attglobal.net> wrote:

> George Kinley wrote:
> > Is there any  way  for rockets to fly in space , other then throwing mass
> > out in one direction and moving in other
> 
> Apart from the fact that this is wildly off-topic, have you considered 
> looking up the definition of the word "rocket"?
> 
> Assuming that you meant "space vessel", and not "rocket", the answer is 
> that gravity can be used for certain purposes, under certain conditions, 
> but you couldn't get anywhere using gravity alone; in general, there is 
> no known way other than reaction.  (Again, under certain circumstances, 
> for certain purposes, ridiculously powerful magnets or electrostatic 
> charges could be used in theory, but such devices would be neither 
> practical nor safe.)

What about solar wind sailing?


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

Date: 09 Mar 2004 21:50:58 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: storing and accessing a has in a package
Message-Id: <slrnc4sf21.8k7.mgjv@verbruggen.comdyn.com.au>

On Tue, 09 Mar 2004 12:37:46 +0200,
	user@domain.invalid <user@domain.invalid> wrote:
> How can I store a hash array so that I can access it within a package?

From the whole thread, I gather that you have what is commonly known
as a XY problem. You need to solve X, and have already concluded you
need to do Y for that. So, instead of asking about X here, you ask
about Y.

Why don't you tell us why you think you need a hash? What is the
problem you're trying to solve?

The general answer to what you ask up there is probably: use a package
scoped hash variable, or a package scoped array to store hash
references, if you ened more than one. I doubt that it is the answer
you really need, though.

Martien
-- 
                        | 
Martien Verbruggen      | Unix is user friendly. It's just selective
Trading Post Australia  | about its friends.
                        | 


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

Date: Tue, 09 Mar 2004 19:45:05 GMT
From: Kirk Strauser <kirk@strauser.com>
Subject: Re: teaching myself perl - stumped on this one!
Message-Id: <877jxtrenf.fsf@strauser.com>

=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-03-08T04:12:01Z, "Martin Livingston" <mjpliv@hfx.eastlink.ca> write=
s:

> $catagory=3Dparam("catagory");
> $name=3Dparam("name");
> $description=3Dparam("description");
> $source=3Dparam("source");
> $origin=3Dparam("origin");
> $ingredients=3Dparam("ingredients");
> $method=3Dparam("method");
> $service=3Dparam("service");
> $picture=3Dparam("picture");
> $filename=3D param("filename");
> $imgfilename =3D  param("imgfilename");

Blocks of code like that always scream "hash! hash!".  Consider something
like:

my %formvars;

foreach my $key (qw/category name description source origin ingredients
                    method service picture filename imgfilename/)
{
    $formvars{$key} =3D param($key)
}

and replace occurences of $ingredients with $formvars{'ingredients'}, for
example.

This makes code much more readable, it's trivially easy to add new
variables, and you'll never be guessing whether $formvars{'something'} is a
value you got from the form or whether you calculated it at runtime - the
name says it all.
=2D --=20
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFATh4V5sRg+Y0CpvERAo/qAJ9JXRDjvwu5jOyk19i9B/bW92U33wCfZBEm
+aaYSFgc2VBFCDWk+7q33Xw=3D
=3DAN+p
=2D----END PGP SIGNATURE-----


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

Date: Tue, 9 Mar 2004 15:00:06 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: teaching myself perl - stumped on this one!
Message-Id: <20040309145658.V27834@dishwasher.cs.rpi.edu>

On Tue, 9 Mar 2004, Kirk Strauser wrote:

> At 2004-03-08T04:12:01Z, "Martin Livingston" <mjpliv@hfx.eastlink.ca> writes:
>
> > $catagory=param("catagory");
> > $name=param("name");
> > $description=param("description");
> > $source=param("source");
> > $origin=param("origin");
> > $ingredients=param("ingredients");
> > $method=param("method");
> > $service=param("service");
> > $picture=param("picture");
> > $filename= param("filename");
> > $imgfilename =  param("imgfilename");
>
> Blocks of code like that always scream "hash! hash!".  Consider something
> like:
>
> my %formvars;
>
> foreach my $key (qw/category name description source origin ingredients
>                     method service picture filename imgfilename/)
> {
>     $formvars{$key} = param($key)
> }
>
> and replace occurences of $ingredients with $formvars{'ingredients'}, for
> example.
>

Alternatively, you might as well just ask CGI.pm to create the variables
for you:

import_names();

Then access each var as $Q::category, $Q::name, etc etc

Paul Lalli


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

Date: Tue, 09 Mar 2004 20:21:19 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: teaching myself perl - stumped on this one!
Message-Id: <e2297c06fbcdae2b1899a77d6d00f192@news.teranews.com>

>>>>> "Paul" == Paul Lalli <ittyspam@yahoo.com> writes:

Paul> Alternatively, you might as well just ask CGI.pm to create the variables
Paul> for you:

Paul> import_names();

Paul> Then access each var as $Q::category, $Q::name, etc etc

Ugh.  Almost always, someone THEN asks "how do I iterate over
$Q::field1, $Q::field2, $Q::field3?" then.

Please don't create Perl variables based on data names. :)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6240
***************************************


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