[25202] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7448 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 25 21:05:58 2004

Date: Thu, 25 Nov 2004 18:05:05 -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           Thu, 25 Nov 2004     Volume: 10 Number: 7448

Today's topics:
    Re: CGI.PM not setting HTTP header <tadmc@augustmail.com>
    Re: CGI.PM not setting HTTP header <nospam@thanksanyway.org>
    Re: CGI.PM not setting HTTP header <flavell@ph.gla.ac.uk>
    Re: CGI.PM not setting HTTP header <tadmc@augustmail.com>
    Re: character encoding in CGI.pm <flavell@ph.gla.ac.uk>
    Re: character encoding in CGI.pm <flavell@ph.gla.ac.uk>
        Cut the last invisible spaces from the words <david@NoSpam.com>
    Re: Cut the last invisible spaces from the words <david@NoSpam.com>
    Re: Cut the last invisible spaces from the words <tadmc@augustmail.com>
    Re: Dat files help "Att James" <tadmc@augustmail.com>
    Re: Dat files help "Att James" hope@hope.com
    Re: Dat files help "Att James" <tadmc@augustmail.com>
        FAQ 4.49: How do I process/modify each element of an ar <comdog@panix.com>
    Re: Help: separate difference length of spaces between  <tadmc@augustmail.com>
    Re: List::Util::shuffle - where did the algorithm come  <richard@zync.co.uk>
        looking for a better regexp (mike)
    Re: looking for a better regexp <noreply@gunnar.cc>
    Re: Need some problemsolving-cgi/xml <jwillmore@fastmail.us>
    Re: Using embedded PERL with commercial applications? (Cameron Laird)
    Re: using sort directly on subroutine returning list <kisrael@mezzo.eecs.tufts.edu>
    Re: using sort directly on subroutine returning list <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 25 Nov 2004 13:30:56 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <slrncqccng.bpm.tadmc@magna.augustmail.com>

Mark <nospam@thanksanyway.org> wrote:
> "Tore Aursand" <toreau@gmail.com> wrote:
>>
>> Is the server written in Perl?
> 
> It's an Apache server.


Is the Apache server written in Perl?


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


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

Date: Thu, 25 Nov 2004 12:51:05 -0800
From: "Mark" <nospam@thanksanyway.org>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <fPKdnbbO0f8u2DvcRVn-3w@speakeasy.net>

"Tad McClellan" <tadmc@augustmail.com> wrote:

> Is the Apache server written in Perl?

Maybe.





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

Date: Thu, 25 Nov 2004 22:00:21 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <Pine.LNX.4.61.0411252150430.23751@ppepc56.ph.gla.ac.uk>

On Thu, 25 Nov 2004, Mark wrote:

> "Tad McClellan" <tadmc@augustmail.com> wrote:
> 
> > Is the Apache server written in Perl?
> 
> Maybe.

Watch out.  The hon Usenauts are trying to advise you, in their 
somewhat grumpy and obtuse fashion, that you started off by saying

|| but the server is returning a MIME type of 'text/plain'.

If you truly had a web server problem, then your problem would be 
wildly off-topic here.  I think they want you to acknowledge that.

As it turned out, you've solved your problem by using CGI.pm better.  
It's still not (quite) a Perl language problem, and might have been 
more at home on a usenet group that's primarily about the CGI, but
you've rubbed-up several of the respected contributors here in the 
wrong way, and I wouldn't really recommend that: they may prove 
infinitely helpful to you in future, if you give them the idea that 
you're keen to learn.

all the best


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

Date: Thu, 25 Nov 2004 18:39:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <slrncqcuqq.1p2.tadmc@magna.augustmail.com>

Mark <nospam@thanksanyway.org> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote:
> 
>> Is the Apache server written in Perl?
> 
> Maybe.


 *plonk*


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


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

Date: Thu, 25 Nov 2004 22:22:26 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: character encoding in CGI.pm
Message-Id: <Pine.LNX.4.61.0411252215340.23751@ppepc56.ph.gla.ac.uk>


By sheer chance, Google Groups pointed out to me that:

On Wed, 24 Nov 2004, Shawn Corey wrote:

