[17765] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5185 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 23 00:10:30 2000

Date: Fri, 22 Dec 2000 21:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977548213-v9-i5185@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 22 Dec 2000     Volume: 9 Number: 5185

Today's topics:
        Simple REGEX question <harrisr@bignet.net>
    Re: Simple REGEX question <jdhunter@nitace.bsd.uchicago.edu>
    Re: Simple REGEX question <jhelman@wsb.com>
    Re: Simple REGEX question <rick.delaney@home.com>
    Re: Simple REGEX question <harrisr@bignet.net>
    Re: Strange CGI.pm behaviour (Honza Pazdziora)
        Stripping trailing spaces from string <tmartin1@telocity.com>
    Re: Stripping trailing spaces from string <jdhunter@nitace.bsd.uchicago.edu>
    Re: Stripping trailing spaces from string rereidy@my-deja.com
    Re: Stripping trailing spaces from string (Tad McClellan)
        useing dbms_output_enable and dbms_output_get in PL/SQL rereidy@my-deja.com
        using perl <kasi@students.uiuc.edu>
    Re: using perl <jdhunter@nitace.bsd.uchicago.edu>
    Re: web ask seting cookie when perl ... <jbuff1856@my-deja.com>
    Re: Yesterdays Date (Andrew N. McGuire)
    Re: yet another question: is ' more efficient than "? timallen449@my-deja.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 22 Dec 2000 20:52:20 -0500
From: "Randy Harris" <harrisr@bignet.net>
Subject: Simple REGEX question
Message-Id: <t4819g84i8bmb8@corp.supernews.com>

I'm sure this is obvious to most everyone who reads it, but not to me.

$str =~ s/^\s*()/$1/;
Will trim leading spaces.

$str =~ s/()\s*$/$1/;
Will trim trailing spaces.

Why won't
$str =~ s/^\s*()\s*$/$1/;
trim both ends?

I realize that the first two examples needlessly use $1.






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

Date: 22 Dec 2000 20:20:40 -0600
From: John Hunter <jdhunter@nitace.bsd.uchicago.edu>
Subject: Re: Simple REGEX question
Message-Id: <1r66kbnaiv.fsf@video.bsd.uchicago.edu>

>>>>> "Randy" == Randy Harris <harrisr@bignet.net> writes:

    Randy> Why won't $str =~ s/^\s*()\s*$/$1/; trim both ends?

Because it doesn't allow for anything to match between the parentheses
grouping operator.  Is suspect that this is what you want:

$str =~ s/^\s*(.*)\s*$/$1/;




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

Date: Sat, 23 Dec 2000 02:59:19 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Simple REGEX question
Message-Id: <3A441521.7F6EC49@wsb.com>

John Hunter wrote:
> 
> >>>>> "Randy" == Randy Harris <harrisr@bignet.net> writes:
> 
>     Randy> Why won't $str =~ s/^\s*()\s*$/$1/; trim both ends?
> 
> Because it doesn't allow for anything to match between the parentheses
> grouping operator.  Is suspect that this is what you want:
> 
> $str =~ s/^\s*(.*)\s*$/$1/;

Or better yet,

$str =~ s/^\s+|\s+$//g;

This has a couple of advantages.  First, why save the inner data if you
don't need to?  (If I'm trimming a leading newline off a 1 megabyte
document, I don't want to have perl do the string copy if I can avoid
it.)  Second, by using '\s*' you are matching nothing, which seems like
a waste of time to me.  Instead, only match leading whitespace if it
exists.  If not, ignore it.

Hope this helps,
JH


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

Date: Sat, 23 Dec 2000 04:28:34 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Simple REGEX question
Message-Id: <3A442D90.85987C54@home.com>


Jeff Helman wrote:
> 
> John Hunter wrote:
> >
> > >>>>> "Randy" == Randy Harris <harrisr@bignet.net> writes:
> >
> >     Randy> Why won't $str =~ s/^\s*()\s*$/$1/; trim both ends?
> >
> > Because it doesn't allow for anything to match between the parentheses
> > grouping operator.  Is suspect that this is what you want:
> >
> > $str =~ s/^\s*(.*)\s*$/$1/;

