[24148] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6342 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 30 18:06:02 2004

Date: Tue, 30 Mar 2004 15:05:09 -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, 30 Mar 2004     Volume: 10 Number: 6342

Today's topics:
    Re: Cannot capture message from external program. <simon@unisolve.com.au>
    Re: Choosing Perl/Python for my particular niche <fma@doe.carleton.ca>
    Re: Choosing Perl/Python for my particular niche <fma@doe.carleton.ca>
    Re: Converting From C to Perl <ittyspam@yahoo.com>
    Re: INSERT statement works by itself but not in the scr <gnari@simnet.is>
    Re: Lost data on socket - Can we start over politely? (Vorxion)
        Module compilation misery <none@none.com>
    Re: newbie : please explain this behaviour <madhurahuja_delhi@vsnl.net>
        perl modules -> RPM resources??? <gj@freeshell.org>
        Question Regarding LWP <pgmr400@hotmail.com>
    Re: Question Regarding LWP <pgmr400@hotmail.com>
    Re: Question Regarding LWP <noreply@gunnar.cc>
    Re: Question Regarding LWP <uri.guttman@fmr.com>
        Remove empty elements of an array <olusola.o.olaode@intel.com>
    Re: Remove empty elements of an array <ittyspam@yahoo.com>
    Re: Remove empty elements of an array <tore@aursand.no>
        Remove whitespace elements of an array. <olusola.o.olaode@intel.com>
    Re: Remove whitespace elements of an array. <noreply@gunnar.cc>
    Re: Remove whitespace elements of an array. <ittyspam@yahoo.com>
    Re: Remove whitespace elements of an array. <tore@aursand.no>
    Re: scope again <remorse@partners.org>
    Re: Syntax error <noreply@gunnar.cc>
    Re: Trap errors inside MSDOS batch file <bik.mido@tiscalinet.it>
        validate links?? <dnp@ams.org>
    Re: Variable substitution in variable name <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 31 Mar 2004 07:42:50 +0000
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: Cannot capture message from external program.
Message-Id: <c4cpi1$2aue$1@otis.netspace.net.au>

Tad McClellan wrote:

> Hope the OP already knew that, as it is covered in the documentation
> for the function he is using.
> 
> I wouldn't want to think that he would ask thousands of people
> around the world without looking a bit himself first...

Yes but first the OP would need to know that back ticks are
documented in the perlop page. That's quite a counter-intuitive leap
(in my experience) for people who are new to perl.

All the best.

Simon




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

Date: 30 Mar 2004 22:17:38 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Re: Choosing Perl/Python for my particular niche
Message-Id: <4069F1FD.601C9079@doe.carleton.ca>

Peter Hickman wrote:
> 
> Fred Ma wrote:
> > I appreciate the sed terseness because
> > I can make a command line pipe stage out of it, but
> > the same brevity in a scripting language can make for
> > rough going.
> 
> Both perl and python will allow you to do this. in perl
> 
> #!/usr/bin/perl
> while(<>) { print uc $_; }
> 
> this script will read from stdin and write an uppercased version of the
> input to stdout and can be used in a pipeline.
> 
> You can to the same in python and of course the guts of the loop can be
> as big or small as you like. There is also a s2p tool that converts sed
> scripts into perl, but rewiting would be a better bet as s2p can produce
> some crufty code.
> 
> To be honest you could just flip a coin and go with that if you have no
> specific requirements.
> 
> Perl may be easier to sell to your boss than python but if you just went
> ahead with it you could use anything.


Hi, Peter,

My boss is my thesis supervisor.  I'm going with Perl and keeping a
tab on Python.  I expect to do most of my  hacking in Perl, since I
see it around everywhere, composing in Python, and one-liners in
Perl/sed.  About invoking Perl as part of a simple command in a
pipeline, I mean that one doesn't even have to write a script for it,
similar to sed

	Command1 | sed -e Expression1 -e Expression2 ... | Command_N

This might also be possible in Python, in which case so much the better. 
I'll find out (or someone might answer in a follow-up post).  Thanks
for your view on the two.

Fred
-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6


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