[I'm trimming the comprehensive quote down to what I suppose you must 
have interpreted as the significant part.  There's no extra charge for 
doing this yourself, you know...]

> > Now,  is the webpage in ISO-8859-1, utf8, or some other encoding? 
>
> The web page is both.

Impossible, unless it happens to be in us-ascii, in which case it's a 
valid instance of all three.

> The ISO-8859-1 encoding is used for the HTTP transfer. All bytes, 
> including the web page, while be interpreted as ISO-8859-1 encoded 
> until handed off to the display engine in the browser. Then it will 
> be interpreted as UTF-8. This normally does not mean much since the 
> bytes after the blank line are usually not processed by the HTTP 
> decoding code; they are simply passed to the next part.

A truly remarkable castle that you've built in the air there; have you 
read XHTML/1.0 Appendix C, by any chance?

> See perldoc CGI for details.

Whimper.

Once again, I suppose this brings home the importance of not going 
into technical detail on matters that are off-topic for the group.


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

Date: Thu, 25 Nov 2004 23:09:23 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: character encoding in CGI.pm
Message-Id: <Pine.LNX.4.61.0411252258110.23751@ppepc56.ph.gla.ac.uk>

Oh dear, this is desperately off-topic...

On Thu, 25 Nov 2004, Ben Morrow wrote:

> Correct me if I'm wrong, but surely XHTML cannot be served under a
> text/html content type anyway? 

Technically, you're right.  Practically, I'd have to refer you to 
XHTML/1.0 Appendix C.  Well, I already did, but you seem to have 
resisted the temptation to mention it.

> It isn't valid HTML 

Correct.  Appendix C is in theory self-contradictory, but in practice
it gets away with it, since almost all "web browsers" implement 
tag-soup rather than HTML "per se".

emacs-w3 indeed had to be deliberately broken in order to be 
compatible with Appendix C, since it had taken the HTML specification 
just a bit more seriously than anyone else (aside from SGML-conforming 
browsers such as softquad panorama, but who uses those as www 
browsers?).

> 1. the content should be labelled application/xhtml+xml

"should".  Right. XHTML/1.0 Appendix C is a (misguided, IMHO) 
exception to that rule.

> 2. the charsets should match

"must" match, except in a few degenerate cases (since us-ascii can be 
validly labelled as iso-8859-anything as well as utf-8, whatever 
happens to be convenient).

> 3. the charset shouldn't be specified in the HTTP header anyway,

Disagree; but this isn't the place to argue the point.

all the best


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

Date: Thu, 25 Nov 2004 16:22:24 -0500
From: "Dave" <david@NoSpam.com>
Subject: Cut the last invisible spaces from the words
Message-Id: <co5ieh$728$1@zcars0v6.ca.nortel.com>

Sorry to bother you, guys

I have a problem here that :

There is a Txt file formateted like

Apple  (2 spaces after Apple, then \n)
Orange (4 spaces after Apple, then \n)
 ..................

When I use grep, and store the row value to $A. It actually contains some
invisible spaces which failed in the my database query.
 Is there any good way to get rid of these spaces?

Thanks





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

Date: Thu, 25 Nov 2004 16:39:33 -0500
From: "Dave" <david@NoSpam.com>
Subject: Re: Cut the last invisible spaces from the words
Message-Id: <co5jen$afc$1@zcars0v6.ca.nortel.com>

I found one sub routine which can solve this problem.

           $many   = trim($many);

                sub trim {
                        my @out = @_;
                        for (@out) {
                        s/^\s+//;
                    s/\s+$//;
                         }
                 return wantarray ? @out : $out[0];
                }
:



"Dave" <david@NoSpam.com> wrote in message
news:co5ieh$728$1@zcars0v6.ca.nortel.com...
> Sorry to bother you, guys
>
> I have a problem here that :
>
> There is a Txt file formateted like
>
> Apple  (2 spaces after Apple, then \n)
> Orange (4 spaces after Apple, then \n)
> ..................
>
> When I use grep, and store the row value to $A. It actually contains some
> invisible spaces which failed in the my database query.
>  Is there any good way to get rid of these spaces?
>
> Thanks
>
>
>




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