I seriously doubt it.

> Or better yet,
> 
> $str =~ s/^\s+|\s+$//g;

While this will at least work, it is not good enough.  This is a FAQ,
people!

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Fri, 22 Dec 2000 23:43:06 -0500
From: "Randy Harris" <harrisr@bignet.net>
Subject: Re: Simple REGEX question
Message-Id: <t48b9malv86a07@corp.supernews.com>

Jeff Helman <jhelman@wsb.com> wrote in message
news:3A441521.7F6EC49@wsb.com...
> John Hunter wrote:
> >
> > >>>>> "Randy" == Randy Harris <harrisr@bignet.net> writes:
> >
> >     Randy> Why won't $str =~ s/^\s*()\s*$/$1/; trim both ends?
> >
> > Because it doesn't allow for anything to match between the
parentheses
> > grouping operator.  Is suspect that this is what you want:
> >
> > $str =~ s/^\s*(.*)\s*$/$1/;

This doesn't work either. However,  $str =~ s/^\s*(.*?)\s*$/$1/;  does.

I found this in the FAQ after reading a post by Tad McClellan elsewhere.
I still don't understand why the other doesn't.

> Or better yet,
>
> $str =~ s/^\s+|\s+$//g;

This also works, of course.  And without saving the $1 variable, which
would certainly seem more efficient.

But why is (.*) different from (.*?)

Randy Harris




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

Date: Fri, 22 Dec 2000 20:16:32 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Strange CGI.pm behaviour
Message-Id: <slrn947dj0.9aemg.adelton@aisa.fi.muni.cz>

On Fri, 22 Dec 2000 17:18:58 +0100, Alexander Farber (EED) <eedalf@eed.ericsson.se> wrote:
> 
>      perl -M'CGI qw (:standard)' -e 'print hidden (-name  => "x", 
>                                                    -value => param ("y"), 
>                                                    -force => 1)'
> prints:
> 
>     <INPUT TYPE="hidden" NAME="x" VALUE="-force">
> 
> But
>      perl -M'CGI qw (:standard)' -e 'print hidden (-name  => "x", 
>                                                    -value => undef, 
>                                                    -force => 1)'
> prints:
> 
>     <INPUT TYPE="hidden" NAME="x" VALUE="">
> 
> I am looking at the source code of the CGI.pm version 2.56
> (included with Perl 5.6.0) on my Solaris 2.6 workstation and
> don't understand yet, why? Does anyone have an idea?

Because param in list context returns list of values. Here the value
was not defined, so what you effectivelly done was

	(-name  => "x", -value => (), -force => 1)

which is the same as

	(-name  => "x", -value, -force, 1)

which is the same as

	(-name  => "x", -value => '-force', 1 => ())

Using scalar(param ("y")) will help.

Note that if the y was multivalued, it would break your code as well.

Yours,

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
   .project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------


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

Date: Fri, 22 Dec 2000 17:54:09 -0600
From: "Tommy Martin" <tmartin1@telocity.com>
Subject: Stripping trailing spaces from string
Message-Id: <gPR06.40806$ja.7218049@newsrump.sjc.telocity.net>

OK I give. I have been trying for a couple of hours to trim the spaces off
of a string like "This is the string.       "

I cannot seem to find the function to do this. In vb i could use
Trim@(Variable$) but I can't seem to find the perl equivalent.

Any help is appreciated.

I did look in the books I have but don't know what word to search for to
start with.





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

Date: 22 Dec 2000 18:35:49 -0600
From: John Hunter <jdhunter@nitace.bsd.uchicago.edu>
Subject: Re: Stripping trailing spaces from string
Message-Id: <1rae9oc6u2.fsf@video.bsd.uchicago.edu>

>>>>> "Tommy" == Tommy Martin <tmartin1@telocity.com> writes:

    Tommy> OK I give. I have been trying for a couple of hours to trim
    Tommy> the spaces off of a string like "This is the string.  "