Date: 30 Mar 2004 22:23:50 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Re: Choosing Perl/Python for my particular niche
Message-Id: <4069F371.B4D08F58@doe.carleton.ca>

Robin Munn wrote:
> 
> Fred Ma <fma@doe.carleton.ca> wrote:
> > Hello,
> >
> > This is not a troll posting, and I've refrained from
> > asking because I've seen similar threads get all
> > nitter-nattery.
> [snip: poster is basically asking "Should I learn Perl or Python?"]
> 
> While availability of libraries for your specific tasks is a major
> factor to take into consideration, I'd say that even more important is
> to figure out which language fits your brain.
> 
> I first learned Perl, then Python. I now use Python almost exclusively,
> because I found that Python fits my mental "map" much better than Perl
> does. To me, it seemed like in Perl, everything was a string. Sure, you
> could have objects and classes, but they felt strange and awkward -- how
> do I translate the "bless" keyword into my mental model? Whereas
> Python's object model translated perfectly into my mental map, to the
> point where programming in Python gave a clarity that I never had when
> using Perl. It's hard to explain why, exactly -- it just seemed like
> when using Perl, I was always going back down to the level of details,
> the trees in the forest. Python allows me to look at the entire forest.
> I can still go down and look at trees if I need to, but I don't have to
> operate in that mode all the time.
> 
> Your mileage *will* vary. There's no substitute for experience. Set
> yourself a simple task (say, writing a sieve of Eratosthenes program)
> that you could do in about an hour with a language you're familiar with.
> Then write the same program in Perl and in Python, and see which one
> fits *your* brain better.


Well, my bout with Perl took much, much more than an hour.
It worked, though.  It's probably not enough experience to
get a good look at the strength of Perl.  For example, I
am a vim user (an editor), which is cryptic at first, but
let's you fly when you get to know it.  I'm not saying that
all things cryptic are efficient in the end, just that a
brief bout won't always uncover the strengths.  As a
"working model", I've decided to use Perl as the workhorse,
and keep tabs on Python as time permits.  If my mental map
works better with Python, it's ease of ramping up will
allow the better fit to shine through despite the lesser
time I spend with it.  Then it will naturally take a more
prominent role.  Thanks for the advice on checking out both.
It seems to be the most realistic, and in line with what
many have suggested.

Fred
-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6


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

Date: Tue, 30 Mar 2004 16:23:27 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Converting From C to Perl
Message-Id: <20040330162133.A19862@dishwasher.cs.rpi.edu>

On Tue, 30 Mar 2004, SketchySteve wrote:

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:c4c7fv$ssc$2@mamenchi.zrz.TU-Berlin.DE...
> > SketchySteve <nospamplease@no.com> wrote in comp.lang.perl.misc:
> > > Hi there,
> > >
> > > I'm currently working on neural network project. The program i'm using
> > > (SNNS) will automaticly create a network as a c function which can be
> > > called.
> > >
> > > I know there are tools for converting Perl into C but I was wondering if
> > > there were any which worked the other way round.
> >
> > Don't you rather want to *call* the C function from Perl?  Automatically
> > generating C code and translating that into Perl sounds like too strange
> > a concept.  What would a conversion buy you, except a slowdown by 5 or 10?
> >
> > Inline::C is good at making C programs callable from Perl.  If the
> function
> > is in a library and you have a header file for it, with a little luck
> > it does it all by itself, but even if it doesn't, it's usually easy.
> >
> > Anno
>
>
> Thanks for the advice, I have looked into the inline module and it seems to
> do what I want. The only drawback is that i will need to install Visual
> Studio for it to work.
>

Uhm.  Why?  Inline::C just needs a C compiler.  It certainly doesn't need
the bloat that is MS Visual Studio.  Grab yourself a copy of the GNU C
compiler and install that.  You don't need an entire IDE to use Inline::C.

Paul Lalli


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

Date: Tue, 30 Mar 2004 17:32:45 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: INSERT statement works by itself but not in the script??
Message-Id: <c4catd$fuf$1@news.simnet.is>