Date: Thu, 25 Nov 2004 19:06:52 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Cut the last invisible spaces from the words
Message-Id: <slrncqd0dc.1p2.tadmc@magna.augustmail.com>

Dave <david@NoSpam.com> wrote:

> Sorry to bother you, guys


Apologizing for asking a Frequently Asked Question does not make
it OK to ask a Frequently Asked Question.

You are expected to check the Perl FAQ *before* you post to the 
Perl newsgroup.


> Apple  (2 spaces after Apple, then \n)


> When I use grep, 


Why are you using grep(1) when you have Perl?

Perl can do what grep(1) does, there is no need to shell out.


>  Is there any good way to get rid of these spaces?


   perldoc -q space

       How do I strip blank space from the beginning/end of a string?


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


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

Date: Thu, 25 Nov 2004 13:46:28 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Dat files help "Att James"
Message-Id: <slrncqcdkk.bpm.tadmc@magna.augustmail.com>

hope@hope.com <hope@hope.com> wrote:
> On Wed, 24 Nov 2004 14:26:58 -0800, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> 
>>In article <h2r9q0lpmkd35tc7g1qkhbtova6gcm4lbg@4ax.com>,
>><hope@hope.com> wrote:


>>> use CGI:: Carp dw(fatelsToBrowser)
>>
>>Spelling counts. Did you cut and paste this out of your program or
>>re-type it?
> 
> Yes I did re-type it 


Have you seen the Posting Guidelines that are posted here frequently?


> I see the  mistakes now it should be
>>> use CGI ::Carp qw<fatelsToBrowser>;


There is *still* a typo there you know...


>>> Name "Main::dir" used only once possible typo at line 13
>>> Use of uninitalized value in concatenation (.) or string at line 13
>>
>>These are warnings, not fatal errors, but they may be significant.


They point out rather clearly what the problem is.

Namely, $dir has never been given a value.



> open my $out, '+>/home/me/outfile' or die $!;


Why do you open it for input AND output when you are only
using it for output?


>     read $fh, my $data, -s $fh;
>     my @fields = split /\n/, $data;
>     $csv->combine(@fields);


>>From the above, I might guess that $dir is undefined.


And it still is.


> As always, any and all help is greatly appreciated.


Any not-ignoring of previously received help is greatly appreciated.

Your original code had nothing in $dir.

It was pointed out that $dir had nothing it...

 ... and here is some new code, still with nothing in $dir.

Put something like '/home/local/whatever' into $dir before
you use $dir.


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


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

Date: Thu, 25 Nov 2004 21:46:57 GMT
From: hope@hope.com
Subject: Re: Dat files help "Att James"
Message-Id: <goicq0l4dna939mcmu8omm26v3ojlt85na@4ax.com>

On Thu, 25 Nov 2004 13:46:28 -0600, Tad McClellan <tadmc@augustmail.com> wrote:

>hope@hope.com <hope@hope.com> wrote:
>> On Wed, 24 Nov 2004 14:26:58 -0800, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>> 
>>>In article <h2r9q0lpmkd35tc7g1qkhbtova6gcm4lbg@4ax.com>,
>>><hope@hope.com> wrote:
>
>
>>>> use CGI:: Carp dw(fatelsToBrowser)
>>>
>>>Spelling counts. Did you cut and paste this out of your program or
>>>re-type it?
>> 
>> Yes I did re-type it 
>
>
>Have you seen the Posting Guidelines that are posted here frequently?

I presume you mean the line where it says 
DO NOT TYPE IN YOUR CODE
>
>> I see the  mistakes now it should be
>>>> use CGI ::Carp qw<fatelsToBrowser>;
>
>
>There is *still* a typo there you know...

Ok so you mean should be "("  instead of  ">"
>
>
>>>> Name "Main::dir" used only once possible typo at line 13
>>>> Use of uninitalized value in concatenation (.) or string at line 13
>>>
>>>These are warnings, not fatal errors, but they may be significant.
>They point out rather clearly what the problem is.

Yes for you, but it is like all things in life very easy when you know how

Yes I have read and read also looked in these groups and also I have now found the perldocs etc 

>
>Namely, $dir has never been given a value.


Yes I know, If you look at my  post to james in here you will see that I did Find that error out
and ask him how I do this
See below further down for this

