[22223] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4444 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 21 21:08:50 2003

Date: Tue, 21 Jan 2003 18:05:07 -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, 21 Jan 2003     Volume: 10 Number: 4444

Today's topics:
    Re: ActivePerl 5.8 / MySQL / Apache Problem <alex@alexbanks.com>
    Re: arrg, grep {"abc"} @stuff, always is true?! <NOSPAMintx@yahoo.com>
    Re: Couple of Perl CGI problems (UmanS)
    Re: execute b.pl script from within a.pl script and b.p <NOSPAMintx@yahoo.com>
    Re: File::Copy under NT appears to fail. (Jay Tilton)
    Re: File::Copy under NT appears to fail. (Malcolm Dew-Jones)
        identifying web host platform? <dg1261@cs-REMOVE_THIS-.com>
    Re: Newbie: How to remove some characters from a string <steven.smolinski@sympatico.ca>
    Re: Newbie: How to remove some characters from a string <dover@nortelnetworks.com>
    Re: Newbie: How to remove some characters from a string (Ben Morrow)
    Re: Newbie: How to remove some characters from a string (Tad McClellan)
    Re: Paragraph Mode (Malcolm Dew-Jones)
    Re: Paragraph Mode <mgjv@tradingpost.com.au>
    Re: Paragraph Mode <mgjv@tradingpost.com.au>
    Re: Perl Script not working on Win NT <LaoTzu@TaoTeChing.co.uk.us>
    Re: Perl Script not working on Win NT <eric.ehlers@btopenworld.com.nospam>
        Regex: optional word boundary <amittai@amittai.com>
    Re: Reverse Inheritance? <uri@stemsystems.com>
    Re: Send a file w/ CGI <bongie@gmx.net>
        split with pattern matching question <stremitz@consultant.com>
    Re: split with pattern matching question <tassilo.parseval@post.rwth-aachen.de>
    Re: split with pattern matching question <stremitz@consultant.com>
    Re: split with pattern matching question <skuo@mtwhitney.nsc.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 21 Jan 2003 23:47:09 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: ActivePerl 5.8 / MySQL / Apache Problem
Message-Id: <3e2ddc00$0$241$cc9e4d1f@news.dial.pipex.com>

Thanks Lou - sounds like that's it.

"Lou Moran" <lou.moran@gellerandwind.com> wrote in message
news:ah9r2v4r4eq2o3kf2g8okf69e141okgchl@4ax.com...
> On Tue, 21 Jan 2003 12:04:29 -0000, "Alex Banks" <alex@alexbanks.com>
> wrote:
>
> >Would be really grateful for any help with this... I've been surfing for
> >hours to try to find a similar case.
> >
> >---
> >
> >I used to run ActivePerl 5.6 with Apache on my Windows XP box just fine -
> >but since I installed ActivePerl 5.8 my old database scripts don't work.
> >They come back with this error:
> >
> >[Tue Jan 21 11:51:24 2003] [error] [client 192.168.1.15]
> >install_driver(mysql) failed: Can't load
> >'C:/Perl/site/lib/auto/DBD/mysql/mysql.dll' for module DBD::mysql:
> >load_file:The specified module could not be found at
> >C:/Perl/lib/DynaLoader.pm line 229.
> >[Tue Jan 21 11:51:24 2003] [error] [client 192.168.1.15]  at (eval 1)
line 3
> >[Tue Jan 21 11:51:24 2003] [error] [client 192.168.1.15] Compilation
failed
> >in require at (eval 1) line 3.
> >[Tue Jan 21 11:51:24 2003] [error] [client 192.168.1.15] Perhaps a
required
> >shared library or dll isn't installed where expected
> SNIP
> The big problem is that 5.8 and 5.6 are not binary compatible.  You
> need to go get new modules.  One such module is DBD::mysql.
>
> You can read more about it here:
>
> http://dev.perl.org/perl5/news/2002/07/18/580ann/
>
> But this is the part you'll care most about -
>
>   BINARY INCOMPATIBLE:
>   mainly because of the PerlIO introduction, Perl 5.8 is not
>   binary compatible with any earlier Perl release, XS MODULES
>   WILL HAVE TO BE RECOMPILED!
>
>
>
> --
> There's more than one way to do it, but only some of them work




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