"Bing Du" <bdu@iastate.edu> wrote in message
news:c4c6sl$1bu$1@news.iastate.edu...
> Greetings,
>
> This is perl, v5.8.0 built for i386-linux-thread-multi.
>
> The result of the following INSERT is '0E0' (value of $rv) if run in a
> Perl script that uses DBI and DBD::mysql (version 2.9003).  The table
> $ltm_ssn_table is still empty after INSERT.
>
> =============
> $rv = $mysql_dbh->do(qq{INSERT INTO $ltm_ssn_table (ltm_number,ssn,notes)
>                     SELECT
> $source_data_table.crse,$source_data_table.ssn,$old_ltm_ssn_table.notes
>                     FROM $source_data_table LEFT JOIN $old_ltm_ssn_table
>                     ON
$source_data_table.crse=$old_ltm_ssn_table.ltm_number
>                     AND $source_data_table.ssn=$old_ltm_ssn_table.ssn
>                     WHERE
$source_data_table.offer_dept_abrvn='$ltm_string'
>                     });
> ============
>
> However, the above INSERT works fine with the MySQL command line client:
>
> ========
> mysql> INSERT INTO ltm_ssn (ltm_number,ssn,notes) SELECT
> source_data.crse, source_data.ssn, old_ltm_ssn.notes FROM source_data
> LEFT JOIN old_ltm_ssn ON source_data.crse=old_ltm_ssn.ltm_number AND
> source_data.ssn=old_ltm_ssn.ssn WHERE source_data.offer_dept_abrvn='L TM;
> Query OK, 485 rows affected (0.03 sec)
> Records: 485  Duplicates: 0  Warnings: 0
> ==========
>
> Would anybody tell me what's wrong with the INSERT within the script?
>

have you checked what the sql actually is?
there are too many (unknown to us) variables in your insert statement,
for us to be able to guess what's wrong. maybe one of
$ltm_ssn_table ,$source_data_table, $source_data_table,$old_ltm_ssn_table,
 or $ltm_string is not what you think
try:
  my $sql=qq{INSERT INTO $ltm_ssn_table .....};
  print "debug sql=[$sql]\n";
  $rv = $mysql_dbh->do($sql);
  print "debug rv=$rv\n";


now you can cut and paste the debug sql into your client to make sure
 you are trying the same thing.


gnari





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

Date: 30 Mar 2004 16:56:06 -0500
From: vorxion@knockingshopofthemind.com (Vorxion)
Subject: Re: Lost data on socket - Can we start over politely?
Message-Id: <4069ecf6$1_1@news.iglou.com>

In article <4069a132.0@juno.wiesbaden.netsurf.de>, Thomas Kratz wrote:
>[ code snipped ]
>
>Sorry, but the code is still too cluttered to debug it. I have tried, 
>really, for about 45 minutes, then I gave up.