>> open my $out, '+>/home/me/outfile' or die $!;
>
>
>Why do you open it for input AND output when you are only
>using it for output?

I do not know why
In my very first post to this group on this subject A very kind person named James wrote this script for me

So I did not write it, that is why the Subject is Att James
I wanted to ask him these things But he as not got back to me as yet
>
>>     read $fh, my $data, -s $fh;
>>     my @fields = split /\n/, $data;
>>     $csv->combine(@fields);
>
>>>From the above, I might guess that $dir is undefined.
>
>And it still is.

Ok I see that now, BUT I have done some searches on how to define and all I came up with was 

my  $dir = '/xxx/xxx';

So the director where my dat files are in WinXp pro are
c:\1\35 
So I put
 my  $dir = '/1/35';
But that did not work  

>> As always, any and all help is greatly appreciated.
>
>Any not-ignoring of previously received help is greatly appreciated.

I'm sorry what do you mean?

>
>Your original code had nothing in $dir.
>
>It was pointed out that $dir had nothing it...

I'm sorry but that is not much help to me as I said above
If you had said to me 
>Your original code had nothing in $dir.
It should look like   xxxxx xxxxx   xxxxx
I would understand and did some more searches on it
>
>... and here is some new code, still with nothing in $dir.

What new code?

>Put something like '/home/local/whatever' into $dir before you use $dir.

So is this the same as above?

my  $dir = '/1/35';

So now I'm saying that $dir is = to a folder on my hard drive  like c:\1

Sorry to be so dum

Regards

 



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

Date: Thu, 25 Nov 2004 19:02:29 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Dat files help "Att James"
Message-Id: <slrncqd055.1p2.tadmc@magna.augustmail.com>

hope@hope.com <hope@hope.com> wrote:
> On Thu, 25 Nov 2004 13:46:28 -0600, Tad McClellan <tadmc@augustmail.com> wrote:
>>hope@hope.com <hope@hope.com> wrote:
>>> On Wed, 24 Nov 2004 14:26:58 -0800, Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>>>>In article <h2r9q0lpmkd35tc7g1qkhbtova6gcm4lbg@4ax.com>,
>>>><hope@hope.com> wrote:
>>
>>
>>>>> use CGI:: Carp dw(fatelsToBrowser)
                           ^
                           ^
>>>>Spelling counts.

>>> I see the  mistakes now it should be
>>>>> use CGI ::Carp qw<fatelsToBrowser>;
                           ^
                           ^
>>There is *still* a typo there you know...
> 
> Ok so you mean should be "("  instead of  ">"


Sheesh man, wake up!

He said *spelling* counts.

Punctuation is not spelling.

You have misspelled something there, even after being told that
you have misspelled something there.


>>>>These are warnings, not fatal errors, but they may be significant.
                            ^^^^^

Spelled correctly. That should be helpful to you.


>>> open my $out, '+>/home/me/outfile' or die $!;
>>
>>
>>Why do you open it for input AND output when you are only
>>using it for output?
> 
> I do not know why


You should not run code that you don't understand...


> In my very first post to this group on this subject A very kind person named James wrote this script for me


 ... because *bad* guys also post code on the web, hoping to lure
people into running it for them.

Don't be their patsy.

(I am not talking about James here, of course.)


>>>     read $fh, my $data, -s $fh;
>>>     my @fields = split /\n/, $data;


That is a mighty strange way of reading in the data...

   chomp( my @fields = <$fh> );  # does the same thing, no temp variable


>>>>From the above, I might guess that $dir is undefined.
>>
>>And it still is.
> 
> Ok I see that now, BUT I have done some searches on how to define and all I came up with was 
> 
> my  $dir = '/xxx/xxx';


Yes, exactly so.


> So the director where my dat files are in WinXp pro are
> c:\1\35 
  ^^
  ^^
> So I put
>  my  $dir = '/1/35';
> But that did not work  


How come you didn't put the "c:" part in there?

   my  $dir = 'c:/1/35';


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


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

