[16738] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4150 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 28 09:05:43 2000

Date: Mon, 28 Aug 2000 06:05:18 -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: <967467918-v9-i4150@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 28 Aug 2000     Volume: 9 Number: 4150

Today's topics:
    Re: @_ as array (Martien Verbruggen)
        ANNOUNCE: Spreadsheet::WriteExcel 0.20 - Multiple works mcnam@my-deja.com
        appending to files <mslho@my-deja.com>
    Re: appending to files <carvdawg@patriot.net>
    Re: appending to files <lincolnmarr@nospam.europem01.nt.com>
    Re: basic question <gellyfish@gellyfish.com>
    Re: basic question <flavell@mail.cern.ch>
    Re: Bulk add to a hash.. Any ideas? (Jakob Schmidt)
    Re: CD Rom with Perl? <gellyfish@gellyfish.com>
    Re: DB_File Problem: HELP!!! (Jakob Schmidt)
        Debugging tools <are.bjoerby@pineapple.no>
        directory where perl script is <beric20@my-deja.com>
        Evenlog module <jco@hetnet.nl>
    Re: Finding size of image size of  jpeg file <i_hate_spam@do-not-mail.org>
    Re: Finding size of jpeg file <stig@palmquist.org>
    Re: Formatting text (CGI) <gellyfish@gellyfish.com>
        Getting slices of this ...(not pizza) <webmaster@ostas.lu.se>
    Re: Golf: Date of Easter <tony@pyxis.blackstar.co.uk>
    Re: How do I manipulate each element of an array? <dietmar.staab@t-online.de>
    Re: How do I manipulate each element of an array? <whatever@hnv.com>
    Re: How do I manipulate each element of an array? (Jakob Schmidt)
    Re: How do I manipulate each element of an array? <elephant@squirrelgroup.com>
    Re: How do I manipulate each element of an array? <gellyfish@gellyfish.com>
    Re: How do I manipulate each element of an array? <lincolnmarr@nospam.europem01.nt.com>
    Re: How to Unzip a .tar.gz file <gellyfish@gellyfish.com>
    Re: Installation of perl 5.6 on Solaris 2.5.1 <gellyfish@gellyfish.com>
    Re: Kill Me! <iltzu@sci.invalid>
    Re: mod_perl & heap <gellyfish@gellyfish.com>
    Re: Module to Download HTML Pages <gellyfish@gellyfish.com>
        MySQL and perl <abel@inlander.es>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 28 Aug 2000 22:42:44 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: @_ as array
Message-Id: <slrn8qkk1k.3fr.mgjv@martien.heliotrope.home>

[alt.perl removed from Newsgroups list]

On 25 Aug 2000 08:14:52 -0700,
	Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> here" and if you got the wrong one, throw in the scalar or the
> (...)[0] tricks.  And don't over use those.  I see this all the time:
> 
>         $n = scalar @a;
> 
> Bleh!  That's a bit like strapping training wheels onto your training
> wheels.

I'm not sure... It's almost the same as writing

	(void) fprintf(stdout, "Stuff\n");

in C. Of course, in C it also helps to shut up overzealous warnings from
compilers and lint. But it also helps the programmer to see that you did
indeed mean to chuck away that return value. In the

	$n = scalar @a;

case, the programmer makes it just extra clear that, yes, I did mean to
asign the number of elements here, and not something else.

I wouldn't do it, but I don't have as much of a Bleh reaction as you do.

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


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

Date: Mon, 28 Aug 2000 08:16:45 GMT
From: mcnam@my-deja.com
Subject: ANNOUNCE: Spreadsheet::WriteExcel 0.20 - Multiple worksheet version
Message-Id: <sqkgikdt9110@corp.supernews.com>



NAME
    Spreadsheet::WriteExcel - Write text and numbers to a cross-
    platform Excel binary file.

DESCRIPTION
    This module can be used to write numbers and text in the native
    Excel binary file format. Multiple worksheets can be added to a
    workbook. Formatting of cells is not yet supported.

    The Excel file produced by this module is compatible with Excel 5,
    95, 97 and 2000.

    The module will work on the majority of Windows, UNIX and
    Macintosh platforms. Generated files are also compatible with the
    Linux/UNIX spreadsheet applications Star Office, Gnumeric and
    XESS.

    This module cannot be used to read an Excel file. Look at the main
    documentation for some suggestions.