Date: Wed, 22 Jan 2003 01:06:08 GMT
From: Kevin T <NOSPAMintx@yahoo.com>
Subject: Re: arrg, grep {"abc"} @stuff, always is true?!
Message-Id: <3E2DEEFA.2000707@yahoo.com>

wow!
thanks for all the great suggestions/corrections and polite, rtm more 
closeley, hints.

using the /abc/ worked.

ktom wrote:

> i have a array @stuff created with
> my @stuff = qw(abc def ghi);
> 
> foreach $a ( @stuff ) { if ( $a =~ "abc" ) {print "yes";} }
> 
> behaves correctly and prints yes, if abc is changed to cba, it does not 
> print.
> 
> replacing the above with
> 
> if( grep { "abc" } @stuff ) { print "yes"; }
> 
> prints yes regardless of the value defined for the grep statement.  abc, 
> xyz, cba, foobar.  it will always print yes.
> 
> the reference says grep is to return the number of times that a match 
> occured.  i can not see how a non-matching valueis returning a non-zero 
> #.  putting scalar( grep { "abc" } @stuff ) proves no different
> 
> this seems to be such a simple issue, i am annoyed that the obvious 
> escapes me..
> 
> thanks.  kevint
> 



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

Date: 21 Jan 2003 15:48:56 -0800
From: kedaran0504@yahoo.com.au (UmanS)
Subject: Re: Couple of Perl CGI problems
Message-Id: <751924de.0301211548.2e9a3054@posting.google.com>

Hi,
Thanks goes to
Tad - for solution to problem one
I am now using 'tr' instead of 's'

Janek - for solution to problem 2
I have forgotten this option (directly assigning to variables from
split output)

I have used sample variables for this list only they are not real
variables. Also some typo errors.

Thanks to all again
Uman
 