Date: Thu, 25 Nov 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.49: How do I process/modify each element of an array?
Message-Id: <co5ob5$ncn$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.49: How do I process/modify each element of an array?

    Use "for"/"foreach":

        for (@lines) {
            s/foo/bar/;     # change that word
            y/XZ/ZX/;       # swap those letters
        }

    Here's another; let's compute spherical volumes:

        for (@volumes = @radii) {   # @volumes has changed parts
            $_ **= 3;
            $_ *= (4/3) * 3.14159;  # this will be constant folded
        }

    which can also be done with map() which is made to transform one list
    into another:

            @volumes = map {$_ ** 3 * (4/3) * 3.14159} @radii;

    If you want to do the same thing to modify the values of the hash, you
    can use the "values" function. As of Perl 5.6 the values are not copied,
    so if you modify $orbit (in this case), you modify the value.

        for $orbit ( values %orbits ) {
            ($orbit **= 3) *= (4/3) * 3.14159;
        }

    Prior to perl 5.6 "values" returned copies of the values, so older perl
    code often contains constructions such as @orbits{keys %orbits} instead
    of "values %orbits" where the hash is to be modified.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Thu, 25 Nov 2004 13:35:41 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help: separate difference length of spaces between words
Message-Id: <slrncqcd0d.bpm.tadmc@magna.augustmail.com>

KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote:


> So, Lei, here's another important lesson: to get the real scoop in
> CLPM, don't ask.  Just post your best guess as fact, and someone
> who really knows will go ballistic and post the correct answer.


You can count on that not happening for future posts of yours.


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


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

Date: Thu, 25 Nov 2004 19:30:08 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Re: List::Util::shuffle - where did the algorithm come from?
Message-Id: <pan.2004.11.25.19.30.07.958095@zync.co.uk>

On Thu, 25 Nov 2004 19:03:04 +0000, Richard Gration wrote:

Ah, sorry, got sidetracked. The reason I was looking at this sub is to see
if I could adapt it to not shuffle certain elements of the list based on
arbitrary criteria. "Not easily" was my answer. Can anyone suggest how I
could do this?

My shuffle code atm looks like:

for (0 .. 3 * $page->{numqs}) {
    my $q1 = int rand $page->{numqs};
    my $q2 = int rand $page->{numqs};
    redo if ($page->{questions}->[$q1]->{qtype} =~ /^pres/
          or $page->{questions}->[$q2]->{qtype} =~ /^pres/);
    my $q = $page->{questions}->[$q1];
    $page->{questions}->[$q1] = $page->{questions}->[$q2];
    $page->{questions}->[$q2] = $q;
}

It doesn't seem to shuffle very well, particularly for lists with few
elements. That's why I was looking at List::Util::shuffle, which seemed to
do a pretty good job.

This code runs in an Apache module. I saw exactly the same series of
$q1,$q2 numbers generated in 2 consecutive requests. I thought
maybe this is because all the httpd child processes ended up with the same
random number seed. Is this possible? It seemed plausible to me because
each child is forked from the same parent, and all Perl mod init is
done in the parent, unless the mod registers a PerlChildInitHandler, which
is clearly not the case here.

TIA
Rich


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

Date: 25 Nov 2004 17:35:05 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: looking for a better regexp
Message-Id: <dfd17ef4.0411251735.1b16a9d1@posting.google.com>

hi folks

i have to strip a line of empty spaces/tabs before and after a comma
eg word1,  word2  ,word3,word4<tab>,word5
i have to make it become word1,word2,word3,word4,word5

so far i have tried
$line =~ s/^\s+//;      #get rid of spaces in the beginining of the line
$line =~ s/^\t+//;      #get rid of tabs in the beginning of the line
$line =~ s/\s+,/,/g ;   #get rid of spaces before a comma
$line =~ s/,\s+/,/g;    #get rid of spaces after a comma
$line =~ s/\t+,/,/g;    #get rid of tables before comma
$line =~ s/,\t+/,/g;    #get rid of tabs after comma

i may have the line also containing eg
word1,  word2  <2 tabs>  ,word3,word4<1 tab><space><space>,word5
or other combinations of spaces/tabs .

Is there a better way to do the regexp? I just need the output to be
word1,word2,word3,word4,word5

thanks for any help


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

Date: Fri, 26 Nov 2004 02:53:23 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: looking for a better regexp
Message-Id: <30ngqfF32o3jjU1@uni-berlin.de>