Thanks for the effort though.  However, this example you gave (I just woke
up in the middle of the "night" and decided to check mail and news quickly,
so I haven't tested it yet) is very helpful.  One thing I don't understand
about it though...

>++++ server ++++
>
>use strict;
>use warnings;
>
>use IO::File;
>use IO::Select;
>use IO::Socket;
>
>my $max_buf = 10240;
>
>my $sel = IO::Select->new();
>
>my $srv = IO::Socket::INET->new(
>      Proto => 'tcp',
>      LocalPort => 4016,
>      Listen => SOMAXCONN,
>      ReuseAddr => 1,
>);
>
>$sel->add($srv);
>
>die "couldn't create socket" unless $srv;
>
>my $log = IO::File->new('server.log', '>') or die $!;
>$log->autoflush(1);
>
>while ( 1 ) {
>
>    foreach my $sock ( $sel->can_read(0.05) ) {
>
>       if ( $sock == $srv ) {
>
>          my $new = $srv->accept();
>          $new->autoflush(1);
>          print $log "new connection from ", $new->peerhost,
>                ':', $new->peerport, "\n";
>          $sel->add($new);
>
>          next;
>       }
>
>       my $buf = '';
>       my $clsel = IO::Select->new($sock);

There...  -Every- time you go through the loop, you're reconstructing
$clsel as a single-element-holding object containing the current
iteration's object?  Could I inquire as to why you're doing this instead of
simply performing the following check on $sel instead of $clsel?  Is it
simply a speed optimisation for that block, or is there something inherently
safer in what you're doing that would cause problems if you tried using
$sel?

>       while ( $clsel->can_read(0.05) ) {
>          last unless $sock->sysread($buf, 1024, length($buf))
>             and (length($buf) <= $max_buf);
>       }

Wait a second...Doh.  *lightbulb*  You come in the first time on $sel, but
you're rebuilding $clsel so that you can purely stay -on that socket- until
it's drained?  I think I'm startng to see.  Could you confirm?

That, and one thing is curious--the docs for foreach() say that adding and
removing elements from something from a list used for the loop is a Bad 
Thing[tm].  You're modifying $sel any time there's a connect or disconnect.
Doesn't that throw the foreach() loop out of sync?  Not at all a criticism,
it's just that I've had fresh experience with foreach() and changed lists
and elements thereof, and that part of the docs is fresh in my mind.  I'm
curious why this causes no difficulties in your example.

This example is definitely worth a shot.  If it works properly, I'll have to
adapt it, but it would be tremendously helpful to see a working example,
using select, that doesn't drop data on the floor.  I'll let you know how it
turns out.  I was just very curious as to why you're rebuilding a
single-element IO::Select handle each iteration, rather than simply having
an 'else' block as an inverse of the server accept().  I -think- I see now,
though.

And I saw your note about not using non-blocking.  Gotcha.

Thanks -very much- for the code to test, and will try tonight!

-- 
Vorxion - Member of The Vortexa Elite


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

Date: Tue, 30 Mar 2004 23:14:24 +0100
From: Garry Heaton <none@none.com>
Subject: Module compilation misery
Message-Id: <immac.28419$Y%6.3352420@wards.force9.net>

Please don't take this as a troll as I would like to hear how other Perl
programmers deal with failed module compilation.

Despite my love of Perl as a language I've had to give-up on it recently
because module compilation is so hit and miss. I have experienced failed
compilations of many modules lately on both Mac OSX Panther and Fedora Core
1 (DBD::mysql, HTML::Mason, mod_perl and others) such that I've had to
resort to learning PHP to get work done without the need for endless module
compilation.

How I wish this was not the case as I consider PHP an inferior version of
Perl. However, much as everyone lauds the virtues of Perl modules and CPAN I
contend that this is Perl's weakest link. Module dependency is as bad as RPM
on Linux. Installing HTML::Mason, for example, required compilation of about
a dozen other modules so I didn't exactly hold much hope of getting a result
after several other failed compilations. True to form HTML::Mason died on me
with "Failed 23/23 test scripts, 0.00% okay. 92/92 subtests failed, 0.00%
okay /usr/bin/make test -- NOT OK .." I frankly haven't the time or patience
to trace through the voluminous error messages produced and try to work out
exactly where everything went wrong.

If I can't get modules to install reliably then Perl itself is unreliable.
Fine if you can make do with the core modules but once you take a trip to
CPAN you're on your own. Hence I can't recommend Perl for client projects
because the ISP's sysadmin isn't going to want to waste hours tracing failed
compilations as I exeperienced.

This raises a broader issue of Perl's usability in that the more bits 'n
pieces required to get a job done (Perl, mod_perl, HTML::Mason) the greater
the likelihood of something backfiring and the fewer the ISPs who are going
to offer the complete package. Hence PHP's success in the web development
sphere. Isn't it time we had a more inclusive core, particularly for web
development?

Perl was my first server-side scripting language and still my favourite. I
just wish I didn't have to deal with CPAN's shortcomings. What a waste.



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

Date: Wed, 31 Mar 2004 00:25:28 +0530
From: "madhur" <madhurahuja_delhi@vsnl.net>
Subject: Re: newbie : please explain this behaviour
Message-Id: <c4ci1k$2hngql$1@ID-81175.news.uni-berlin.de>

Thanks to both of you

Madhur
India




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

Date: Tue, 30 Mar 2004 21:54:01 +0000 (UTC)
From: Gerald Jones <gj@freeshell.org>
Subject: perl modules -> RPM resources???
Message-Id: <c4cq9p$6av$1@chessie.cirr.com>

Hello,

Does anyone know of a howto or tutorial on creating RPMs from regular tarballs
of perl modules?

Thanks,
Gerald

-- 
The press is so powerful in its image-making role, it can make a
criminal look like he's the victim and make the victim look like he's
the criminal.  --Malcolm X


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

Date: Tue, 30 Mar 2004 21:00:14 GMT
From: "Douglas Pollock" <pgmr400@hotmail.com>
Subject: Question Regarding LWP
Message-Id: <ydlac.362124$Po1.20918@twister.tampabay.rr.com>

I'm using ActiveState Perl on a Windows XP Professional computer. It has
libwww-perl loaded.

I just bought the book Spidering Hacks By Kevin Hemenway, Tara Calishain.

One of their examples includes the following partial code:

--------------------------------
if ($libloc = $ENV{'LIBWWW_PERL'}) { unshift(@INC, $libloc); }

require "getopts.pl";
require "www.pl";
require "wwwurl.pl";
require "wwwerror.pl";
--------------------------------

When I try to run the script it complains that it can't find www.pl,
wwwurl.pl, and wwwerror.pl. I'm new to PERL so I not clear on how to find
the modules. I did a search on CPAN for the module www.pl and it says it
can't find it. I did a search on the ActiveState web site and it did not
find it. Can anyone tell me where www.pl, wwwurl.pl, and wwwerror.pl come
from and how to install?


Thanks
Doug




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

Date: Tue, 30 Mar 2004 21:29:34 GMT
From: "Douglas Pollock" <pgmr400@hotmail.com>
Subject: Re: Question Regarding LWP
Message-Id: <2Flac.362126$Po1.25030@twister.tampabay.rr.com>

My mistake the code was not from the Spidering Hacks book but actually came
from

http://ftp.ics.uci.edu/pub/websoft/libwww-perl/src/get

and the www.pl, wwwurl.pl, and wwwerror.pl were located on the site.

Doug

"Douglas Pollock" <pgmr400@hotmail.com> wrote in message
news:ydlac.362124$Po1.20918@twister.tampabay.rr.com...
> I'm using ActiveState Perl on a Windows XP Professional computer. It has
> libwww-perl loaded.
>
> I just bought the book Spidering Hacks By Kevin Hemenway, Tara Calishain.
>
> One of their examples includes the following partial code:
>
> --------------------------------
> if ($libloc = $ENV{'LIBWWW_PERL'}) { unshift(@INC, $libloc); }
>
> require "getopts.pl";
> require "www.pl";
> require "wwwurl.pl";
> require "wwwerror.pl";
> --------------------------------
>
> When I try to run the script it complains that it can't find www.pl,
> wwwurl.pl, and wwwerror.pl. I'm new to PERL so I not clear on how to find
> the modules. I did a search on CPAN for the module www.pl and it says it
> can't find it. I did a search on the ActiveState web site and it did not
> find it. Can anyone tell me where www.pl, wwwurl.pl, and wwwerror.pl come
> from and how to install?
>
>
> Thanks
> Doug
>
>
>




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

Date: Tue, 30 Mar 2004 23:33:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Question Regarding LWP
Message-Id: <c4cp7c$2f5h07$1@ID-184292.news.uni-berlin.de>

Douglas Pollock wrote:
> 
> http://ftp.ics.uci.edu/pub/websoft/libwww-perl/src/get

That code is almost 10 years old.

You told us that you are new to Perl (not PERL). Please use books and 
documentation from this century. ;-)

     http://learn.perl.org/

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 30 Mar 2004 16:40:07 -0500
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Question Regarding LWP
Message-Id: <sisck712dnew.fsf@tripoli.fmr.com>

>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

  GH> Douglas Pollock wrote:
  >> http://ftp.ics.uci.edu/pub/websoft/libwww-perl/src/get

  GH> That code is almost 10 years old.

  GH> You told us that you are new to Perl (not PERL). Please use books and
  GH> documentation from this century. ;-)

s/century/millennium/ ;

uri



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

Date: Tue, 30 Mar 2004 15:20:28 -0500
From: "fenisol3" <olusola.o.olaode@intel.com>
Subject: Remove empty elements of an array
Message-Id: <c4ckqc$ck$1@news01.intel.com>

Hello,

What I am trying to do is to go through each element in an array using
foreach loop, delete the elements that are empty (blank spaces), and store
the rest in another array. Each element is intentionally separated by
commas. If you know how to do this, please help me. Thanks.
 -Fenisol3




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

Date: Tue, 30 Mar 2004 15:45:51 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Remove empty elements of an array
Message-Id: <20040330153921.J19862@dishwasher.cs.rpi.edu>

On Tue, 30 Mar 2004, fenisol3 wrote:

> Hello,
>
> What I am trying to do is to go through each element in an array using
> foreach loop, delete the elements that are empty (blank spaces), and store
> the rest in another array. Each element is intentionally separated by
> commas. If you know how to do this, please help me. Thanks.
>  -Fenisol3


Not *quite* sure I understand what you're getting at, but...

@array = grep /\S/, @array;

That will remove all elements that contain either an empty string or only
space characters, leaving only the 'good' elements in @array.

You said you want to both remove the blank elements and save the rest in
another array.  That means that you will end up with two arrays containing
exactly the same elements?  I don't understand why you'd do that, but if
you really need to:

@array = grep /\S/, @array;
@array2 = @array;


HTH,
Paul Lalli


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

Date: Tue, 30 Mar 2004 23:59:24 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Remove empty elements of an array
Message-Id: <pan.2004.03.30.20.49.30.609022@aursand.no>

On Tue, 30 Mar 2004 15:20:28 -0500, fenisol3 wrote:
> What I am trying to do is to go through each element in an array using
> foreach loop, delete the elements that are empty (blank spaces), and
> store the rest in another array. Each element is intentionally separated
> by commas.

What have you tried so far?  What didn't work?


-- 
Tore Aursand <tore@aursand.no>
"Writing is a lot like sex. At first you do it because you like it.
 Then you find yourself doing it for a few close friends and people you
 like. But if you're any good at all, you end up doing it for money."
 -- Unknown


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

Date: Tue, 30 Mar 2004 16:45:39 -0500
From: "fenisol3" <olusola.o.olaode@intel.com>
Subject: Remove whitespace elements of an array.
Message-Id: <c4cpq4$36v$1@news01.intel.com>

Hello,

What I am trying to do is to go through each element in an array using
foreach loop, delete the elements that are empty (blank spaces), and store
the rest in another array. For some reason, (@array = grep /\S/, @array)
doesn't do anything to the array.
If you know how to do this, please help me. Thanks.
 -Fenisol3




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

Date: Tue, 30 Mar 2004 23:58:03 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Remove whitespace elements of an array.
Message-Id: <c4cqki$23hv32$1@ID-184292.news.uni-berlin.de>

[ This relates to a previous thread with a similar name. You should
have posted a follow-up to that thread instead of starting a new one. ]

fenisol3 wrote:
> What I am trying to do is to go through each element in an array
> using foreach loop, delete the elements that are empty (blank
> spaces), and store the rest in another array. For some reason,
> (@array = grep /\S/, @array) doesn't do anything to the array.

Yes, it removes possible whitespace elements in the array.

If you claim otherwise, please post a short but complete program that
people can copy and run, and that made you come to your conclusion.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 30 Mar 2004 17:00:15 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Remove whitespace elements of an array.
Message-Id: <20040330165834.Y19862@dishwasher.cs.rpi.edu>

On Tue, 30 Mar 2004, fenisol3 wrote:

> Hello,
>
> What I am trying to do is to go through each element in an array using
> foreach loop, delete the elements that are empty (blank spaces), and store
> the rest in another array. For some reason, (@array = grep /\S/, @array)
> doesn't do anything to the array.
> If you know how to do this, please help me. Thanks.
>  -Fenisol3
>

Please do not start a new thread instead of continuing the old one.

I assure you, that line does indeed remove white-space-only elements from
an array.  Therefore, either there is something else wrong, or you are not
adequetley describing your problem or data.  Please post a *short but
complete* program showing us what's going wrong.

Paul Lalli


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

Date: Wed, 31 Mar 2004 00:11:24 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Remove whitespace elements of an array.
Message-Id: <pan.2004.03.30.22.10.09.485118@aursand.no>

On Tue, 30 Mar 2004 16:45:39 -0500, fenisol3 wrote:
> What I am trying to do is to go through each element in an array using
> foreach loop, delete the elements that are empty (blank spaces), and store
> the rest in another array. For some reason, (@array = grep /\S/, @array)
> doesn't do anything to the array.

You still don't tell us anything about what you've tried so far.  What
doesn't work?  What have you tried?

The simples approach - at least for me - would be something like this:

  my @old = ( 'a', 'b', '', 'c', ' ', 'd' );
  my @new;

  foreach ( @old ) {
      if ( /\S/ ) {
          push( @new, $_ );
      }
  }

This can easily have been cut down to:

  foreach ( @old ) {
      push( @new, $_ ) if ( /\S/ );
  }

 ...and again to:

  my @new = grep /\S/, @old;

If none of these suggestions work, you're not describing your problem
sufficiently.  Please do that next time you post here.  Give us some
example data and what you have tried so far (which doesn't work).


-- 
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
 4 will be fought with sticks and stones." -- Albert Einstein


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

Date: Tue, 30 Mar 2004 17:16:50 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: scope again
Message-Id: <remorse-12E0E2.17165030032004@plato.harvard.edu>

In article <slrnc6je7l.ig8.xx087@smeagol.ncf.ca>,
 Glenn Jackman <xx087@freenet.carleton.ca> wrote:

>     % require 'space.pl'
> 
>     % $s=Space->new('foo')
>     Space=HASH(0x12bfd4)
> 
>     % use Data::Dumper
> 
>     % print Dumper($s)
>     $VAR1 = bless( {
>                     'char' => '@',
>                     'tile' => 'foo'
>                 }, 'Space' );
> 
>     % $s->fchsym
>     tile is 'foo'

Wait -- completely un-related to the question, what is this?  How do you 
get an interactive Perl?

Ricky

-- 
Pukku


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

Date: Tue, 30 Mar 2004 22:03:33 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Syntax error
Message-Id: <c4cjtp$2fqjsq$1@ID-184292.news.uni-berlin.de>

Scott Bryce wrote:
> It really is a lot easier to test locally. Install Apache server on
> your local machine and configure it to run CGI scripts locally.

Couldn't agree more. (I know, because for a couple of years I wrote
Perl programs without having access to Perl locally, but I did all
testing via the web server of my web hosting provider. ;-)  That was
before I realized how easy it is to install Perl locally.)

