[19431] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1626 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 27 09:10:35 2001

Date: Mon, 27 Aug 2001 06:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998917506-v10-i1626@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 27 Aug 2001     Volume: 10 Number: 1626

Today's topics:
    Re: $1 as subroutine parameter - problems <markus.laire@usa.net>
    Re: $1 as subroutine parameter - problems <markus.laire@usa.net>
        adding rows in a text file (soumitra bhattacharya)
    Re: File::Find not recursing on Win32 Perl 5.001 (Randal L. Schwartz)
    Re: fwd: Sex or perl? <markus.laire@usa.net>
    Re: It's to AM for me to think (Anno Siegel)
        Object oriented question <jwl@sgi.com>
    Re: Perl help <bart.lateur@skynet.be>
    Re: Problems with fixed-length random access databases. <dscarlett@optushome.com.au>
    Re: Problems with fixed-length random access databases. <tinamue@zedat.fu-berlin.de>
    Re: Problems with fixed-length random access databases. <dscarlett@optushome.com.au>
        Two simple structures! but what is the difference? <Pcmann1@btinternet.com>
    Re: Two simple structures! but what is the difference? <tinamue@zedat.fu-berlin.de>
    Re: Two simple structures! but what is the difference? (Martien Verbruggen)
    Re: uploadin images into tables? <swancar2000@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 27 Aug 2001 12:21:15 GMT
From: Markus Laire <markus.laire@usa.net>
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <Xns910A9C3C13BE6markuslaire@192.89.123.233>

> Bart Lateur had written:
>> test("$1")
>> will make a temporary copy of it.
> 
> You seem to like that solution. With respect to preserving the variable
> being passed, it's effectively the same as using "test($1)" with "my
> ($copy) = @_;" except that the latter will allow you to remember what
> you're doing when you come back to it in 6 months when "tightness" has
> less value than clarity. 

I admit that "my ($copy) = @_;" might be better for clarity, but I really 
like test("$1"), because in this case those normally superfluous quotes 
really have some use.

Anyway, it's always nice to know MTOWTDI :)


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

Date: Mon, 27 Aug 2001 12:36:51 GMT
From: Markus Laire <markus.laire@usa.net>
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <Xns910A9EE0DE7EDmarkuslaire@192.89.123.233>

ebohlman@omsdev.com (Eric Bohlman) wrote in
news:9mbr2l$8kv$2@bob.news.rcn.net: 
>>
>> I thought that test(my $temp = $1) is too long to be nice perl so I
>> was thinking a way to make it shorter. test("$1") is nice. 
> 
> How are those superfluous quote marks "nice"?  In fact, putting quote
> marks around variable names in sub calls is a very bad habit to get
> into, because it will blow up on you when you need to pass any kind of
> reference to a sub (the quotes will stringify the reference passed to
> the sub, making it unusable as a reference).

In this case I need to pass a copy of $1 to sub and definitely not a 
reference, so usually superfluous quotes have real use for once.



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

Date: 27 Aug 2001 05:36:52 -0700
From: soumitra@mailandnews.com (soumitra bhattacharya)
Subject: adding rows in a text file
Message-Id: <72fd0cf4.0108270436.6d948a8e@posting.google.com>

Hi!
I have a txt file of the following format
1||15||8||99||08||7
2||15||8||99||08||7
3||33||55||3||2||1
4||109||3||0||1||80
5||78||5||0||2||88
6||55||4||0||1||67
7||44||6||0||1||85
8||25||7||0||1||70
13||6||7||0||0||36
14||3||13||0||6||50
15||9||12||0||0||51
16||3||12||0||1||48
17||4||32||1||16||165
18||1||5||1||2||78
The first piece of data in each row is the number of logins and
the next datas are mails read||deleted||etc for login.
I want to generate a graph
but I want to sum on the basis of number of logins after 4.
i.e.
1||....
2||..
3||..
4||...
5-10||sum of mails read for 5 to 10||sum of mails deleted for5-10||.....
11-20||...
21-30||....
31-40||...
41-50||....
50-whatever is max
so in first row will be data for people logged in once,
but in row 5-10 will be sum of data in rows 5,6,7,8,9,10 if they exist.
similarly for the row named 11-20 will be sum of data in rows 11..20 if they exist.
How do I do this.
Any Help will be appreciated.
Soumitra


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

Date: 27 Aug 2001 03:31:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: File::Find not recursing on Win32 Perl 5.001
Message-Id: <m1r8txrdz8.fsf@halfdome.holdit.com>

>>>>> "Phil" == Phil Hibbs <phil.hibbs@capgemini.co.uk> writes:

Phil> I tried this from the cookbook:
Phil> @ARGV = qw(.) unless @ARGV;
Phil> use File::Find;
Phil> find sub { print $File::Find::name, -d && '/', "\n" }, @ARGV;