mike wrote:
> i have to strip a line of empty spaces/tabs before and after a comma
> eg word1,  word2  ,word3,word4<tab>,word5
> i have to make it become word1,word2,word3,word4,word5
> 
> so far i have tried
> $line =~ s/^\s+//;      #get rid of spaces in the beginining of the line
> $line =~ s/^\t+//;      #get rid of tabs in the beginning of the line
> $line =~ s/\s+,/,/g ;   #get rid of spaces before a comma
> $line =~ s/,\s+/,/g;    #get rid of spaces after a comma
> $line =~ s/\t+,/,/g;    #get rid of tables before comma
> $line =~ s/,\t+/,/g;    #get rid of tabs after comma
> 
> i may have the line also containing eg
> word1,  word2  <2 tabs>  ,word3,word4<1 tab><space><space>,word5
> or other combinations of spaces/tabs .
> 
> Is there a better way to do the regexp? I just need the output to be
> word1,word2,word3,word4,word5

Probably. The \s character class includes tabs, so this should be 
sufficient:

     $line =~ s/^\s+//;
     $line =~ s/\s*,\s*/,/g;

Or if the words may not include whitespace, i.e. if you simply want to 
remove all spaces and tab characters:

     $line =~ tr/ \t//d;

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


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

Date: Thu, 25 Nov 2004 14:30:20 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Need some problemsolving-cgi/xml
Message-Id: <pan.2004.11.25.19.30.18.981436@fastmail.us>

On Thu, 25 Nov 2004 07:22:36 +0100, lievemario wrote:

<snip>
> Now the following errors appear:
> - first of all, I don't know why, but the script is not able to open / write
> person.xml anymore

And your logs say .... what?  Did you check the server logs to see what
messages are being issued by the script?  Have you tested the script at
the command line first?  If so, what happened?  

> - second, when I have such an xml file, the script is not able to produce
> the output,
>    I get a CGI timeout error.
>    (Just for info; I call the script via the following line in the form
> application:
>         <form action="person2.cgi?person_id=$person_id" method="POST">
>    )
>   I have search a long time, but I can not solve the problem.

And your logs say .... what?  Did you check the server logs to see what
messages are being issued by the script?  Have you tested the script at
the command line first?  If so, what happened?  Are you *sure* it's a "CGI
timeout error" and not some other error happening in the background that
results in your script timing out?  Logs will tell you lots ... if you let
them :-)

 
> - another question I also have;
>    it is my intention to execute 1 or more queries (depending on the
> @details the
>    user selected in the form).  How can I combine all these xml files/xsl to
> one output?

To "transform", "process", etc. XML using XSLT, you have a wide variety of
choices (Xalan, Saxon ...).  You could even create an XML file (file
system or in memory) and use XPath statements to extract data from the XML
file. Visit CPAN (http://search.cpan.org) and search for xsl or xml or
xpath to find them :-)

> #!/usr/bin/perl

#!/usr/bin/perl -T
#turn taint checking on
#visit http://www.w3.org/Security/Faq/wwwsf4.html#CGI-Q15 
#for more information
 
> # use strict;

use strict;
use warnings;

> use DBI;
> use XML::Generator::DBI;
> use XML::Handler::YAWriter;
> use XML::Parser;
> use XML::XSLT;

#you already found a module for using XSLT
#have you looked at the 'toString' method?
 
> use CGI qw(param);

use CGI qw(:standard :debug);
#load standard CGI routines *and* debugging support
# ... so you can run the script at the command line
 
<snip>

> # create a DBI connection
> my $dbh = DBI->connect ("DBI:mysql:rd", "root", "",
>   { RaiseError => 1,
>     PrintError => 0
>   });

using 'root' is a *very* bad move for a CGI script ... glad it's not my
box :-)
 
<snip>

> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/,
> $buffer);
> foreach $pair (@pairs) {
>     ($name, $value) = split(/=/, $pair);
>     $value =~ tr/+/ /;
>     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value
>     =~ s/'//g;
>     $value =~ s/&/and/g;
>     $value =~ s/\"//g;
>     $value =~ s/\+//g;
>     $FORM{$name} = $value;
> }
> }