If others are correct in their assumption that you are on Windows, I
don't think there is any easier way to get Perl + Apache + PHP + ...
than installing the package available at
http://www.indigostar.com/indigoperl.htm

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 31 Mar 2004 00:20:53 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Trap errors inside MSDOS batch file
Message-Id: <c1hj605gt37giqpaj314u8u4euol11h6dr@4ax.com>

On 30 Mar 2004 18:02:26 +0100, Brian McCauley <nobull@mail.com> wrote:

>(CMD) would be better.  In NT command shell you can do things
>conditionally using "IF" based on the exit code of a command (for
>details RTFM on "IF" in CMD).  I don't know if the same syntax works
>in MSDOS. 

No, the *same syntax* doesn't work with command.com, but then there's

  IF ERRORLEVEL <value> <cmd>

>If you can't rely on the exit status then I'd suggest you get a real
>shell or sumply use Perl.
          ^^^^^^^^^^^^^^^

Definitely!


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Tue, 30 Mar 2004 13:30:25 -0500
From: Dan Pelton <dnp@ams.org>
Subject: validate links??
Message-Id: <c4cjjn$m15$1@sun06.ams.org>

Whats the best way to check for broken links on a web page. These links goto to CGIs 
and some of the links a redirected. I tried the code below from the perl cook book. 
It works fine for links to html pages only.