Phil> It doesn't recurse into subdirectories. Ideas why not? I can't upgrade
Phil> my perl, as this has to function on other machines with standard
Phil> installs.

Are you giving it directories on the command line (@ARGV)?  Do they
have any actual subdirectories (as opposed to symlinks to directories,
which will NOT be recursed)?  What does invoking this with @ARGV set
to qw(/) do?

-- 
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: Mon, 27 Aug 2001 12:44:59 GMT
From: Markus Laire <markus.laire@usa.net>
Subject: Re: fwd: Sex or perl?
Message-Id: <Xns910AA041C26B6markuslaire@192.89.123.233>

"Brian A. Stumm" <bs@bs-linux.com> wrote in 
news:Pine.LNX.4.21.0108262009150.3683-100000@bdslppp62.spkn.uswest.net:
>
> But to answer the question, Sex is better. Eventually Perl will be
> outdated and obsolete. Sex ensures that their will be future programmers
> creating newer, better software...

You don't need sex for that if you just write learning AI in perl for 
developing better Perl/other software.

So perl is better because there is no need for sex anymore. ;)



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

Date: 27 Aug 2001 11:37:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: It's to AM for me to think
Message-Id: <9mdbdo$5nf$1@mamenchi.zrz.TU-Berlin.DE>

According to Logan Shaw <logan@cs.utexas.edu>:

> By the way, I just realized there is an optimization to my method
> that also makes the code clearer in addition to being faster:
> 
> 	@array = qw{ -111 6 5 7 89 3 76 };
> 
> 	$largest = $array[0];	# assume first element is largest

        $largest = shift @array;

> 	foreach my $i (@array)
> 	{
> 	    $largest = $i if $i > $largest;
> 	}
> 
> 	print $largest, "\n";

A minuscule optimization, but it comes free.

Anno


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

Date: Mon, 27 Aug 2001 09:00:14 -0400
From: Jim Lynch <jwl@sgi.com>
Subject: Object oriented question
Message-Id: <3B8A445E.3D71C3C1@sgi.com>

Is there a way within the OO framework of Perl to initialize variables
at the first instantance of an object other than making them global?

Here's what I want to do.  I want to create objects that contain the
data from a since row of a database fetch.  Since the prepare operation
of the DBI module needs only be done once and is expensive (time wise),
I'd like to do the prepare only once when the first row object is
created.  Same goes for the database connect.  I know I could make the
prepare global but that kind of defeats the spirit of object oriented
programming.  I suppose I could put the onus on the programmer and
require that he instantiate another class that contains the prepared
statement(s) and open the database, but if possible I'd like to hide
that complexity.   

Any suggestions?

Thanks,
Jim.


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

Date: Mon, 27 Aug 2001 13:03:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl help
Message-Id: <lsgkot8er93s57pnr72ahl129bsn52ooa1@4ax.com>

teleconnect wrote:

>I'v
>read "local" is replaced with "my" in Perl 5, yet I see some programmers
>using it, even in Matt's Script Archive.

"EVEN" in Matt's Script Archive?

Matt's script have been written when he was a young lad, years ago, it
pretty much predates Perl5. It never got fixed into being reliable. It's
still beta software, and it will never grow beyond it.

But, with regards to your question: there's an entry in the FAQ,
distributed with every perl distribution, in perlfaq7:

   What's the difference between dynamic and lexical (static) scoping?
   Between local() and my()?

The gist: local() *temporarily* replaces a value. The changes are
visible in subs called from the block where the variable got localised.
my() makes variables only visible *within* the block. That's why most
people find "my" easier to deal with, though local() is more powerful.
Perl4 only knew about local().

-- 
	Bart.


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

Date: Mon, 27 Aug 2001 11:18:21 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <10qi7.23373$A5.71742@news1.eburwd1.vic.optushome.com.au>

"David Scarlett" <dscarlett@optushome.com.au> wrote in message
news:yo1i7.22829$A5.70124@news1.eburwd1.vic.optushome.com.au...

Ok, I think I'm getting somewhere with this... ;-)

>
> Here's the subroutine used for writing (and variables declared/files
opened
> beforehand):
> ----------------
> my($pstring) = "LSfC";        # Pack control string.
> my($psize) = length($pstring);    # Length of each record.

This should have been:
my($psize) = length(pack($pstring));

> open(DB,"+>>ping.dat") || die "Error: Cannot open ping.dat. $!\n";

This should have been:
if (-e "ping.dat") {
    open(DB,"+<ping.dat") || die "Error: Cannot open ping.dat. $!\n";
} else {
    open(DB,"+>ping.dat") || die "Error: Cannot open ping.dat. $!\n";
}
binmode(DB);