DOWNLOAD
    http://search.cpan.org/search?dist=Spreadsheet-WriteExcel

    ActivePerl users can use PPM as follows:
    C:\> ppm
    PPM> set repository tmp http://homepage.eircom.net/~jmcnamara/perl
    PPM> install Spreadsheet-WriteExcel
    PPM> quit
    C:\>

VERSION
    This document refers to version 0.20 of Spreadsheet::WriteExcel,
    released Aug 27, 2000.

AUTHOR
    John McNamara (jmcnamara@cpan.org)
--
Before you die()


Sent via Deja.com http://www.deja.com/
Before you buy.




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

Date: Mon, 28 Aug 2000 10:00:49 GMT
From: Manuel Ho <mslho@my-deja.com>
Subject: appending to files
Message-Id: <8odd8c$mld$1@nnrp1.deja.com>

hi all,

how can i achieve appending to the second last line of a file?
and is there a function in perl that reads a line at a time?
thanks all.

manuel.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 28 Aug 2000 06:52:10 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: appending to files
Message-Id: <39AA445A.EA9C85CA@patriot.net>

my $str = "text to append to 2nd line of file";
open(FH,$myfile) || die "Could not open $myfile to read: $!\n";
my @lines = <FH>;
close(FH);
$lines[1] = $lines[1].$str;
open(FH,">$myfile") || die "Could not open $myfile to write: $!\n";
map{print FH $_;}@lines;
close(FH);


Manuel Ho wrote:

> hi all,
>
> how can i achieve appending to the second last line of a file?
> and is there a function in perl that reads a line at a time?
> thanks all.
>
> manuel.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

Date: Mon, 28 Aug 2000 12:50:59 +0200
From: "Lincoln Marr" <lincolnmarr@nospam.europem01.nt.com>
Subject: Re: appending to files
Message-Id: <8odg61$3rm$1@qnsgh006.europe.nortel.com>

>how can i achieve appending to the second last line of a file?
>and is there a function in perl that reads a line at a time?
>thanks all.

You can't tell perl to find the second last line of a file (unless the lines
are all exactly the same length). What you can do however, is make a
temporary copy of the file, update the line you want, then copy the file
back into its original location. See perl faq5  "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?"

To read a line in one at a time, you can use the diamond operator (this is
only a sensible option if the files are relatively small - as they get
bigger you may begin to run out of memory). What I do is the following:

open(FILE,"$filename");
@line = <FILE>;
close(FILE);
foreach (@line) {
  ## do what you want with each line, eg split it, print it etc
}

Hope this helps.

--Lincoln






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

Date: 28 Aug 2000 10:06:22 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: basic question
Message-Id: <8oda2e$d99$1@orpheus.gellyfish.com>

On Mon, 28 Aug 2000 02:17:43 GMT Kevin Ackerman wrote:
> Hello,
>     I have one simple question, What is the difference between PERL and CGI.
> My closest guess is that PERL is an interpreted language and CGI is the
> *thing* that makes PERL and a web browser work together. However, I am not
> satisfied that this is correct. Any help with the correct answer to my
> question would be greatly appreciated.
> 

You are nearly there.

The Common Gateway Interface is a specification that determines how a web
*server* and a program that is invoked as a result of a user request will 
communicate. Perl is a commonly used language for the creation of such
programs however any language that can supply the input and output
requirements of the specificaton can be used.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Mon, 28 Aug 2000 12:43:17 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: basic question
Message-Id: <Pine.GHP.4.21.0008281233590.25951-100000@hpplus03.cern.ch>

On 28 Aug 2000, Abigail wrote:

> Well, noone knows what PERL is, as PERL was never created.

http://support.microsoft.com/support/kb/articles/Q164/6/72.asp

"IE Does Not Interpret PERL Scripts Correctly as Plain Text", is what
MS calls it.  So it seems that somebody must have created "PERL"  ;-}

Reading the article, however, you'll find what it really says is
"IE does not interpret plain text correctly as plain text".
The fact that the plain text in question was generated by a Perl
script is completely irrelevant to the problem under review.

They further claim that

  We are researching this problem and will post new
  information here in the Microsoft Knowledge Base as it becomes
  available. 