"churl.pl http://www.ams.org" reports that http://www.ams.org/eims is BAD, but it 
is a valid URL.

Any suggestions?

thanks,
Dan

--------------------------------------------------------
#!/usr/bin/perl -w
# churl - check urls
use HTML::LinkExtor;
use LWP::Simple;
$base_url = shift
    or die "usage: $0 <start_url>\n";
$parser = HTML::LinkExtor->new(undef, $base_url);
$html = get($base_url);
die "Can't fetch $base_url" unless defined($html);
$parser->parse($html);
@links = $parser->links;
print "$base_url: \n";
foreach $linkarray (@links) {
    my @element  = @$linkarray;
    my $elt_type = shift @element;
    while (@element) {
        my ($attr_name , $attr_value) = splice(@element, 0, 2);
        if ($attr_value->scheme =~ /\b(ftp|https?|file)\b/) {
            print "  $attr_value: ", head($attr_value) ? "OK" : "BAD", "\n";
        }
    }
}



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

Date: Tue, 30 Mar 2004 22:55:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Variable substitution in variable name
Message-Id: <4069FA56.535564EA@acm.org>

mshetty wrote:
> 
> Hi,
> 
> Have the following code where I want to reduce the lines of code:
> 
> #Variables to store total file count for each type
> $total_cpp_file=0;
> $total_h_file=0;
> $total_c_file=0;
> $total_inp_file=0;
> $total_inl_file=0;
> $total_hpp_file=0;
> $total_cc_file=0;
> $total_hh_file=0;
> $total_yxx_file=0;
> $total_y_file=0;
> $total_l_file=0;
> 
> find (\&wanted, "S:\\src");
> find (\&wanted, "S:\\inc");
> sub wanted
> {
>                 store_file ($File::Find::name);
> }
> 
> sub store_file ($)
> {
>     my $name = shift;
>     if ($name =~ /\.(cpp)$/i)
>         {
>         $total_cpp_file++;
>         push @files_cpp, ($name);
>     }
>     elsif ($name =~ /\.(h)$/i)
>         {
>         $total_h_file++;
>         push @files_h, ($name);
>     }
>     elsif ($name =~ /\.(c)$/i)
>         {
>         $total_c_file++;
>         push @files_c, ($name);
>     }
>         elsif ($name =~ /\.(inp)$/i)
>         {
>         $total_inp_file++;
>         push @files_INP, ($name);
>     }
>         elsif ($name =~ /\.(inl)$/i)
>         {
>         $total_inl_file++;
>         push @files_INL, ($name);
>     }
>         elsif ($name =~ /\.(hpp)$/i)
>         {
>         $total_hpp_file++;
>         push @files_HPP, ($name);
>     }
>         elsif ($name =~ /\.(cc)$/i)
>         {
>         $total_cc_file++;
>         push @files_CC, ($name);
>     }
>         elsif ($name =~ /\.(hh)$/i)
>         {
>         $total_hh_file++;
>         push @files_HH, ($name);
>     }
>         elsif ($name =~ /\.(yxx)$/i)
>         {
>         $total_yxx_file++;
>         push @files_YXX, ($name);
>     }
>         elsif ($name =~ /\.(y)$/i)
>         {
>         $total_y_file++;
>         push @files_Y, ($name);
>     }
>         elsif ($name =~ /\.(l)$/i)
>         {
>         $total_y_file++;
>         push @files_L, ($name);
>     }elsif ($name =~ /\.(dsp)$/i)
>         {
>         push @files_dsp, ($name);
>     }
> 
> } #store_file end
> 
> IS there a shorter way to write this?
> 
> I mean can I store (cpp, h, c, inp, inl, hpp, cc, hh, yxx, y, l) in an
> array(file_type and say push @files_$file_type[1]?

Yes there is a shorter way:

use warnings;
use strict;
use File::Find;

my @types = qw( cpp hpp inp inl yxx cc hh c h l y );
# types must have longest first to work correctly
my $regex = qr/@{[ join '|', @types ]}/i;

my %totals;
find( sub{
    return unless /\.($regex)$/;
    push @{ $totals{ $1 } }, $File::Find::name;
    }, 'S:/src', 'S:/inc' );

print <<HEADER;
Type Count
----------
HEADER
for my $type ( sort keys %totals ) {
    printf "%4s %d\n", $type, @{ $totals{ $type } };
    }

__END__



John
-- 
use Perl;
program
fulfillment


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

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


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