#!/usr/local/bin/perl -w
use strict;
my $str = 'This is the string.       ';
$str =~ s/\s*$//;   
print "$str  Look, ma!  No extra spaces\n";

The funny looking line says substitute 0 or more spaces ('\s*') at the end of
a line ('$') with nothing ('//').  

    Tommy> I did look in the books I have but don't know what word to
    Tommy> search for to start with.

Regular Expression.  The 'online' relevant documentation, that should
be accessible from the command prompt if you are on some flavor of
UNIX, is perlre:

perldoc perlre



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

Date: Sat, 23 Dec 2000 00:25:26 GMT
From: rereidy@my-deja.com
Subject: Re: Stripping trailing spaces from string
Message-Id: <920rdi$4vi$1@nnrp1.deja.com>

$string =~ s/\s+$//g;

In article <gPR06.40806$ja.7218049@newsrump.sjc.telocity.net>,
  "Tommy Martin" <tmartin1@telocity.com> wrote:
> OK I give. I have been trying for a couple of hours to trim the spaces
off
> of a string like "This is the string.       "
>
> I cannot seem to find the function to do this. In vb i could use
> Trim@(Variable$) but I can't seem to find the perl equivalent.
>
> Any help is appreciated.
>
> I did look in the books I have but don't know what word to search for
to
> start with.
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 19:45:24 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Stripping trailing spaces from string
Message-Id: <slrn947td4.8qj.tadmc@magna.metronet.com>

Tommy Martin <tmartin1@telocity.com> wrote:

>OK I give. I have been trying for a couple of hours to trim the spaces off
>of a string like "This is the string.       "
>
>I cannot seem to find the function to do this. In vb i could use
>Trim@(Variable$) but I can't seem to find the perl equivalent.
>
>I did look in the books I have but don't know what word to search for to
>start with.


   perldoc -q strip

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


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


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

Date: Sat, 23 Dec 2000 00:32:27 GMT
From: rereidy@my-deja.com
Subject: useing dbms_output_enable and dbms_output_get in PL/SQL
Message-Id: <920rqs$5at$1@nnrp1.deja.com>

Hi,

I am trying to retrieve the output from an Oracle SP using this
functionality as outlined in the DBD::Oracle docs.  My code flow is:

$sth = $dbi->prepare(qq{
  BEGIN
    package.procedure(:arg1, :arg2, :arg3);
  END;
});

$sth->bind_param(':arg1', $val1);
$sth->bind_param(':arg2', $val2);
$sth->bind_param(':arg3', $val3);

$dbh->func('dbms_output_enable');
$dbh->execute;
$dbh->func('dbms_output_get');

I of course have the appropriate "|| croak ..." statements with each
call to prepare(), bind_param(), execute(), and func().


When this code is executed, I receive ORA-06550 (which points to a
PL/SQL compilation problem).

Since I have never used this type of interface to PL/SQL before, I am
lost as to what to do with this error.

Any help is very appreciated.

Ron Reidy
Oracle DBA


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 19:45:15 -0600
From: karthy muthiah kasi <kasi@students.uiuc.edu>
Subject: using perl
Message-Id: <Pine.GSO.4.10.10012221940480.4256-100000@ux7.cso.uiuc.edu>

Hi, 
	I am new to the Perl language and I have a question regarding its
use. 	I am thinking of using perl to do the database processing and
using visual c++ as a front end to an application.  Is there an advantage
in terms of speed of using perl to do the database processing?  Thanks for
any help.   

-Karthy 





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

Date: 22 Dec 2000 20:18:29 -0600
From: John Hunter <jdhunter@nitace.bsd.uchicago.edu>
Subject: Re: using perl
Message-Id: <1rae9nnami.fsf@video.bsd.uchicago.edu>