kedaran0504@yahoo.com.au (UmanS) wrote in message news:<751924de.0301201911.5a7c6f42@posting.google.com>...
> Hi,
> 
> First problem.
> I am submitting a field contains name and email address separated by
> "|" (Selected from a drop down list in a form)
> ex: Surname.Firstname|user@mydomain.com
> In the cgi script I assign this to a field and splitting this field
> into an array.
> $var1 =query->param('formfield1');
> @myarray = split ("|",$var1);
> @myname = $myarray[0];
> @myaddr = $myarray[1];
> 
> When I print $var1 it prints ok, but how can I print @myname or
> @myaddr. If say
> print $myname[0] it will print only the first letter.
> 
> Second Problem.
> I am sumitting a Text type field through a web form that may contains
> (' single quot character) and when my perl cgi script submit this to
> the oracle database oracle interprets it as a terminator. SO I am
> coverting the single quots to double quots. But the problem is I am
> using
> $string = ~/\'/\"/; but this changes only the first occurance only. 
> Please help me.
> 
> Thanks


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

Date: Wed, 22 Jan 2003 01:17:17 GMT
From: Kevin T <NOSPAMintx@yahoo.com>
Subject: Re: execute b.pl script from within a.pl script and b.pl vars remain
Message-Id: <3E2DF197.3070504@yahoo.com>


Anno Siegel wrote:

> ktom  <xyzzy@billgates.com> wrote in comp.lang.perl.misc:
> 
>>Ben Morrow wrote:
>>
>>>xyzzy@billgates.com
>>>
> 
>>>>i would like to execute a perl script, a.pl, which contain code to 
>>>>execute the perl script b.pl and have the values for the variables 
>>>>define in b.pl remain for use withing a.pl
>>>>
> 
> [...]
> 
> 
>>>, but what on earth do you need to do this for? I'm sure there is a better
>>>answer if you tell us what your actual problem is.
>>>
> 
> Looks like xyzzy has led us astray with an XY problem.
> 
> 
>>i am very much a csh person the equivalent of 'source' is a comfortable 
>>implementation.
>>
>>the b.pl is the result of ls -1 *.abc | sed | sed > b.pl   very easy and 
>>quick/reliable..
>>
> 

yes, i can see the simplicity of using some of the suggestions that you 
have made.  if the result of ls  -1 *.abc is what i am using.  it is not..

the '| sed | sed' (sed -e 'stuff' -e 'morestuff' -e 
'evenmorepiddlystuff') is meant to indicate additional munging before it 
is usable in the form needed.

and i am sure that a better long term solution would to put the munging 
in the perl script as well.  the real meat of the script is in a.pl and 
more important at this time.

not to  mention perl is still an unnative language to me, although i am 
trying to change that.


> So you want to expand a shell glob?  Yikes, was Ben right!
> 
>     my @files = glob( '*.abc');
> 
> does exactly that.  Talk about easy...
> 
> Anno
> 



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

Date: Wed, 22 Jan 2003 00:24:53 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: File::Copy under NT appears to fail.
Message-Id: <3e2de488.406576278@news.erols.com>

fergus@twig.demon.co.uk (Fergus McMenemie) wrote:

: I have used File::Copy to copy 600000 files from one disk to another.
: The copy returned 0 now and again for no apparent reason.

What is in $! when this happens?



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

Date: 21 Jan 2003 17:26:01 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: File::Copy under NT appears to fail.
Message-Id: <3e2df329@news.victoria.tc.ca>

Fergus McMenemie (fergus@twig.demon.co.uk) wrote:



: I have used File::Copy to copy 600000 files from one disk to another.
: The copy returned 0 now and again for no apparent reason. The output
: file was there and seemed OK in almost all cases. Its size and contents
: are identical to the original file. About 300 files produced a 0 return
: status. About 50 or so files did fail to copy, there size and or
: checksum was different.

: Anybody else seen this or have any ideas? Im using Perl 5.005 from
: Active State. It is running on MIcrosoft Windows NT 4.0 with SP6. 

: Copy was performed using a File::Find call back:-
:    File::Copy($File::Find::name,"N:/docs/$year/$mon/$day/$_");

This may be unrelated, but from the command line you have to explicitly
copy everything on NT in binary mode to be sure the copy works correctly.

	copy /b old new



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

Date: Wed, 22 Jan 2003 02:04:41 GMT
From: "I'm Dan" <dg1261@cs-REMOVE_THIS-.com>
Subject: identifying web host platform?
Message-Id: <Z_mX9.776698$WL3.770936@rwcrnsc54>

Some time ago (within the last year or two) I recall tinkering with a way to
reveal the host platform and server of a website (ie., NT vs linux, IIS v
Apache, etc).  However, I can no longer recall how it was done.  I don't
remember whether it was a URL of some diagnostic site, or whether it was a
perl CGI script, or whether it was some exe file to run.  I don't even
remember whether I learned about it from a magazine (PC Magazine, maybe?) or
from a newsgroup.  Does this ring a bell with anyone?





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

Date: Tue, 21 Jan 2003 23:02:44 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Newbie: How to remove some characters from a string
Message-Id: <okkX9.50882$_N5.492801@news20.bellglobal.com>

[ Do not use "Newbie" in your subject header or your article may not be
seen by many. ]

Frank San Juan <sanjuan10@hispavista.com> wrote:
> 
> I'm trying to remove these characters from my string: "," and ".".
> 
> I've been playing with Regular Expressions, but I'm green:
> $text =~ s/([\,\.])/\d/g;
> 
> I write '\d' in order to _D_elete the character, but I get a 'd'
> character.  John,Paul,Mary ---> JohndPauldMary (and I want:
> JohnPaulMary)

For this, you're better off with transliteration than regular
expressions:

$text =~ tr/,.//d;  # see perlop for transliteration operator

But if you had to use the (less efficient) regular expression, you
should read perlre instead of making up stuff and hoping it works.

$text =~ s/[,.]//g;  # see perlre

The transliterator is the better option.

Steve
-- 
Steven Smolinski => http://arbiter.ca/
GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
                 => or email me with 'auto-key' in the subject.
Key Fingerprint  => 08C8 6481 3A7B 2A1C 7C26  A5FC 1A1B 66AB F637 495D


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

Date: Tue, 21 Jan 2003 17:13:43 -0600
From: "Bob Dover" <dover@nortelnetworks.com>
Subject: Re: Newbie: How to remove some characters from a string
Message-Id: <b0kk8c$jr5$1@zcars0v6.ca.nortel.com>

"Frank San Juan" wrote...
>
> I'm trying to remove these characters from my string: "," and ".".
> $text =~ s/([\,\.])/\d/g;

Try:
$text =~ s/[\,\.]//g;

-Bob




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

Date: Wed, 22 Jan 2003 00:06:27 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Newbie: How to remove some characters from a string
Message-Id: <b0kna3$2bg$1@wisteria.csv.warwick.ac.uk>

sanjuan10@hispavista.com (Frank San Juan) wrote:
>I'm trying to remove these characters from my string: "," and ".".
>
>I've been playing with Regular Expressions, but I'm green:
>$text =~ s/([\,\.])/\d/g;

Have you read _any_ of Perl's documentation?
You need neither the () brackets nor the backslashes.
The bslashes are harmless but messy; the brackets will make things slower and
may cause problems later.

>I write '\d' in order to _D_elete the character, but I get a 'd' character.

Where on _earth_ did you get that idea from?

>John,Paul,Mary ---> JohndPauldMary
>(and I want: JohnPaulMary)

s/[,.]//g;

replace dot-or-comma with nothing.

Now read perldoc perlretut and perldoc perlop.
Oh, and the posting guidlines 
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 .

Ben


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

Date: Tue, 21 Jan 2003 17:20:03 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie: How to remove some characters from a string
Message-Id: <slrnb2rld3.4qb.tadmc@magna.augustmail.com>

Frank San Juan <sanjuan10@hispavista.com> wrote:
> 
> I'm trying to remove these characters from my string: "," and ".".
> 
> I've been playing with Regular Expressions, but I'm green:


You do not need regular expressions to remove those characters
from your string.

   $text =~ tr/,.//d;


> $text =~ s/([\,\.])/\d/g;
             ^ ^ ^  ^
             ^ ^ ^  ^

You do not need any of those characters, it will do the
same thing without them.


> I write '\d' in order to _D_elete the character, but I get a 'd' character.


What makes you think that you are _supposed_ to write \d in order
to delete the character?

That is, where did you read that?

You can't just make stuff up and hopes that it works, Perl's DWIMery 
is good, but it isn't that good...

If you want to replace it with nothing, then replace it with nothing:

      $text =~ s/[,.]//g;


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


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

Date: 21 Jan 2003 15:20:06 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Paragraph Mode
Message-Id: <3e2dd5a6@news.victoria.tc.ca>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: Alan J. Flavell <flavell@mail.cern.ch> wrote in comp.lang.perl.misc:
: > On Jan 21, Tassilo v. Parseval inscribed on the eternal scroll:

: [about $/ in perlvar]

: > To start however, it seems a consensus is needed on whether the term
: > "Paragraph mode" covers one or both of $/ = ''; and $/ = "\n\n"; The
: > current perlvar explains well enough what each of them does, but omits
: > to give a name to them.

: That question never occurred to me.  Right-thinking Perlers know that
: $/ = ''; is the true paragraph mode, anything else is ersatz.  I think
: a case can be made for that belief.

I agree with the conclusion. 

Notice that the docs discuss how to change perl's opinion of what
constitutes a "line".  You can change its opinion, but in almost all cases
the result has nothing special about it - a "line" is simply everything
from the current position upto and including the fixed delimiter that you
supply. 

However, (as in much of perl), there are certain cases that are "special",
and therefore deserve their own name.

"slurp mode" is one such special behaviour. 

"paragraph mode" should be another.  Paragraph mode is when perl makes the
end of "line" parsing more useful for picking up blocks of text by
applying additional behind the scenes logic to the normally trivial
algorithm. 


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

Date: Wed, 22 Jan 2003 10:58:53 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Paragraph Mode
Message-Id: <slrnb2rnlt.7m2.mgjv@martien.heliotrope.home>

On Tue, 21 Jan 2003 21:32:18 +0100,
	Alan J. Flavell <flavell@mail.cern.ch> wrote:
> On Jan 21, Tassilo v. Parseval inscribed on the eternal scroll:
> 
>> But is it a FAQ? I think working around an omission in perlvar.pod by
>> adding an entry to the FAQs doesn't seem quite right.
> 
> I'd certainly vote for making the documentation the first priority.
> 
> As for FAQ, maybe it isn't a question that's frequently asked.  It
> wouldn't be the first time that an answer which is often enough needed
> was smuggled into the FAQs with a somewhat artifical question to hang
> it on.  ;-)  But I still think it's perlvar to tackle first.
> 
> To start however, it seems a consensus is needed on whether the term
> "Paragraph mode" covers one or both of $/ = ''; and $/ = "\n\n"; The
> current perlvar explains well enough what each of them does, but omits
> to give a name to them.