>
> ----------------
> sub output {                        # @_ == (IP,PORT,PING)
>     my($ptotal,$n,$bytes,$buf) = (0,0);
>
>     seek(DB,0,0);
>     $bytes = read(DB,$buf,$psize);
>
>     SEARCH: while ($bytes == $psize) {
>         if (@_[0,1] == (unpack($pstring,$buf))[0,1]) {    # Record found.
>              ($ptotal,$n) = (unpack($pstring,$buf))[2,3];
>              break SEARCH;

This should have been last, not break. It appears I have C on the
brain.......

>         }
>
>         $bytes = read(DB,$buf,$psize);
>     }
>
>     if ($bytes == $psize) {                # Guess it didn't find the
> record...
>         seek(DB,0,2);
>     } else {                        # Or did it?....
>         seek(DB,-$psize,1);
>     }
>
>     $n++;
>     $ptotal += $_[2];
>
>     print DB pack($pstring,$_[0],$_[1],$ptotal,$n);
>
>     return;
> }
> ----------------
>
>
> TiA,
> --
> David Scarlett
> dscarlett@optushome.com.au
> http://www.listen.to/artifice/
> http://members.optushome.com.au/dscarlett/
>
> "Is your feng-shui properly aligned? If so, take a hard look at your life.
> Why would you know what feng-shui is, means or tastes like? If you truly
> believe that placing a plant in the northeast corner of your power square
> will foster financial prosperity, give up now. Believing that a dwarfed
tree
> is going to right all of your life's wrongs is simply desperation."
>         -FIGHT CLUB promotional catalogue
>
>




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

Date: 27 Aug 2001 11:39:40 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <9mdbhs$1jjjd$1@fu-berlin.de>