>>>>> "karthy" == karthy muthiah kasi <kasi@students.uiuc.edu> writes:

    karthy> Hi, I am new to the Perl language and I have a question
    karthy> regarding its use.  I am thinking of using perl to do the
    karthy> database processing and using visual c++ as a front end to
    karthy> an application.  Is there an advantage in terms of speed
    karthy> of using perl to do the database processing?  

It depends on what you mean by speed.  

If you mean 'computation time', then properly coded C++ will be faster
because it is a compiled language and perl is interpreted.

But if you mean time to development or programmer time, then perl be
faster because it is an easy language to program in and database
interfaces are heavily supported.

John Hunter


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

Date: Fri, 22 Dec 2000 23:45:32 GMT
From: jbuff <jbuff1856@my-deja.com>
Subject: Re: web ask seting cookie when perl ...
Message-Id: <920p2r$370$1@nnrp1.deja.com>

In article <91vl2m$5t6$1@nnrp1.deja.com>,
  justinlee1998@my-deja.com wrote:
> I want to use perl script to login a web server,
> but the web server ask to cookie.
> I don't know how to process.
>
>  Any suggest will be appreciate
>

Courtesy copy with more info sent by email.

See: http://www.jbuff.org/jbuff/entry249.htm for how this humble perl
beginner did it.

-- jbuff


Sent via Deja.com
http://www.deja.com/


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

Date: 22 Dec 2000 21:41:33 -0600
From: anmcguire@ce.mediaone.net (Andrew N. McGuire)
Subject: Re: Yesterdays Date
Message-Id: <86bsu3st1u.fsf@hawk.ce.mediaone.net>

>>>>> "BK" == Bjoern Kaiser <bkaiser@trans-it.de> writes:

BK> Hi

Greetings.

BK> (my $day,my $month,my $year) = (localtime(time))[3,4,5];

ahem, my($day, $month, $year) will suffice. :-)

BK> gives me todays date but what's the most simple way to get yesterdays date
BK> in the same format?

#!/usr/bin/perl -wl
use strict;

sleep(24 * 60**2);
print +(localtime(time))[3,4,5];
__END__

or you could consult the FAQ answer if you dont feel like waiting. :-)

[anm@hawk ~] man perlfaq4 | grep -A4 -B4 yesterday                    [0 ttyp1]

       The time() function returns the current time in seconds
       since the epoch.  Take one day off that:

           $yesterday = time() - ( 24 * 60 * 60 );

       Then you can pass this to localtime() and get the
       individual year, month, day, hour, minute, seconds values.

[anm@hawk ~]                                                          [0 ttyp1]

anm

-- 
perl -wMstrict -e '
$a=[[qw[J u s t]],[qw[A n o t h e r]],[qw[P e r l]],[qw[H a c k e r]]];$.++
;$@=$#$a;$$=[reverse sort map$#$_=>@$a]->[$|];for$](--$...$$){for$}($|..$@)
{$$[$]][$}]=$a->[$}][$]]}}$,=$";$\=$/;print map defined()?$_:$,,@$_ for @$;
'


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

Date: Sat, 23 Dec 2000 01:47:37 GMT
From: timallen449@my-deja.com
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <92107o$8dk$1@nnrp1.deja.com>

In article <977339250.4849@itz.pp.sci.fi>,
  Ilmari Karonen <usenet11311@itz.pp.sci.fi> wrote:
> What's this?  Definitely not the code you benchmarked below!
   I included the wrong program with the correct output.  I'm
very sorry, and frustrated, as I had hoped to express the idea of using
Perl to answer the question.
   The percentages I got were based on using cmpthis, not timethis, but
my code was essentially the same as yours.  I just included three test
cases, one of which was a long line of about 1024 characters.  I later
had to process the output file to get rid of the results of the print
statements.
   cmpthis returns straight percentage comparisons of different
strategies.  The percentages I got were read directly from these.  I
found that in the part about benchmarking in Programming Perl.
   Of course, this would have made a lot more sense had I sent the
original code.  My sincere apologies, I had hoped to be helpful.


Sent via Deja.com
http://www.deja.com/


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


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


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