perlrun quite clearly states that "the special value 00 will cause Perl
(sic) to slurp files in paragraph mode.". It doesn't state specifically
that this is equivalent to $/ = "", but it is, as a little testing could
show.

Therefore, there should be no confusion. Paragraph mode is where perl
sees any sequence of more than one newlines as a record separator. To
get this behaviour, you set $/ to "", or use -000 as a command line
flag.


I don't think the documentation is lacking anything as such. Paragraph
mode is not "official" Perl language, however..

I agree that, since the term "paragraph mode" has become part of Perl's
terminology, that the entry for $/ should be fixed. I also think the FAQ
entry would be a good idea. If you hear the term paragraph mode, and
you're a tool-deprived beginner (e.g. you're on a platform withour
grep), you will not know that you should be looking at -0 or $/ entries
to find out what paragraph mode means, even if you've picked up that
phrase somewhere. While most of Perl's documentation is a reference
(although many of the tutorials are fixing this), the FAQ is more of a
place where new users can look up things expressed in English. Apart
from answering FAQs, they also function a little bit as an index into
the reference documentation by providing keywords and locations to look.

Martien
-- 
                        | 
Martien Verbruggen      | If it isn't broken, it doesn't have enough
                        | features yet.
                        | 


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

Date: Wed, 22 Jan 2003 11:03:10 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Paragraph Mode
Message-Id: <slrnb2rntu.7m2.mgjv@martien.heliotrope.home>