although elsewhere they document this mishandling as intentional
and desirable:

http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp

while making no mention of the potentially serious security exposure
which this involves.

all the best



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

Date: Mon, 28 Aug 2000 12:45:12 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: Bulk add to a hash.. Any ideas?
Message-Id: <1eg2qv3.60p37ppyqryaN@[192.168.88.117]>

brian d foy <brian@smithrenaud.com> wrote: 
>
> [ you snipped the good parts! ]

Some guys have all the luck :-)
 
> > Well if you're going to add a 'bulk' (sounds like at least a dozen k-v
> > pairs to me) it'll enhance readability hugely IMHO.
> 
> then, i would suggest that a slice is not a good way to do it
> (from a readability perspective).

I suppose you like

In article <8oc336$8um$1@nnrp1.deja.com>,  <alphazerozero@my-deja.com>
wrote:
>$hash->{'key3'}="value3";  #however this
>$hash->{'key4'}="value4";  #does... But surely its more verbose than

better (from a readability perspective)?

Well - maybe that's more readable but then it's a bit clumbsy too. It's
a trade-off. TMTOWTDI.

By the way there's also the possibility of making a hash concatenation
like so:

%add = ( key5 => 'value5', key6 => 'value6' );
@$hash_reference{ keys %add } = values %add;

This spends an extra variable and some cycles but enables you to use the
customary idiom for hash assignment, so for readability that may be my
best bet. Besides it's easily subroutinized.

-- 
Jakob


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

Date: 28 Aug 2000 09:40:29 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: CD Rom with Perl?
Message-Id: <8od8ht$d78$1@orpheus.gellyfish.com>

On Mon, 28 Aug 2000 07:54:28 GMT reevehot@hotmail.com wrote:
> I've got a job to put some HTML-driven information onto CD Rom. As I
> understand it, a browser will read HTML (and Javascript)from a CD Rom
> just as well as from the web.
> 
> However, can I use my CGI-BIN? I guess what I mean is, I'm used to
> using form-to-mail and other Perl scripts on the web, but can these be
> used on a local machine?
> 

No you need a web server in order to run CGI programs.  If you want to
find a web server that is suitable to be run from a CD then you will want
to ask in one of the comp.infosystems.www.servers.* groups.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Mon, 28 Aug 2000 13:10:05 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: DB_File Problem: HELP!!!
Message-Id: <1eg2shc.1539fs9x70d22N@[192.168.88.117]>

Bob Walton <bwalton@rochester.rr.com> wrote:

> If your keys and values don't contain newlines, carriage returns or form
> feeds and the keys don't contain colons