David Scarlett <dscarlett@optushome.com.au> wrote:
> "Eric Bohlman" <ebohlman@omsdev.com> wrote in message
> news:9mbrqc$8kv$3@bob.news.rcn.net...
>> David Scarlett <dscarlett@optushome.com.au> wrote:
>> >         if (@_[0,1] == (unpack($pstring,$buf))[0,1]) {    # Record
> found.
>>
>> You can't compare lists like this.

> I beg to differ. Have a look at the following script and it's output.

> my(@array) = (1,2,3,4,5,1,2,3,4,5);

> foreach $i (0,1,2,3) {
>     foreach $j (5,6,7,8) {
>  if (@array[$i,$i+1] == @array[$j,$j+1]) {
>      print "True\n";
>  } else {
>      print "False\n";
[...]

you're not comparing the lists to each other. look at this:
01:25pm tina@lux:inline 943> perl -wle'
@a=(1,2);   # @a and @b are equal
@b=(1,2);
if (@b[0..1]==@a[0..1]) {print "ok"}'
ok
            # ok, they're equal
01:25pm tina@lux:inline 944> perl -wle'
@a=(1,3);   # they're not equal, the last element differs
@b=(1,2);
if (@b[0..1]==@a[0..1]) {print "ok"}'
            # no output, so they differ
01:27pm tina@lux:inline 945> perl -wle'
@a=(1,2);   # they differ, that means, their first arguments differ
@b=(4,2);
if (@b[0..1]==@a[0..1]) {print "ok"}'
ok
            # script says they're equal.

be careful with array slices. an array slice like
@a[1..4]
means:
($a[1], $a[2], $a[3], $a[4]). so 

" if (@b[0..1]==@a[0..1]) " means:

if (($b[0],$b[1]) == ($a[0], $a[1]))

that's the comma operator, and only the last element
is returned with the comma operator.

regards,
tina

-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


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

Date: Mon, 27 Aug 2001 11:47:47 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <Drqi7.23388$A5.72042@news1.eburwd1.vic.optushome.com.au>

"Tina Mueller" <tinamue@zedat.fu-berlin.de> wrote in message
news:9mdbhs$1jjjd$1@fu-berlin.de...
>
> that's the comma operator, and only the last element
> is returned with the comma operator.

Ahh, that explains it. Thanks. :-)


--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/

"Is your feng-shui properly aligned? If so, take a hard look at your life.
Why would you know what feng-shui is, means or tastes like? If you truly
believe that placing a plant in the northeast corner of your power square
will foster financial prosperity, give up now. Believing that a dwarfed tree
is going to right all of your life's wrongs is simply desperation."
        -FIGHT CLUB promotional catalogue




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

Date: Mon, 27 Aug 2001 12:51:04 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Two simple structures! but what is the difference?
Message-Id: <9mdc4o$67u$1@plutonium.btinternet.com>

Dear all,
    I have a program im trying to restructure, but there is a small
fragement of code that is causing problems. Initially I have 'strucure 1',
but i am trying to adapt it to 'structure 2' because I want to put more
stuff in the 'if' and the 'else' blocks. I throught 'strucure 1' was
shorthard, for what I am trying to achive in 'structure 2', so where am I
going wrong?
p.s. - 'check_fragement' and 'check_base' are two other subs, ones that I
want to call all within strucutre 2 rather than call them seperately!
Any suggestions what the difference is would be much appreciated!
Thanks
   - Pete


#-------------------------
# Structure 1
my $check    = defined $fragment ? 'check_fragment' :
            'check_base';
#-------------------------


#-------------------------
# Structure 2
 my $check;
  if (defined $fragment) {
        $check = check_fragement()
  }
  else
  {
        $check = check_base()
  }
#-------------------------


 my $success  = $link->$check();





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

Date: 27 Aug 2001 12:22:14 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Two simple structures! but what is the difference?
Message-Id: <9mde1m$1jjjd$2@fu-berlin.de>

Peter Mann <Pcmann1@btinternet.com> wrote:
> Dear all,
>     I have a program im trying to restructure, but there is a small
> fragement of code that is causing problems. Initially I have 'strucure 1',
> but i am trying to adapt it to 'structure 2' because I want to put more
> stuff in the 'if' and the 'else' blocks. I throught 'strucure 1' was
> shorthard, for what I am trying to achive in 'structure 2', so where am I
> going wrong?
> p.s. - 'check_fragement' and 'check_base' are two other subs, ones that I
> want to call all within strucutre 2 rather than call them seperately!
> Any suggestions what the difference is would be much appreciated!
> Thanks
>    - Pete


> #-------------------------
> # Structure 1
> my $check    = defined $fragment ? 'check_fragment' :
>             'check_base';

this means:
if (defined $fragment) { $check = 'check_fragment' }
else {$check = 'check_base' }

hth,
tina
-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


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

Date: Mon, 27 Aug 2001 22:31:14 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Two simple structures! but what is the difference?
Message-Id: <slrn9okfci.3ga.mgjv@martien.heliotrope.home>

On 27 Aug 2001 12:22:14 GMT,
	Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:
> Peter Mann <Pcmann1@btinternet.com> wrote:
> 
>> #-------------------------
>> # Structure 1
>> my $check    = defined $fragment ? 'check_fragment' :
>>             'check_base';
> 
> this means:

my $check;

> if (defined $fragment) { $check = 'check_fragment' }
> else {$check = 'check_base' }

To the OP:

The perlop documentation explains the ?: operator under the header
'Conditional Operator'

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd.   | selective about its friends.
NSW, Australia                  | 


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

Date: Mon, 27 Aug 2001 12:19:11 +0100
From: "Julie" <swancar2000@yahoo.com>
Subject: Re: uploadin images into tables?
Message-Id: <OZpi7.14012$3f.3209981@news2-win.server.ntlworld.com>

Thanks for all of your replies.
I am using webdatabase, and I have to put a variable in the spot where I
want the image to appear, this variable being $data
[9] this will return a unique image for each relating record.
I have tried the following;

<img src="$data[9] width="500" height="107" alt="picture-house"> but this
does not work, CSS works but only on Explorer,
I am not knowledgeable to integrate further CGIs, is there any other way of
achieving my goals, perhaps by locking the table cells so that any large
images will be squashed in therefore making the uploading person re-size
their images for a better out-come I have seen this somewhere before. any
help really is appreciated.
Thanks
Julie




E.Chang <echang@netstorm.net> wrote in message
news:Xns9109D1CEC55CBechangnetstormnet@207.106.92.86...
> "Julie" <swancar2000@yahoo.com> wrote in
> <U_fi7.28270$_71.1695285@news6-win.server.ntlworld.com>:
>
> > I am very new to all this and so my question maybe very simple to
> > all you lot.
> > I am using a perl script for a database and I am allowing people to
> > upload pictures as well as their data, the problem is that I would
> > like to have all the pictures appear in a table cell to be all the
> > same size. I have tried to use CSS but this only works in Explorer,
> > is there another way I can do this either by setting the size of
> > the table cell so that any large images that are uploaded can be
> > squashed into the cell or is there a way to make it mandatory that
> > a set picture size has to be uploaded. I already have it set so
> > that the file size is mandatory but not image dimensions.
>
> As I understand it, you are printing out an image tag for each image
> displayed and want to control the size.  Instead of trying to set the
> dimensions of the table cell, just set the dimensions of the image
> using standard height and width attributes:
>
> print qq(<img src="$whatever_it_is" height="$calculated_height
> width="$calculated_width" alt="Of_course_you_use_image_alts.">);
>
> The use of the qq operator saves escaping the double quotes in the
> string.  (And justifies this as a Perl question rather than just an
> HTML question, which would belong in another newsgroup.)
>
> --
> EBC




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

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.  

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


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