On Tue, 21 Jan 2003 16:06:24 +0100,
	Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:
> Alan J. Flavell wrote (Tuesday 21 January 2003 14:47):
> 
>> On Jan 21, Koos Pol inscribed on the eternal scroll, apparently at
>> 13:47:05:
>> 
>>> My guess is it is the standard mode.
>> 
>> My guess it that if you're unsure, then waiting to see if one of the
>> regulars answers would be a useful strategy.  If, after a reasonable
>> delay, no-one has offered any answer, then it might be time to step up
>> to the plate.
> 
> Don't patronize me. After my explaination (there seems to be a 
> linguistic/I18N issue according to my Dutch/English dictionary), it seems 
> perfectly valid to offer my guess especially when it is said to be a guess 
> from the start and not as a fact. And the OP is free to migrate my 
> suggestion to /dev/null if my paragraph is not the same as his.
> Enough said.

No. Not enough said.

As Alan explained, if you're uncertain, it is better, MUCH better, to
wait until you are certain no one else is going to provide an accurate
answer. Much better for everyone involved. No one has to correct your
wrong answer, which is wasteful of their time, and no one has to even
bother reading your wrong answer, plus all followups that are certain to
come.

And coming up with lame excuses is weak and petty. Don't. Just accept
criticism and move on.

Martien
-- 
                        | 
Martien Verbruggen      | Begin at the beginning and go on till you
                        | come to the end; then stop.
                        | 


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

Date: Tue, 21 Jan 2003 18:19:45 -0500
From: "Lao Tzu" <LaoTzu@TaoTeChing.co.uk.us>
Subject: Re: Perl Script not working on Win NT
Message-Id: <NmkX9.1556$t51.587@news.bellsouth.net>


"Eric" <electo7366@aol.com> wrote in message
news:fc8f04ad.0301211453.49b599da@posting.google.com...
> I have a perl script that works on Linux, Unix, and Win ME with
> Apache. I need it to run on Win NT/2000 web server with IIS 5.0.
>
> After going through the script I have determined it is not opening a
> file using the open command. I've tried using the standard unix file
> paths /cgi-bin/file.txt as well as the full disk path C:\directory\
> and C:/directory/ none work. The file does not return an error.
>
> Does anyone know how to fix this? Is it the file path or a problem
> with the perl open command?
>
> Thank you!!
>

Try using something like:

open(FILE, $filename) || die "Can't open `$filename': $!";