otherwise you can (probably) use the Data::Dumper module (I can't test
it right here, but I assumes that it'll dump a tied hash).

-- 
Jakob


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

Date: Mon, 28 Aug 2000 10:42:54 GMT
From: "Are Bjoerby" <are.bjoerby@pineapple.no>
Subject: Debugging tools
Message-Id: <Omrq5.6590$Dxe.196385280@news.telia.no>

Hi all,

I am developing scripts for a server without any debugging modules
installed.
Is there any tool available that will compile a script and check for syntax
errors?

--
mvh,
Are Bjørby

// What's the frequency, Kenneth?




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

Date: Mon, 28 Aug 2000 12:48:07 GMT
From: Eric BULEON <beric20@my-deja.com>
Subject: directory where perl script is
Message-Id: <8odn20$13f$1@nnrp1.deja.com>

Hello

I want to know in which directory the currently running Perl script is.
How can I do that ?

Thanks

--
Eric


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 28 Aug 2000 13:58:14 +0200
From: "Johan" <jco@hetnet.nl>
Subject: Evenlog module
Message-Id: <ujp0AdOEAHA.61@net003s>

I wrote a script to get the eventlog records from several machines. All
fields in the hash are filled correct except the 'user' field. Anybody else
who came across this problem and found a solution? I'm working with
Activestate Perl build 5.6.0 build 616
thanks in advance,
Johan





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

Date: Mon, 28 Aug 2000 16:13:06 +0530
From: "Debjit" <i_hate_spam@do-not-mail.org>
Subject: Re: Finding size of image size of  jpeg file
Message-Id: <8oekkt$233$1@news.vsnl.net.in>

Thanks. Meanwhile I dowloaded Image::Size from CPAN, working great for me!
use Image::Size;
my ($globe_x, $globe_y) = imgsize("a.jpg");
print $globe_x, "\t", $globe_y;

zejames@my-deja.com wrote in message <8odcrv$mhf$1@nnrp1.deja.com>...
>
>
>> Is there any way I can find the width and height in pixel, of a jpeg
>file by perl program?
>
>You can have a look at the GD Perl module:
>
>use GD;
>
>$image = newFromJpeg GD::Image('image.jpeg');
>
>($width,$height) = $image->getBounds()
>
>
>
>
>Hope this helps
>
>James
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.




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

Date: 28 Aug 2000 12:17:13 +0200
From: Stig Palmquist <stig@palmquist.org>
Subject: Re: Finding size of jpeg file
Message-Id: <m3vgwlsn9y.fsf@stig.a.sol.no>

"Debjit" <i_hate_spam@do-not-mail.org> writes:

> Is there any way I can find the width and height in pixel, of a jpeg file by
> perl program?

http://www.cpan.org/authors/id/R/RJ/RJRAY/Image-Size-2.903.tar.gz

-- 
Stig Palmquist <stig@palmquist.org>


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

Date: 28 Aug 2000 10:52:47 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Formatting text (CGI)
Message-Id: <8odcpf$dcm$1@orpheus.gellyfish.com>

On Sat, 26 Aug 2000 15:33:16 GMT Jeff Helman wrote:
> bretttdonovan wrote:
>> 
>> Does anyone know how to format text strings so that I can for example have
>> scripts kicking out arial font instead of default?
>> 
> Yes.  First, investigate an HTML book to learn about the <FONT> tag. 
> Then incorporate that into your perl output.
> 

Or alternatively read the HTML 4 specification to discover that the FONT
tag is not present and then use the facilities provided by the CGI module
to incorporate Cascading Style Sheets.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Mon, 28 Aug 2000 14:45:29 +0200
From: Jimmy Lantz <webmaster@ostas.lu.se>
Subject: Getting slices of this ...(not pizza)
Message-Id: <39AA5EE8.97437996@ostas.lu.se>

Hi, I have a problem of getting two arrays from a file, I dont know
which method is the fastest.
I currently use an foreach then push the result according to an if /
else statement into 2 arrays.

I have a clumsy validation script which checks (2 times only) if an
created username doesnt already exist else it changes it slightly. and
revalidates it.
I would welcome any suggestion on to how to improve that one.

I also welcome any suggestion on how to make the rest of the program
better.
Chers
Jimmy Lantz

################### Macperl program. #############

#!PERL
use KursModul;
use Mail::Sendmail;
use Time::localtime;
use PwdScrambler;
########################
#Att ordna: lägga till koll på vilka som fått mail, ordna *grep* på de
som saknar email# , skriva ut rapport lista.
########################
#read form input and format input
if ($ENV{'REQUEST_METHOD'} eq 'GET'){ KursModul::read_form_get(); }
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { KursModul::read_form_post();}

else { KursModul::read_form_get();}
#######################
#Set vars
my $DBbasedir = 'Server G4:DATABAS:';
my $DBdatadir = 'Server G4:DATABAS:data:';
my $DBDatafile = $DBdatadir . 'user.data';
my $realm = 'distanskurs';
KursModul::get_kurskod($KursModul::in{'meny'});# kurskod
$amne = $KursModul::amne;
$kod = $KursModul::kod;
$kurskod = $amne . $kod;
######################
#Main program

SetBaseFile();

@students = KursModul::read_file($DBBasefile);
@users = KursModul::read_file($DBDatafile);

my $studentline;
foreach $studentline (@students) {
    push(@student_rec, new_student($studentline));
 }

my $stud;
my @no_email;
my @have_email;

foreach $stud (@student_rec) {                  ############ Is there an
easier / faster  way to do this
if (${$stud}{'epost'} eq '#')                        ############
 { push(@no_email, $stud);}                      ############
else
############
{ push(@have_email, $stud);}                    ############

}

Handle_student(@have_email);
Handle_student2(@no_email);

####################
sub Handle_student
{
my(@student_record) = @_ ;
my $student;
foreach $student (@student_record) {

my $username = do_username(${$student}{'fnamn'}, ${$student}{'enamn'});
my $password = PwdScrambler::scramble(${$student}{'fnamn'},
${$student}{'enamn'});

append_file($DBDatafile);
send_email(${$student}{'fnamn'}, ${$student}{'enamn'}, $username,
$password, $epost);
}

}

sub Handle_student2
{
my(@student_record) = @_ ;
my $student;
foreach $student (@student_record) {
my $username = do_username(${$student}{'fnamn'}, ${$student}{'enamn'});
my $password = PwdScrambler::scramble(${$student}{'fnamn'},
${$student}{'enamn'});
append_file($DBDatafile);
Do_report(${$student}{'fnamn'}, ${$student}{'enamn'}, $username,
$password, $epost); #This sub is to large to enclose in this mail but
its working fine.
}

}

#####################
#Subs: SetBaseFile,  new_student, do_username
sub SetBaseFile # Med ansökningar
{
my $DBBasefile = $DBbasedir . $amne . ':' . $kurskod . '.data';
}

######################
sub new_student {
my($line) = @_ ;
    my @flds = split /:/, $line;

      my %stud_rec = (
       fnamn    => $flds[2],
       enamn    => $flds[3],
       epost   => $flds[4]);
    return \%stud_rec;
 }

###############
sub do_username
{
my($fnamn, $enamn) = @_ ;
my $year = localtime->year();#100
$year =~ /^1(\d\d)/;
$year = $1;

my $username = $year . $kod;
$fnamn =~ /(^[A-Z]{2})/;
$fnamn = $1;
$enamn =~ /(^[A-Z]{2})/;
$enamn = $1;

$username = $username . $fnamn . $enamn;

validate_username($username); #This validation is far from perfect

if ($user_error != 1)                    # This is a VERY
clumsy/insecure way to do it , ANY SUGGESTIONS ?
{
return $username;
}
else
{
$username = $username . '1';
validate_username($username);
if ($user_error != 1)
{
return $username;
}
else
{
$username = $username . '1';
}
}

 }
###################
sub validate_username
{
my($user) = @_ ;
foreach my $userline (@users)
 {
if($userline =~ /^$user/)
{
my $user_error = 1;
last;
}
else
{
next;
}

 }

 }
#####################




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

Date: Mon, 28 Aug 2000 11:39:34 GMT
From: Tony Bowden <tony@pyxis.blackstar.co.uk>
Subject: Re: Golf: Date of Easter
Message-Id: <Wbsq5.4490$SR1.92332@news6-win.server.ntlworld.com>

Marcel Grunauer <marcel@codewerk.com> wrote:
>>  $y=pop;$a=(19*($y%19)+24)%30;$b=22+$a+(2*($y%4)+4*($y%7)+6*$a+5)%7;
>>  print $b<32?"3/$b":"4/",$b-31
>>But I suspect this isn't the tersest algorithm ...

> It would appear the inline condition EXPR1 ? EXPR2 : EXPR3, when EXPR2
> is true, only stretches to the comma in EXPR3, since print() is a list
> operator.

*doh*

I've just scrolled back in screen, and at seems that every single test
year I fed it hit EXPR2, so I totally missed that! Must write better tests.
Must write better tests.

> In any case, this saves a few bytes and doesn't output the extra numbers
> at the end:
>     print int 3+$b/31,"/",$b%31;

Aha! Nice. I stared at that line for ages thinking there had to be a shorter
version, but didn't spot that.

Thanks,

Tony
-- 
-----------------------------------------------------------------------------
 Tony Bowden | Belfast, NI | tb@tmtm.com | www.tmtm.com | www.blackstar.co.uk
                        If I'm feigning coherence and calmness  Laugh with me
-----------------------------------------------------------------------------


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

Date: Mon, 28 Aug 2000 12:01:50 +0100
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <8oddee$f06$17$1@news.t-online.com>

In article <8od8tj$hd$1@qnsgh006.europe.nortel.com>, "Lincoln Marr"
<lincolnmarr@nospam.europem01.nt.com> wrote:
> I'm having a little trouble at getting at all elements of an array at
> the same time.... I'm no perl wizard so this is probably pretty simple.
> 
> All I want to do is say 'foreach element of @array, if the element is
> empty then set it to &nbsp; otherwise leave it as it is'.

> but then what happens once you've reached the end of the array? Any
> thoughts?? Thanks

The foreach iterates over your @array, but it stops, when reaching your
last element. I think you worry that it will never stop assining "&nbps;"
to infinity. You don't have to reserve memory, but it doesn't mean that
your array has no size.

D.



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

Date: Mon, 28 Aug 2000 12:50:24 +0200
From: P ten Bruggencate <whatever@hnv.com>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <39AA43F0.9D7BE931@hnv.com>

Maybe better to use:

#/perl/bin -w
use strict;

my $arr_size = scalar( @array );
my $x = 0;

while( $x < $arr_size )
{
    bla bla;
    $x++;
}

or

my $element;

foreach $element (@array)
{
    if( $element eq "" )
    {
        $element = "bla bla";
    }
}

Each element in the array is assignend to $element, altering $element
also alters the contents of the array.

Enjoy,

Patrick.

Ps: Forgot something, read the perl documents on foreach, dude.

Lincoln Marr wrote:
<snippet>
> $x =1;
> foreach (@array) {
>  if ($array[$x] eq "") { $array[$x] = "&nbsp;" ; }
> ++$x;
> }
> Thanks
> 
> --Lincoln


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

Date: Mon, 28 Aug 2000 13:00:43 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: How do I manipulate each element of an array?
Message-Id: <1eg2rm3.pfkqutw012dcN@[192.168.88.117]>

Lincoln Marr <lincolnmarr@nospam.europem01.nt.com> wrote:

> $x =1;
> foreach (@array) {
>  if ($array[$x] eq "") { $array[$x] = "&nbsp;" ; }
> ++$x;
> }

As usual with perl the solution is much simpler. the $_ in a foreach
loop works as a reference to the arrayvalue so you just need

foreach ( @array ) { $_ or $_ = '&nbsp;' }

Note this will change any false array value (including 0, '0', undef) to
'&nbsp;'. If you expressly only want empty strings changed use

foreach ( @array ) { $_ eq '' and $_ = '&nbsp;' }

( or foreach ( @array ) { if ( $_ eq '' ) { $_ = '&nbsp;' } } if your
more comfortable with the if () {} syntax )

Note that eq accepts undef as an empty string. If you don't want to
change those test for definedness as well.

-- 
Jakob


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

Date: Mon, 28 Aug 2000 11:11:26 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <MPG.1414e651add005db98970f@localhost>

Lincoln Marr <lincolnmarr@nospam.europem01.nt.com> wrote ..
>I'm having a little trouble at getting at all elements of an array at the
>same time.... I'm no perl wizard so this is probably pretty simple.
>
>All I want to do is say 'foreach element of @array, if the element is empty
>then set it to &nbsp; otherwise leave it as it is'.
>
>Simple enough??
>Here's some of my basic sketches/musings of how I could do it:
>
>$x =1;
>foreach (@array) {
> if ($array[$x] eq "") { $array[$x] = "&nbsp;" ; }
>++$x;
>}
>
>but then what happens once you've reached the end of the array? Any
>thoughts??

perhaps you're not aware of how to search through the Perl FAQ that's 
included with every distribution of Perl .. for any OS with a command 
line if you type

  perldoc -q "element.*array"

your question has been answered

  perldoc perldoc

for more information on this fiesty young tool

  perldoc perlsyn

for more information on Perl syntax

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 28 Aug 2000 11:47:48 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <8odg0k$dob$1@orpheus.gellyfish.com>

On Mon, 28 Aug 2000 10:46:50 +0200 Lincoln Marr wrote:
> I'm having a little trouble at getting at all elements of an array at the
> same time.... I'm no perl wizard so this is probably pretty simple.
> 
> All I want to do is say 'foreach element of @array, if the element is empty
> then set it to &nbsp; otherwise leave it as it is'.
> 
> Simple enough??
> Here's some of my basic sketches/musings of how I could do it:
> 
> $x =1;
> foreach (@array) {
>  if ($array[$x] eq "") { $array[$x] = "&nbsp;" ; }
> ++$x;
> }
> 

Try this for size :


#!/usr/bin/perl -w

use strict;

my @array = ('foo','','zub','blah','','');

@array = map { length $_ ? $_ : '&nbsp;' } @array;

print "@array";

> but then what happens once you've reached the end of the array? Any
> thoughts??
> 

You dont have to worry about it as the foreach will only iterate over the
defined elements of the array.  Indeed you dont need to use your indexing
scheme as in the foreach $_ is aliased to each element in turn so altering
$_ will alter the value of the element so you can do :


#!/usr/bin/perl -w

use strict;

my @array = ('foo','','zub','blah','','');

foreach (@array)
{
  $_ = 'nbsp;' if $_ eq '';
}
print "@array";


Note that I have only interpolated the array into a double quoted string
for clarity in printing.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Mon, 28 Aug 2000 13:57:00 +0200
From: "Lincoln Marr" <lincolnmarr@nospam.europem01.nt.com>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <8odk1v$5k9$1@qnsgh006.europe.nortel.com>

Thanks everyone very helpful...

--Lincoln




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

Date: 28 Aug 2000 10:32:37 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to Unzip a .tar.gz file
Message-Id: <8odbjl$db6$1@orpheus.gellyfish.com>

On Sun, 27 Aug 2000 22:20:46 GMT What A Man ! wrote:
> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">

*plonk*

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 28 Aug 2000 10:41:23 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Installation of perl 5.6 on Solaris 2.5.1
Message-Id: <8odc43$dbu$1@orpheus.gellyfish.com>

On Sat, 26 Aug 2000 11:55:31 -0400 Mike Wilson wrote:
> I recently installed perl 5.6 using pkgadd on a solaris box. Everything
> seemed to go ok, but when i tried perl I got a message saying cannot
> find libgdbm.o.2. After some searching I found a file in perl called
> libGDBM.o. I copied it to /usr/lib, renaming it to libgdbm, and perl
> now works. I am not to familar with installing programs on Solaris. Any
> help in understanding what was going on would be great.

You probably should add the location where you find the library file to
your LD_LIBRARY_PATH (and create the appropriate links to the required
name ).  


/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 28 Aug 2000 10:12:16 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Kill Me!
Message-Id: <967457082.9990@itz.pp.sci.fi>

In article <slrn8qkdcg.sup.rgarciasuarez@rafael.kazibao.net>, Rafael Garcia-Suarez wrote:
>
>And, by the way, what is 'postit.pl 0.05'?

A wrapper script between slrn and emacs that lets me send posts just
the way I want them.  The datestamped addresses in my reply-to header
are one of its features.

I suppose I ought to clean it up some day and publish it, since it
does seem to be a useful hack.  Mail me if you want to see the source
as it is.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla  | "By promoting postconditions to
and its pseudonyms -    |  preconditions, algorithms become
do not feed the troll.  |  remarkably simple."  -- Abigail



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

Date: 28 Aug 2000 11:07:03 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: mod_perl & heap
Message-Id: <8oddk7$ddp$1@orpheus.gellyfish.com>

On Sat, 26 Aug 2000 06:36:59 GMT jong884@my-deja.com wrote:
> I tried apache with mod_perl and DBI.  The
> problem is that after just one call of a script
> which makes database connection to Oracle with
> DBI/DBD, the heap size of the apache process
> jumps to 8 MB.  Any suggestion or explanation
> would be greatly appreciated.
> 

Thats right.  The compiled Perl program, any modules it uses and any global
data will become part of the httpd process - if you are finding that the
processes continue to grow after every request then you will probably
want to limit the amount of global data or perhaps ask in the group
comp.infosystems.www.servers.unix about how to limit the number of requests
each child process handles before dying.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 28 Aug 2000 10:08:54 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Module to Download HTML Pages
Message-Id: <8oda76$d9d$1@orpheus.gellyfish.com>

On Sun, 27 Aug 2000 16:13:09 -0700 Gabe wrote:
> Does a module exists which will follow all the links on a page and download
> those pages?

LWP::UserAgent allows you to download pages and HTML::LinkExtor enables
you to obtain the links from within those pages.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Mon, 28 Aug 2000 12:57:36 GMT
From: Abel Almazan <abel@inlander.es>
Subject: MySQL and perl
Message-Id: <39AA61A3.CC1E0EB0@inlander.es>

What i need to connect to a Mysql database with perl??

I have DBI installed. What's the name of the next module i have to
install??

And when i install the modules, perl automaticxally connects to the
database or i need to do something more with the mysql or perl
configuration??

Thanx



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 4150
**************************************


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