*READ* the CGI documentation ... hell, there's even an *example* at the
very top of the document demonstrating *how* to use the module :-)
The above code is, well, pointless, if you're going to use the CGI module.

> my @details = ("data","team","pubs","other");
> foreach $x (@details) {
>     if ($FORM{$x} == 1) {
>  if($x eq "data") {
>   data_query();
>  }
>  #print "You picked $x.\n";
>     }
>     }
>     }

foreach my $x (@details) {
 ...
}

You need to declare a variable before using it and using the 'strict'
pragma.  The above will do that.

Just FYI, you could also look over ...
http://www.w3.org/Security/Faq/wwwsf4.html#CGI-Q17
on how to untaint variables, and 
http://www.cert.org/tech_tips/cgi_metacharacters.html
on hot to remove unsafe characters from the query string.


<snip>

You should really read the documentation for the various modules you're
using.  It looks like you cobbled together something from various sources
and, well, this ain't going to work the way you expect it to.  Try small
parts of what you're trying to do (for example, do some small XML
transformations first and small do nothing CGI scripts). Test them and see
that they work the way you expect them to. Then put it all together for
the final product.

HTH

Jim


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

Date: Thu, 25 Nov 2004 22:08:03 GMT
From: claird@lairds.us (Cameron Laird)
Subject: Re: Using embedded PERL with commercial applications?
Message-Id: <dtvh72-4d4.ln1@lairds.us>

In article <a1538a71.0411242344.6806e712@posting.google.com>,
Patrick Finnegan <chppxf1@yahoo.com.au> wrote:
			.
			.
			.
>On second thoughts I think Python is maintained by Guido van Rossum.

On a legal basis, the Python license is granted by the Python Software
Foundation <URL: http://www.python.org/2.2/license.html >.


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

Date: Fri, 26 Nov 2004 00:51:13 GMT
From: Kirk Is <kisrael@mezzo.eecs.tufts.edu>
Subject: Re: using sort directly on subroutine returning list
Message-Id: <56vpd.265$Y2.6604@news.tufts.edu>

Bob Walton <see@sig.invalid> wrote:
> Kirk Is wrote:

> > I've been using Perl for at least 10 years and I'm kind of surprised I 
> > haven't run into this one before, so I want to see if I'm interpreting it 
> > correctly...
> > 
> > @files = getarray();
> > @files = sort @files;
> > does 'what I expect' while trying to be "clever" and inline it
> > @files = sort getarray();
> > 
> > Doesn't...because when the first argument to sort is a subroutine,
> > it tries to use it as the comparison function.  
> > 
> > On the other hand, experimentally,
> > @files = sort &getarray();

> ...

> In addition, you can do:

>     @files = sort +getarray;

> which also disambiguates the call to sort (+getarray is clearly not a 
> subname or a block, but an expression).  I'm surprised

Huh, hadn't seen the + operator like that.

>     @files = sort &getarray;

> works, as I would think &getarray is clearly a subname.  Hmmmm.  Perl 
> must think &getarray is an expression?

Dunno.

I really love Perl and I'm probaby too old and crusty (at 30) to change my
ways and switch to another scripting type language, but I read a
description of Ruby as trying to be the language that follows the
principle of least surprise, and sometimes it's funny when Perl doesn't
quite live up to that :-)

-- 
QUOTEBLOG: http://kisrael.com   SKEPTIC MORTALITY: http://kisrael.com/mortal
  BAR JOKE #11 A man walks into a bar. He has a few drinks and chats with the 
  bartender. Later that night, he goes home and reflects on the poor decisons 
  he's made in life.


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

Date: Fri, 26 Nov 2004 02:02:39 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using sort directly on subroutine returning list
Message-Id: <30ndqvF31lqsiU1@uni-berlin.de>

Bob Walton wrote:
> Kirk Is wrote:
>> 
>> @files = sort &getarray();
> 
> In addition, you can do:
> 
>    @files = sort +getarray;
> 
> which also disambiguates the call to sort (+getarray is clearly not a 
> subname or a block, but an expression).

Simply surrounding the function call with parentheses works as well:

     @files = sort( getarray() );

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


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

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


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