to open the file, that way you can see an error.





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

Date: Tue, 21 Jan 2003 23:33:53 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.nospam>
Subject: Re: Perl Script not working on Win NT
Message-Id: <b0kld1$og2$1@knossos.btinternet.com>

> After going through the script I have determined it is not opening a
> file using the open command.

do you mean to say that your script "is trying and failing to open a file
using the open command" ?

> I've tried using the standard unix file
> paths /cgi-bin/file.txt as well as the full disk path C:\directory\
> and C:/directory/ none work.

from within perl you use "/"s in pathnames even on operating systems which
use "\"s.

> The file does not return an error.

files don't "return errors" in and of themselves - do you mean to say that
the open command does not return an error?  i very much doubt that the open
command is failing without returning an error - how are you checking the
return code?  your code should look something like -

open (FH, "/path/to/file.txt") or die "can't open file - error message is:
$!";

i suggest you isolate the problem in the smallest possible test script, and
troubleshoot a bit - can you get the script to open any files at all?  how
are those files different from the one that you can't open?  if you have no
joy then post the relevant code here.

-eric




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

Date: Tue, 21 Jan 2003 20:33:34 -0500
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Regex: optional word boundary
Message-Id: <b0ksdj$r073c$1@ID-124651.news.dfncis.de>

Hi!  I am trying to create a single regular expression rule that will match
_either_ a certain independent word _or_ certain specified compounds in
which that word is the first element, but not other compounds in which the
word is a specified element.  For instance, the rule should match
fan
fanmail
fanbase

-- but not
fantastic

or any other compound other than, say, in this case, compounds with "mail"
and "base."  In other words, the rule is to say that there is either a word
boundary at the end of "fan" _or_ "fan" is followed by one of the two other
possibilities.  This will not work:

\bfan(mail | base)?

-- because it will match "fantastic."

I realize that this question really is entirely about regular expressions,
not specifically about Perl.  If I should not be posting the question to
this NG, I'd appreciate specific advice about where else to post such
questions.  I did a few searches for NGs devoted to regular expressions and
didn't turn any up.

Thanks.

Amittai Aviram
amittai@amittai.com






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

Date: Tue, 21 Jan 2003 23:08:18 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Reverse Inheritance?
Message-Id: <x7u1g2rti6.fsf@mail.sysarch.com>

>>>>> "BM" == Ben Morrow <mauzo@mimosa.csv.warwick.ac.uk> writes:

  BM> eval is also the answer recommended in perldoc -f require.

  >> for the odd cases where use is needed at runtime, then string eval
  >> is (a poor) solution.

  BM> I fully agree here. Use is never needed at runtime. The solution I
  BM> would use is

  BM> $module = "File::Copy";
  BM> eval "require $module";
  BM> import $module qw/args/;

  BM> .

  BM> Am I missing something here? Is there a solution that doesn't require eval
  BM> (well, except in the sense that a require is a do is an eval)?

i have done the file munging at runtime so i know that is needed. should
change that to use file::spec as it is hardwired for unix paths now. the
only advantage in using the string eval is that you can keep the module
name as a class name and not a real path. but then you also have to taint
check the module name if it came from the outside as it will be passed
to eval. converting the module name to a path and then calling require
is inherently safe as all it can do is load a file.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: Wed, 22 Jan 2003 02:42:10 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Send a file w/ CGI
Message-Id: <1394456.h5OvO8l3qq@nyoga.dubu.de>

Ryan wrote:
>   I tried the following code, but it doesn't work especially on
>   Mozilla.

"doesn't work" is not a valid error description.  Please be more
specific.  Your code Works For Me[tm] with Mozilla, Netscape 4.x, and
Konqueror.

(Although with different results: Netscape offers the filename as
proposed in the Content-Disposition header, Mozilla wants to add the
extension .exe - on Linux! d'oh! - and Konqueror ignores the
disposition and offers the script name as filename.)

> my $path = "/data/";
> my $fname = $FORM{file};
> my $cwd = '';
> if ($FORM{CWD}) { $cwd = "$FORM{CWD}/"; }
> my $filepath = "$path$cwd$fname";

I really hope that those %FORM variables don't come directly from form
entries, or you opened a huge security hole on the server.  Just
imagine what happens if I call your script with CWD=../etc and
file=passwd ...

> print "Content-type: application/octet-stream\r\n";

Please use \015\012, not \r\n.
\n is a logical newline and may produce different output on different
operating systems.

Or just let CGI.pm do this for you.

> print "Content-Length: $size\r\n";
> print "Content-disposition: attachment;filename=$fname\r\n\r\n";

According to the RFC, the filename argument should be in double quotes.
(But most browsers don't care, anyway.)

> open(FILE, "<$filepath") || die;

Let Perl tell you the reason why the open fails:
                .. or die "cannot open $filepath: $!";

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Es gibt keine bedeutenden Fehler in unseren Programmen, die eine
nennenswerte Anzahl von Benutzern behoben haben moechte
                -- Bill Gates, Focus 43/1995 


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

Date: Tue, 21 Jan 2003 18:32:15 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: split with pattern matching question
Message-Id: <3E2DD87F.4080104@consultant.com>

$_ contains a line with items delimited with "|" which looks something like:
|TEXT1    |TEXT2     |     TEXT3|    TEXT4   |

The following program line works fine to remove all trailing white space 
in each field.
my $line = join '|', split /\s*(?:\||$)/;

However, I can't figure out how to remove the leading white space also. 
Pattern matching is already hard to understand, but pattern matching as 
argument to split ...

Any help is appreciated.

Thanks,
Alex

-- 
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)




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

Date: 22 Jan 2003 00:07:16 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: split with pattern matching question
Message-Id: <b0knbk$js5$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Alexander Stremitzer:

> $_ contains a line with items delimited with "|" which looks something like:
>|TEXT1    |TEXT2     |     TEXT3|    TEXT4   |
> 
> The following program line works fine to remove all trailing white space 
> in each field.
> my $line = join '|', split /\s*(?:\||$)/;
> 
> However, I can't figure out how to remove the leading white space also. 
> Pattern matching is already hard to understand, but pattern matching as 
> argument to split ...

It's not so hard. Just think about where a split should happen. This
'where' can be described using a pattern:

    my $line = join '|', split /\s*\|\s*/;

That reads: Split on any number of whitespaces followed by one | and
again followed by any number of whitespaces (including none at all).
Since the * modifier is greedy it will gobble up as many as possible.

But what I really wonder about: Do you make these split contortions
simply to remove whitespaces? If so a mere

    s/\s*//g;

would be easier.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Tue, 21 Jan 2003 19:27:28 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Re: split with pattern matching question
Message-Id: <3E2DE570.5010301@consultant.com>

Thanks, that did the trick.

Tassilo v. Parseval wrote:

>>|TEXT1    |TEXT2     |     TEXT3|    TEXT4   |
>>
>But what I really wonder about: Do you make these split contortions
>simply to remove whitespaces? If so a mere
>
>    s/\s*//g;
>
>would be easier.
>
>Tassilo
>
I did not describe my input data accurate enough. A field can also look 
like |  TEXTA  TEXTB  |. I don't want to remove the space between TEXTA 
and TEXTB.

-- 
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)





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

Date: Tue, 21 Jan 2003 17:15:10 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: split with pattern matching question
Message-Id: <Pine.GSO.4.21.0301211708070.24992-100000@mtwhitney.nsc.com>

On Tue, 21 Jan 2003, Alexander Stremitzer wrote:

> $_ contains a line with items delimited with "|" which looks something like:
> |TEXT1    |TEXT2     |     TEXT3|    TEXT4   |
> 
> The following program line works fine to remove all trailing white space 
> in each field.
> my $line = join '|', split /\s*(?:\||$)/;
> 
> However, I can't figure out how to remove the leading white space also. 
> Pattern matching is already hard to understand, but pattern matching as 
> argument to split ...
> 
> Any help is appreciated.



The canonical way to remove blank space from the beginning and end is
with s/^\s+// and s/\s+$// (see perldoc -q "blank space").  If you
find it too difficult to incorporate all that into one regular
expression, you may want to split it up into many:

my $line = join '|', map {s/^\s+//; s/\s+$//; $_} split (/\|/, $_);

To my eye, this is more legible (but probably slower). YMMV.


-- 
Cheers,
Steven



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

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


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